Ejemplo n.º 1
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()));
     }
 }
Ejemplo n.º 2
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()));
     }
 }
Ejemplo n.º 3
0
 /**
  * @return array|ViewModel
  */
 public function headerBarAction()
 {
     if ($this->navigation->getType() === NavModel::NAV_UPDATER) {
         if ($this->status->isUpdateError() || $this->status->isUpdateInProgress()) {
             $this->view->setVariable('redirect', '../' . Environment::UPDATER_DIR . '/index.php');
         }
     }
     $this->view->setTemplate('/magento/setup/navigation/header-bar.phtml');
     $this->view->setTerminal(true);
     return $this->view;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 6
0
 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([]);
 }
Ejemplo n.º 7
0
 /**
  * Check if Cron job can be run
  *
  * @return bool
  */
 private function checkRun()
 {
     return $this->deploymentConfig->isAvailable() && $this->readinessCheck->runReadinessCheck() && !$this->status->isUpdateInProgress() && !$this->status->isUpdateError();
 }
Ejemplo n.º 8
0
 public function testIsUpdateError()
 {
     $this->varReaderWriter->expects($this->once())->method('isExist')->willReturn(true);
     $this->assertTrue($this->status->isUpdateError());
 }
Ejemplo n.º 9
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);
 }