/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->checkRun()) {
         return;
     }
     try {
         $this->status->toggleUpdateInProgress();
     } catch (\RuntimeException $e) {
         $this->status->add($e->getMessage());
         return;
     }
     try {
         while (!empty($this->queue->peek()) && strpos($this->queue->peek()[Queue::KEY_JOB_NAME], 'setup:') === 0) {
             $job = $this->queue->popQueuedJob();
             $this->status->add(sprintf('Job "%s" has started' . PHP_EOL, $job));
             try {
                 $job->execute();
                 $this->status->add(sprintf('Job "%s" has been successfully completed', $job));
             } catch (\Exception $e) {
                 $this->status->toggleUpdateError(true);
                 $this->status->add(sprintf('An error occurred while executing job "%s": %s', $job, $e->getMessage()));
             }
         }
     } catch (\Exception $e) {
         $this->status->add($e->getMessage());
         $this->status->toggleUpdateError(true);
     } finally {
         $this->status->toggleUpdateInProgress(false);
     }
 }
 /**
  * Execute job
  *
  * @throws \RuntimeException
  * @return void
  */
 public function execute()
 {
     try {
         $this->params['command'] = 'setup:upgrade';
         $this->command->run(new ArrayInput($this->params), $this->output);
         $this->queue->addJobs([['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]);
     } catch (\Exception $e) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
     }
 }
 /**
  * Executes setup jobs from the queue
  *
  * @return int
  */
 private function executeJobsFromQueue()
 {
     $returnCode = \Magento\Framework\Console\Cli::RETURN_SUCCESS;
     try {
         while (!empty($this->queue->peek()) && strpos($this->queue->peek()[Queue::KEY_JOB_NAME], 'setup:') === 0) {
             $job = $this->queue->popQueuedJob();
             $this->status->add(sprintf('Job "%s" has started' . PHP_EOL, $job), \Psr\Log\LogLevel::INFO);
             try {
                 $job->execute();
                 $this->status->add(sprintf('Job "%s" has been successfully completed', $job), \Psr\Log\LogLevel::INFO);
             } catch (\Exception $e) {
                 $this->status->toggleUpdateError(true);
                 $this->status->add(sprintf('An error occurred while executing job "%s": %s', $job, $e->getMessage()), \Psr\Log\LogLevel::ERROR);
                 $returnCode = \Magento\Framework\Console\Cli::RETURN_FAILURE;
             }
         }
     } catch (\Exception $e) {
         $this->status->add($e->getMessage(), \Psr\Log\LogLevel::ERROR);
         $this->status->toggleUpdateError(true);
         $returnCode = \Magento\Framework\Console\Cli::RETURN_FAILURE;
     } finally {
         $this->status->toggleUpdateInProgress(false);
     }
     return $returnCode;
 }
Beispiel #4
0
 /**
  * Create an update task for Updater app
  *
  * @param array $packages
  * @param string $type
  * @param array $additionalOptions
  * @return string
  */
 public function createUpdaterTask(array $packages, $type, array $additionalOptions = [])
 {
     try {
         // write to .update_queue.json file
         $params = [];
         if (!empty($packages)) {
             $params['components'] = $packages;
         }
         foreach ($additionalOptions as $key => $value) {
             $params[$key] = $value;
         }
         $this->queue->addJobs([['name' => $type, 'params' => $params]]);
         return '';
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
 public function testExecute()
 {
     $this->setUpPreliminarySuccess();
     $this->queue->expects($this->at(0))->method('peek')->willReturn(['name' => 'setup:']);
     $this->queue->expects($this->at(1))->method('peek')->willReturn(['name' => 'setup:']);
     $job = $this->getMockForAbstractClass('Magento\\Setup\\Model\\Cron\\AbstractJob', [], '', false);
     $job->expects($this->once())->method('execute');
     $this->queue->expects($this->at(2))->method('popQueuedJob')->willReturn($job);
     $this->status->expects($this->never())->method('toggleUpdateError')->with(true);
     $this->commandTester->execute([]);
 }
 /**
  * Run remove component job
  *
  * @return void
  * @throw \RuntimeException
  */
 public function execute()
 {
     if (!isset($this->params['components']) || !is_array($this->params['components'])) {
         $this->status->toggleUpdateError(true);
         throw new \RunTimeException('Job parameter format is incorrect');
     }
     $components = $this->params['components'];
     foreach ($components as $component) {
         $this->executeComponent($component);
     }
     $this->queue->addJobs([['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]);
     $errorMessage = $this->updater->createUpdaterTask($components, Updater::TASK_TYPE_UNINSTALL);
     if ($errorMessage) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException($errorMessage);
     }
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage field is missing for one or more jobs
  */
 public function testAddJobsInvalidJobs()
 {
     $this->queue->addJobs([['no_name' => 'no job', 'no_params' => []]]);
 }
 private function setUpQuence()
 {
     $this->quence->expects($this->once())->method('addJobs');
 }