/** * * @param \MUtil_Task_TaskBatch $batch Optional batch with different source etc.. * @return \MUtil_Task_TaskBatch */ public function getImportOnlyBatch(\MUtil_Task_TaskBatch $batch = null) { if (!$this->_importBatch instanceof \MUtil_Task_TaskBatch) { $batch = $this->loader->getTaskRunnerBatch(__CLASS__ . '_import_' . basename($this->sourceModel->getName()) . '_' . __FUNCTION__); $batch->setVariable('targetModel', $this->getTargetModel()); $this->_importBatch = $batch; } else { $batch = $this->_importBatch; } return parent::getImportOnlyBatch($batch); }
/** * Code execution in batch mode * * @return void */ protected function processCli() { try { // Lookup in importTranslators $transName = $this->request->getParam('trans', $this->defaultImportTranslator); if (!isset($this->importTranslators[$transName])) { throw new \MUtil_Model_ModelTranslateException(sprintf($this->_("Unknown translator '%s'. Should be one of: %s"), $transName, implode($this->_(', '), array_keys($this->importTranslators)))); } $translator = $this->importTranslators[$transName]; $this->importer->setSourceFile($this->request->getParam('file')); $this->importer->setImportTranslator($translator); // \MUtil_Registry_Source::$verbose = true; $batch = $this->importer->getCheckAndImportBatch(); $batch->setVariable('addImport', !$this->request->getParam('check', false)); $batch->runContinuous(); if ($batch->getMessages(false)) { echo implode("\n", $batch->getMessages()) . "\n"; } if (!$batch->getCounter('import_errors')) { echo sprintf("%d records imported, %d records changed.\n", $batch->getCounter('imported'), $batch->getCounter('changed')); } } catch (\Exception $e) { $messages[] = "IMPORT ERROR!"; $messages[] = $e->getMessage(); $messages[] = null; $messages[] = sprintf("Usage instruction: %s %s file=filename [trans=[%s]] [check=1]", $this->request->getControllerName(), $this->request->getActionName(), implode('|', array_keys($this->importTranslators))); $messages[] = sprintf("\tRequired parameter: file=filename to import, absolute or relative to %s", getcwd()); $messages[] = sprintf("\tOptional parameter: trans=[%s] default is %s", implode('|', array_keys($this->importTranslators)), $this->defaultImportTranslator); $messages[] = "\tOptional parameter: check=[0|1], 0=default, 1=check input only"; echo implode("\n", $messages) . "\n"; } }