/**
  *
  * @param \MUtil_Batch_BatchAbstract $batch
  * @param string $title
  * @param \Gems_AccessLog $accessLog
  */
 public function direct(\MUtil_Batch_BatchAbstract $batch, $title, $accessLog = null)
 {
     if ($batch->isConsole()) {
         $batch->runContinuous();
         $messages = array_values($batch->getMessages(true));
         echo implode("\n", $messages) . "\n";
         $echo = array_filter(array_map('trim', preg_split('/<[^>]+>/', \MUtil_Echo::out())));
         if ($echo) {
             echo "\n\n================================================================\nECHO OUTPUT:\n\n";
             echo implode("\n", $echo);
         }
         if ($accessLog instanceof \Gems_AccessLog) {
             $accessLog->logChange($this->getRequest(), $messages, $echo);
         }
         exit;
     } elseif ($batch->run($this->getRequest())) {
         exit;
     } else {
         $controller = $this->getActionController();
         $batchContainer = $controller->html->div(array('class' => 'batch-container'));
         $batchContainer->h3($title);
         if ($batch->isFinished()) {
             $controller->addMessage($batch->getMessages(true), 'info');
             $batchContainer->pInfo($batch->getRestartButton($controller->_('Prepare recheck'), array('class' => 'actionlink')));
             if ($accessLog instanceof \Gems_AccessLog) {
                 $echo = array_filter(array_map('trim', preg_split('/<[^>]+>/', \MUtil_Echo::getOutput())));
                 $accessLog->logChange($this->getRequest(), null, $echo);
             }
         } else {
             if ($batch->count()) {
                 $batchContainer->pInfo($batch->getStartButton(sprintf($controller->_('Start %s jobs'), $batch->count())));
                 $batchContainer->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%'));
             } else {
                 $batchContainer->pInfo($controller->_('Nothing to do.'));
             }
         }
     }
 }
Example #2
0
 /**
  * Store a variable in the general store.
  *
  * These variables have to be reset for every run of the batch.
  *
  * @param string $name Name of the variable
  * @param mixed $variable Something that can be serialized
  * @return \MUtil_Batch_BatchAbstract (continuation pattern)
  */
 public function setVariable($name, $variable)
 {
     parent::setVariable($name, $variable);
     $this->source->addRegistryContainer($this->variables, 'variables');
     return $this;
 }