Example #1
0
 /**
  * Execute a single iteration of the task.
  *
  * @param scalar $key The current iterator key
  * @param mixed $current The current iterator content
  * @param array $params The parameters to the execute function
  */
 public function executeIteration($key, $current, array $params)
 {
     // \MUtil_Echo::track($key, $current);
     // Ignore empty rows.
     if (!$current) {
         return;
     }
     $batch = $this->getBatch();
     $row = $this->modelTranslator->translateRowValues($current, $key);
     if ($row) {
         $row = $this->modelTranslator->validateRowValues($row, $key);
     }
     $batch->addToCounter('import_checked');
     $errors = $this->modelTranslator->getRowErrors($key);
     foreach ($errors as $error) {
         $batch->addToCounter('import_errors');
         $batch->addMessage($error);
     }
     $errorCount = $batch->getCounter('import_errors');
     $checked = $batch->getCounter('import_checked');
     $checkMsg = sprintf($this->plural('%d row checked', '%d rows checked', $checked), $checked);
     // \MUtil_Echo::track($key, $row, $errors);
     if (0 === $errorCount) {
         // Do not report empty rows
         if ($row) {
             if ($this->addImport && $this->importBatch) {
                 // Let the translator decide how to save the row
                 $this->modelTranslator->addSaveTask($this->importBatch, $key, $row);
             }
             $batch->setMessage('check_status', sprintf($this->_('%s, no problems found.'), $checkMsg));
         }
     } else {
         $batch->setMessage('check_status', sprintf($this->plural('%s, one import problem found, continuing check.', '%s, %d import problems found, continuing check.', $errorCount), $checkMsg, $errorCount));
     }
 }
Example #2
0
 /**
  * Set the target model for the imported data
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @return \MUtil_Model_Importer (continuation pattern)
  */
 public function setTargetModel(\MUtil_Model_ModelAbstract $model)
 {
     $this->targetModel = $model;
     if ($this->importTranslator instanceof \MUtil_Model_ModelTranslatorInterface) {
         $this->importTranslator->setTargetModel($model);
     }
     return $this;
 }