/**
  * {@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
 public function testAdd()
 {
     $this->varReaderWriter->expects($this->once())->method('isExist')->willReturn(false);
     $this->varReaderWriter->expects($this->once())->method('writeFile');
     $this->logger->expects($this->once())->method('log')->with(\Psr\Log\LogLevel::ERROR, 'test1');
     $this->status->add('test1', \Psr\Log\LogLevel::ERROR);
 }
Example #3
0
 public function testAdd()
 {
     $this->varReaderWriter->expects($this->at(0))->method('isExist')->willReturn(false);
     $this->varReaderWriter->expects($this->at(1))->method('writeFile');
     $this->varReaderWriter->expects($this->at(2))->method('isExist')->willReturn(true);
     $this->varReaderWriter->expects($this->at(3))->method('readFile')->willReturn('test0');
     $this->varReaderWriter->expects($this->at(4))->method('writeFile');
     $this->status->add('test1');
 }
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
 /**
  * Do the cleanup
  *
  * @return void
  */
 protected function performCleanup()
 {
     $this->status->add('Cleaning generated files...', \Psr\Log\LogLevel::INFO);
     $this->cleanupFiles->clearCodeGeneratedFiles();
     $this->status->add('Complete!', \Psr\Log\LogLevel::INFO);
     $this->status->add('Clearing cache...', \Psr\Log\LogLevel::INFO);
     $this->cache->clean();
     $this->status->add('Complete!', \Psr\Log\LogLevel::INFO);
 }
Example #6
0
 /**
  * Run the readiness check
  *
  * @return bool
  */
 public function runReadinessCheck()
 {
     $resultJsonRawData = [self::KEY_READINESS_CHECKS => []];
     $errorLogMessages = [];
     // check PHP version
     $phpVersionCheckResult = $this->phpReadinessCheck->checkPhpVersion();
     $errorMessage = $this->getPhpVersionCheckErrorLogMessage($phpVersionCheckResult);
     if (!empty($errorMessage)) {
         $errorLogMessages[] = $errorMessage;
     }
     // check PHP extensions
     $phpExtensionsCheckResult = $this->phpReadinessCheck->checkPhpExtensions();
     $errorMessage = $this->getPhpExtensionsCheckErrorLogMessage($phpExtensionsCheckResult);
     if (!empty($errorMessage)) {
         $errorLogMessages[] = $errorMessage;
     }
     // check PHP settings
     $phpSettingsCheckResult = $this->phpReadinessCheck->checkPhpCronSettings();
     $errorMessage = $this->getPhpSettingsCheckErrorLogMessage($phpSettingsCheckResult);
     if (!empty($errorMessage)) {
         $errorLogMessages[] = $errorMessage;
     }
     $resultJsonRawData[self::KEY_PHP_CHECKS][self::KEY_PHP_VERSION_VERIFIED] = $phpVersionCheckResult;
     $resultJsonRawData[self::KEY_PHP_CHECKS][self::KEY_PHP_EXTENSIONS_VERIFIED] = $phpExtensionsCheckResult;
     $resultJsonRawData[self::KEY_PHP_CHECKS][self::KEY_PHP_SETTINGS_VERIFIED] = $phpSettingsCheckResult;
     // check DB connection
     $errorMessage = $this->performDBCheck();
     if (empty($errorMessage)) {
         $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_DB_WRITE_PERMISSION_VERIFIED] = true;
     } else {
         $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_DB_WRITE_PERMISSION_VERIFIED] = false;
         $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_ERROR] = $errorMessage;
         $errorLogMessages[] = $errorMessage;
     }
     // Prepare list of magento specific files and directory paths for updater application to check write
     // permissions
     $errorMessage = '';
     try {
         $filePaths = $this->basePackageInfo->getPaths();
         $resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = $filePaths;
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         $resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = [];
         $errorLogMessages[] = $errorMessage;
     }
     $resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_ERROR] = $errorMessage;
     // updates timestamp
     $write = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR);
     if ($write->isExist(self::SETUP_CRON_JOB_STATUS_FILE)) {
         $jsonData = json_decode($write->readFile(self::SETUP_CRON_JOB_STATUS_FILE), true);
         if (isset($jsonData[self::KEY_CURRENT_TIMESTAMP])) {
             $resultJsonRawData[self::KEY_LAST_TIMESTAMP] = $jsonData[self::KEY_CURRENT_TIMESTAMP];
         }
     }
     $resultJsonRawData[self::KEY_CURRENT_TIMESTAMP] = time();
     // write to transient log file to display on GUI
     $resultJson = json_encode($resultJsonRawData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     $write->writeFile(self::SETUP_CRON_JOB_STATUS_FILE, $resultJson);
     // write to permanent log file, var/log/update.log
     foreach ($errorLogMessages as $errorLog) {
         $this->status->add($errorLog, \Psr\Log\LogLevel::ERROR, false);
     }
     return empty($errorLogMessages);
 }