예제 #1
0
 /**
  *
  * @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 = new \MUtil_Task_TaskBatch(__CLASS__ . '_import_' . basename($this->sourceModel->getName()) . '_' . __FUNCTION__);
         $this->registrySource->applySource($batch);
         $batch->setSource($this->registrySource);
         $batch->setVariable('targetModel', $this->getTargetModel());
         $this->_importBatch = $batch;
     } else {
         $batch = $this->_importBatch;
     }
     $this->_importBatch->getStack()->registerAllowedClass('MUtil_Date');
     // \MUtil_Echo::track($this->_importBatch->count());
     if (!$batch->isLoaded()) {
         if ($this->_filename) {
             $batch->addTask('AddTask', 'File_CopyFileWhenTask', $this->_filename, $this->getSuccessDirectory() . DIRECTORY_SEPARATOR . $this->getLongtermFilename() . '.' . $this->_extension, 'import_errors', 0, 0);
         }
         // Rest of loading is done by getCheckOnlyBatch, but when started, the above task must be added.
     }
     return $this->_importBatch;
 }
 /**
  * Add the current row to a (possibly separate) batch that does the importing.
  *
  * @param \MUtil_Task_TaskBatch $importBatch The import batch to impor this row into
  * @param string $key The current iterator key
  * @param array $row translated and validated row
  * @return \MUtil_Model_ModelTranslatorAbstract (continuation pattern)
  */
 public function addSaveTask(\MUtil_Task_TaskBatch $importBatch, $key, array $row)
 {
     $importBatch->setTask($this->saveTask, 'import-' . $key, $row, $this->getNoToken(), $this->getTokenCompleted());
     return $this;
 }
 /**
  * Loads execution of selected db patches for the given $patchLevel into a TaskBatch.
  *
  * @param int $patchLevel Only execute patches for this patchlevel
  * @param boolean $ignoreCompleted Set to yes to skip patches that where already completed
  * @param boolean $ignoreExecuted Set to yes to skip patches that where already executed
  *                                (this includes the ones that are executed but not completed)
  * @param \MUtil_Task_TaskBatch $batch Optional batch, otherwise one is created
  * @return \MUtil_Task_TaskBatch The batch
  */
 public function loadPatchBatch($patchLevel, $ignoreCompleted, $ignoreExecuted, \MUtil_Task_TaskBatch $batch)
 {
     $select = $this->db->select();
     $select->from('gems__patches', array('gpa_id_patch', 'gpa_sql', 'gpa_location', 'gpa_completed'))->where('gpa_level = ?', $patchLevel)->order('gpa_level')->order('gpa_location')->order('gpa_id_patch');
     if ($ignoreCompleted) {
         $select->where('gpa_completed = 0');
     }
     if ($ignoreExecuted) {
         $select->where('gpa_executed = 0');
     }
     // \MUtil_Echo::track($ignoreCompleted, $ignoreExecuted, $select);
     $executed = 0;
     $patches = $select->query()->fetchAll();
     if ($patches) {
         foreach ($patches as $patch) {
             $batch->addTask('Db_ExecuteOnePatch', $patch['gpa_location'], $patch['gpa_sql'], $patch['gpa_completed'], $patch['gpa_id_patch']);
         }
         $batch->addTask('Db_UpdatePatchLevel', $patchLevel);
         $batch->addTask('CleanCache');
     }
     return $batch;
 }
예제 #4
0
 /**
  * Hook for after save
  *
  * @param \MUtil_Task_TaskBatch $batch that was just executed
  * @param \MUtil_Form_Element_Html $element Tetx element for display of messages
  * @return string a message about what has changed (and used in the form)
  */
 public function afterImport(\MUtil_Task_TaskBatch $batch, \MUtil_Form_Element_Html $element)
 {
     $imported = $batch->getCounter('imported');
     $changed = $batch->getCounter('changed');
     $text = sprintf($this->plural('%d row imported.', '%d rows imported.', $imported), $imported) . ' ' . sprintf($this->plural('%d row changed.', '%d rows changed.', $changed), $changed);
     $this->addMessage($batch->getMessages(true));
     $this->addMessage($text);
     $element->pInfo($text);
     return $text;
 }
예제 #5
0
 /**
  * Add the current row to a (possibly separate) batch that does the importing.
  *
  * @param \MUtil_Task_TaskBatch $importBatch The import batch to impor this row into
  * @param string $key The current iterator key
  * @param array $row translated and validated row
  * @return \MUtil_Model_ModelTranslatorAbstract (continuation pattern)
  */
 public function addSaveTask(\MUtil_Task_TaskBatch $importBatch, $key, array $row)
 {
     $importBatch->setTask($this->saveTask, 'import-' . $key, $row);
     return $this;
 }