Example #1
0
 /**
  * @expectedException \Magento\Setup\Exception
  * @expectedExceptionMessage Sorry, but we support MySQL version
  */
 public function testCheckDatabaseConnectionIncompatible()
 {
     $this->connection
         ->expects($this->once())
         ->method('fetchOne')
         ->with('SELECT version()')
         ->willReturn('5.5.40-0ubuntu0.12.04.1');
     $this->dbValidator->checkDatabaseConnection('name', 'host', 'user', 'password');
 }
 /**
  * Result of checking DB credentials
  *
  * @return JsonModel
  */
 public function indexAction()
 {
     try {
         $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
         $password = isset($params['password']) ? $params['password'] : '';
         $this->dbValidator->checkDatabaseConnection($params['name'], $params['host'], $params['user'], $password);
         $tablePrefix = isset($params['tablePrefix']) ? $params['tablePrefix'] : '';
         $this->dbValidator->checkDatabaseTablePrefix($tablePrefix);
         return new JsonModel(['success' => true]);
     } catch (\Exception $e) {
         return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
     }
 }
 public function testRunReadinessCheckLastTimestamp()
 {
     $this->dbValidator->expects($this->once())->method('checkDatabaseConnection')->willReturn(true);
     $this->write->expects($this->once())->method('isExist')->willReturn(true);
     $this->write->expects($this->once())->method('readFile')->willReturn('{"current_timestamp": 50}');
     $expected = [ReadinessCheck::KEY_READINESS_CHECKS => [ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED => true], ReadinessCheck::KEY_PHP_CHECKS => $this->expected, ReadinessCheck::KEY_LAST_TIMESTAMP => 50, ReadinessCheck::KEY_CURRENT_TIMESTAMP => 100];
     $expectedJson = json_encode($expected, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     $this->write->expects($this->once())->method('writeFile')->with(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE, $expectedJson);
     $this->readinessCheck->runReadinessCheck();
 }
Example #4
0
 /**
  * A private function to check database access and return appropriate error message in case of error
  *
  * @return string
  */
 private function performDBCheck()
 {
     $errorLogMessage = '';
     $dbInfo = $this->deploymentConfig->get(\Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT);
     try {
         $this->dbValidator->checkDatabaseConnection($dbInfo[\Magento\Framework\Config\ConfigOptionsListConstants::KEY_NAME], $dbInfo[\Magento\Framework\Config\ConfigOptionsListConstants::KEY_HOST], $dbInfo[\Magento\Framework\Config\ConfigOptionsListConstants::KEY_USER], $dbInfo[\Magento\Framework\Config\ConfigOptionsListConstants::KEY_PASSWORD]);
     } catch (\Exception $e) {
         $errorLogMessage = $e->getMessage();
     }
     return $errorLogMessage;
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $options, DeploymentConfig $deploymentConfig)
 {
     $errors = [];
     if (isset($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX])) {
         try {
             $this->dbValidator->checkDatabaseTablePrefix($options[ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX]);
         } catch (\InvalidArgumentException $exception) {
             $errors[] = $exception->getMessage();
         }
     }
     if (!$options[ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION] && ($options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] !== null)) {
         try {
             $options = $this->getDbSettings($options, $deploymentConfig);
             $this->dbValidator->checkDatabaseConnection($options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME], $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST], $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER], $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD]);
         } catch (\Exception $exception) {
             $errors[] = $exception->getMessage();
         }
     }
     $errors = array_merge($errors, $this->validateSessionSave($options), $this->validateEncryptionKey($options));
     return $errors;
 }
 /**
  * Validate Db settings
  *
  * @param array $options
  * @param DeploymentConfig $deploymentConfig
  * @return string[]
  */
 private function validateDbSettings(array $options, DeploymentConfig $deploymentConfig)
 {
     $errors = [];
     if ($options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER] !== null || $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD] !== null) {
         try {
             $options = $this->getDbSettings($options, $deploymentConfig);
             $this->dbValidator->checkDatabaseConnection($options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME], $options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST], $options[ConfigOptionsListConstants::INPUT_KEY_DB_USER], $options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD]);
         } catch (\Exception $exception) {
             $errors[] = $exception->getMessage();
         }
     }
     return $errors;
 }
 /**
  * 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;
 }
 /**
  * Validates that MySQL is accessible and MySQL version is supported
  *
  * @return void
  */
 private function assertDbAccessible()
 {
     $this->dbValidator->checkDatabaseConnection(
         $this->deploymentConfig->get(
             ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
             '/' . ConfigOptionsListConstants::KEY_NAME
         ),
         $this->deploymentConfig->get(
             ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
             '/' . ConfigOptionsListConstants::KEY_HOST
         ),
         $this->deploymentConfig->get(
             ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
             '/' . ConfigOptionsListConstants::KEY_USER
         ),
         $this->deploymentConfig->get(
             ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
             '/' . ConfigOptionsListConstants::KEY_PASSWORD
         )
     );
     $prefix = $this->deploymentConfig->get(
         ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
         '/' . ConfigOptionsListConstants::KEY_PREFIX
     );
     if (null !== $prefix) {
         $this->dbValidator->checkDatabaseTablePrefix($prefix);
     }
 }
 private function prepareValidationMocks()
 {
     $configDataMock = $this->getMockBuilder('Magento\\Framework\\Config\\Data\\ConfigData')->disableOriginalConstructor()->getMock();
     $this->dbValidator->expects($this->once())->method('checkDatabaseTablePrefix')->willReturn($configDataMock);
     $this->dbValidator->expects($this->once())->method('checkDatabaseConnection')->willReturn($configDataMock);
 }
Example #10
0
 public function testIndexActionCheckPrefix()
 {
     $this->dbValidator->expects($this->once())->method('checkDatabaseTablePrefix');
     $this->controller->indexAction();
 }