/** * {@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); } }
/** * 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; }
public function testToggleUpdateInProgressFalseFlagNotExist() { $this->varReaderWriter->expects($this->at(0))->method('isExist')->willReturn(false); $this->varReaderWriter->expects($this->never())->method('delete'); $this->status->toggleUpdateInProgress(false); }