Ejemplo n.º 1
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_executePrepare($input, $output);
     $this->_init();
     $this->_setupConfigure();
     $stepMode = $this->_getOpt('stepmode');
     $profileName = $this->_getOpt('profile');
     $config = $this->_jbconfig->getList('export.items');
     $stepSize = (int) $this->_config->find('params.step_limit', '100');
     $totalItems = $this->_getTotal();
     $this->_showProfiler('CSV Export - prepared');
     $this->_('Step size: ' . $stepSize, 'Info');
     $this->_('Total items: ' . $totalItems, 'Info');
     $this->_('Step mode: ' . ($stepMode ? 'on' : 'off'), 'Info');
     $this->_progressWrap($this->_commandName, $totalItems, $stepSize, function () use($config, $totalItems, $stepSize) {
         $this->_jbexport->clean();
         $this->_progressBar($this->_commandName, $totalItems, $stepSize, function ($currentStep) use($config) {
             $this->_toCSV($currentStep);
         });
         return true;
     }, function ($step) use($config) {
         $this->_toCSV($step);
     }, function ($isFinished) use($config, $profileName) {
         if ($isFinished && ($compressFiles = $this->_jbexport->splitFiles())) {
             $exportPath = $this->_jbpath->sysPath('tmp', '/' . \JBExportHelper::EXPORT_PATH);
             //  Move CSV file to config path.
             foreach ($compressFiles as $file) {
                 $fileName = basename($file);
                 $dir = JBZOO_CLI_JOOMLA_ROOT . '/' . $config->get('file_path');
                 $newFile = FS::clean($dir . '/' . $profileName . '-' . $fileName, '/');
                 \JFile::move($file, $newFile);
                 $this->_('CSV File: ' . $newFile, 'Info');
             }
             //  Delete export tmp folder.
             if (\JFolder::exists($exportPath)) {
                 \JFolder::delete($exportPath);
             }
         }
         $this->_showProfiler('Export - finished');
     });
 }
Ejemplo n.º 2
0
 /**
  * Export dialog action for categoris
  */
 public function categories()
 {
     if (!$this->_jbrequest->isPost()) {
         $this->exportParams = $this->_config->getGroup('export.categories', $this->_jbuser->getParam('export-categories'));
         $this->_setExportParams();
         $this->renderView();
     } else {
         try {
             $request = $this->app->data->create($this->_jbrequest->getAdminForm());
             $data['separator'] = $request->get('separator');
             $data['enclosure'] = $request->get('enclosure');
             $data['separator'] = empty($data['separator']) ? $this->_defaultParams['separator'] : $data['separator'];
             $data['enclosure'] = empty($data['enclosure']) ? $this->_defaultParams['enclosure'] : $data['enclosure'];
             $request->remove('separator');
             $request->remove('enclosure');
             $this->_config->setGroup('export.categories', $request);
             $this->_config->setGroup('export', $data);
             list($appId) = explode(':', $request->get('category_app', '0:'));
             $files = $this->_jbexport->categoriesToCSV($appId, $request);
             if (!empty($files)) {
                 $tmpArch = $this->app->jbarch->compress($files, 'jbzoo-export-categories-' . date('Y-m-d_H-i'));
             } else {
                 throw new AppException(JText::_('JBZOO_EXPORT_CATEGORIES_NOT_FOUND'));
             }
             if (is_readable($tmpArch) && JFile::exists($tmpArch)) {
                 $this->app->filesystem->output($tmpArch);
                 JFile::delete($tmpArch);
                 JFolder::delete($this->app->jbpath->sysPath('tmp', '/jbzoo-export'));
                 JExit();
             } else {
                 throw new AppException(JText::sprintf('Unable to create file %s', $tmpArch));
             }
         } catch (AppException $e) {
             $this->app->jbnotify->notice(JText::_('Error create export file') . ' (' . $e . ')');
             $this->setRedirect($this->app->jbrouter->admin(array('task' => 'categories')));
         }
     }
 }