/**
  * {@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);
     }
 }
Example #2
0
 /**
  * Execute set cache comand
  *
  * @return void
  */
 public function execute()
 {
     try {
         $arguments = [];
         if ($this->getName() === 'setup:cache:enable') {
             if (!empty($this->params)) {
                 $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
             }
             $arguments['command'] = 'cache:enable';
             $inputDefinition = [];
             if ($this->command->getDefinition()->hasArgument('command')) {
                 $inputDefinition[] = new InputArgument('command', InputArgument::REQUIRED);
             }
             if ($this->command->getDefinition()->hasArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES)) {
                 $inputDefinition[] = new InputArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES, InputArgument::REQUIRED);
             }
             if (!empty($inputDefinition)) {
                 $definition = new InputDefinition($inputDefinition);
                 $this->command->setDefinition($definition);
             }
         } else {
             $arguments['command'] = 'cache:disable';
         }
         $this->command->run(new ArrayInput($arguments), $this->output);
     } catch (\Exception $e) {
         $this->status->toggleUpdateError(true);
         throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
     }
 }
Example #3
0
 /**
  * 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()));
     }
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 public function testToggleUpdateErrorFalseFlagNotExist()
 {
     $this->varReaderWriter->expects($this->at(0))->method('isExist')->willReturn(false);
     $this->varReaderWriter->expects($this->never())->method('delete');
     $this->status->toggleUpdateError(false);
 }