public function testCheckPhpExtensionsFailed()
 {
     $this->composerInfo->expects($this->once())->method('getRequiredExtensions')->willReturn(['a', 'b', 'c']);
     $this->phpInfo->expects($this->once())->method('getCurrent')->willReturn(['a', 'b']);
     $expected = ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['required' => ['a', 'b', 'c'], 'missing' => ['c']]];
     $this->assertEquals($expected, $this->phpReadinessCheck->checkPhpExtensions());
 }
Exemple #2
0
 /**
  * Verifies php verifications
  *
  * @return JsonModel
  */
 public function phpExtensionsAction()
 {
     $type = $this->getRequest()->getQuery('type');
     $data = [];
     if ($type == ReadinessCheckInstaller::INSTALLER) {
         $data = $this->phpReadinessCheck->checkPhpExtensions();
     } elseif ($type == ReadinessCheckUpdater::UPDATER) {
         $data = $this->getPhpChecksInfo(ReadinessCheck::KEY_PHP_EXTENSIONS_VERIFIED);
     }
     return new JsonModel($data);
 }
 /**
  * Run the readiness check
  *
  * @return bool
  */
 public function runReadinessCheck()
 {
     $resultJsonRawData = [self::KEY_READINESS_CHECKS => []];
     // checks PHP
     $phpVersionCheckResult = $this->phpReadinessCheck->checkPhpVersion();
     $phpExtensionsCheckResult = $this->phpReadinessCheck->checkPhpExtensions();
     $phpSettingsCheckResult = $this->phpReadinessCheck->checkPhpSettings();
     $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;
     // checks Database privileges
     $success = true;
     $errorMsg = '';
     $write = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $dbInfo = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT);
     try {
         $this->dbValidator->checkDatabaseConnection($dbInfo[ConfigOptionsListConstants::KEY_NAME], $dbInfo[ConfigOptionsListConstants::KEY_HOST], $dbInfo[ConfigOptionsListConstants::KEY_USER], $dbInfo[ConfigOptionsListConstants::KEY_PASSWORD]);
     } catch (\Exception $e) {
         $success = false;
         $errorMsg .= $e->getMessage();
     }
     if ($success) {
         $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] = $errorMsg;
     }
     // updates timestamp
     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();
     $resultJson = json_encode($resultJsonRawData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     $write->writeFile(self::SETUP_CRON_JOB_STATUS_FILE, $resultJson);
     return $success;
 }
 /**
  * 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);
 }
Exemple #5
0
 /**
  * Check required extensions for installation
  *
  * @return void
  * @throws \Exception
  */
 public function checkExtensions()
 {
     $phpExtensionsCheckResult = $this->phpReadinessCheck->checkPhpExtensions();
     if ($phpExtensionsCheckResult['responseType'] === ResponseTypeInterface::RESPONSE_TYPE_ERROR && isset($phpExtensionsCheckResult['data']['missing'])) {
         $errorMsg = "Missing following extensions: '" . implode("' '", $phpExtensionsCheckResult['data']['missing']) . "'";
         throw new \Exception($errorMsg);
     }
 }