diff --git a/installation/src/Helper/DatabaseHelper.php b/installation/src/Helper/DatabaseHelper.php index 7cd02578aa713..a44f45b17c96f 100644 --- a/installation/src/Helper/DatabaseHelper.php +++ b/installation/src/Helper/DatabaseHelper.php @@ -20,6 +20,33 @@ */ abstract class DatabaseHelper { + /** + * The minimum database server version for MariaDB databases as required by the CMS. + * This is not necessarily equal to what the database driver requires. + * + * @var string + * @since 4.0.0 + */ + protected static $dbMinimumMariaDb = '10.1'; + + /** + * The minimum database server version for MySQL databases as required by the CMS. + * This is not necessarily equal to what the database driver requires. + * + * @var string + * @since 4.0.0 + */ + protected static $dbMinimumMySql = '5.6'; + + /** + * The minimum database server version for PostgreSQL databases as required by the CMS. + * This is not necessarily equal to what the database driver requires. + * + * @var string + * @since 4.0.0 + */ + protected static $dbMinimumPostgreSql = '11.0'; + /** * Method to get a database driver. * @@ -109,4 +136,45 @@ public static function getEncryptionSettings($options) 'dbsslcipher' => $options->db_sslcipher, ]; } + + /** + * Get the minimum required database server version. + * + * @param DatabaseDriver $db Database object + * @param \stdClass $options The session options + * + * @return string The minimum required database server version. + * + * @since __DEPLOY_VERSION__ + */ + public static function getMinimumServerVersion($db, $options) + { + // Get minimum database version required by the database driver + $minDbVersionRequired = $db->getMinimum(); + + // Get minimum database version required by the CMS + if (in_array($options->db_type, ['mysql', 'mysqli'])) + { + if ($db->isMariaDb()) + { + $minDbVersionCms = self::$dbMinimumMariaDb; + } + else + { + $minDbVersionCms = self::$dbMinimumMySql; + } + } + else + { + $minDbVersionCms = self::$dbMinimumPostgreSql; + } + + // Use most restrictive, i.e. largest minimum database version requirement + if (version_compare($minDbVersionCms, $minDbVersionRequired) > 0) + { + $minDbVersionRequired = $minDbVersionCms; + } + + return $minDbVersionRequired; + } } diff --git a/installation/src/Model/DatabaseModel.php b/installation/src/Model/DatabaseModel.php index 29743f2bca88a..8620c4805576a 100644 --- a/installation/src/Model/DatabaseModel.php +++ b/installation/src/Model/DatabaseModel.php @@ -455,20 +455,47 @@ public function createDatabase($options) } } - if (!$db->isMinimumVersion()) + // Get required database version + $minDbVersionRequired = DatabaseHelper::getMinimumServerVersion($db, $options); + + // Check minimum database version + if (version_compare($db_version, $minDbVersionRequired) < 0) { if (in_array($type, ['mysql', 'mysqli']) && $db->isMariaDb()) { - throw new \RuntimeException(Text::sprintf('INSTL_DATABASE_INVALID_MARIADB_VERSION', $db->getMinimum(), $db_version)); + throw new \RuntimeException( + Text::sprintf( + 'INSTL_DATABASE_INVALID_MARIADB_VERSION', + $minDbVersionRequired, + $db_version + ) + ); } else { throw new \RuntimeException( - Text::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($type) . '_VERSION', $db->getMinimum(), $db_version) + Text::sprintf( + 'INSTL_DATABASE_INVALID_' . strtoupper($type) . '_VERSION', + $minDbVersionRequired, + $db_version + ) ); } } + // Check database connection encryption + if ($options->db_encryption !== 0 && empty($db->getConnectionEncryption())) + { + if ($db->isConnectionEncryptionSupported()) + { + throw new \RuntimeException(Text::_('INSTL_DATABASE_ENCRYPTION_MSG_CONN_NOT_ENCRYPT')); + } + else + { + throw new \RuntimeException(Text::_('INSTL_DATABASE_ENCRYPTION_MSG_SRV_NOT_SUPPORTS')); + } + } + // @internal Check for spaces in beginning or end of name. if (strlen(trim($options->db_name)) <> strlen($options->db_name)) { diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index b55150fc1e90a..4a0202ebd87be 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -28,33 +28,6 @@ */ class SetupModel extends BaseInstallationModel { - /** - * The minimum database server version for MariaDB databases as required by the CMS. - * This is not necessarily equal to what the database driver requires. - * - * @var string - * @since 4.0.0 - */ - protected static $dbMinimumMariaDb = '10.1'; - - /** - * The minimum database server version for MySQL databases as required by the CMS. - * This is not necessarily equal to what the database driver requires. - * - * @var string - * @since 4.0.0 - */ - protected static $dbMinimumMySql = '5.6'; - - /** - * The minimum database server version for PostgreSQL databases as required by the CMS. - * This is not necessarily equal to what the database driver requires. - * - * @var string - * @since 4.0.0 - */ - protected static $dbMinimumPostgreSql = '11.0'; - /** * Get the current setup options from the session. * @@ -563,58 +536,31 @@ public function validateDbConnection() $dbVersion = $db->getVersion(); - // Get minimum database version required by the database driver - $minDbVersionRequired = $db->getMinimum(); - - // Get minimum database version required by the CMS - if (in_array($options->db_type, ['mysql', 'mysqli'])) - { - if ($db->isMariaDb()) - { - $minDbVersionCms = self::$dbMinimumMariaDb; - } - else - { - $minDbVersionCms = self::$dbMinimumMySql; - } - } - else - { - $minDbVersionCms = self::$dbMinimumPostgreSql; - } - - // Use most restrictive minimum database version requirement - if (version_compare($minDbVersionCms, $minDbVersionRequired) > 0) - { - $minDbVersionRequired = $minDbVersionCms; - } + // Get required database version + $minDbVersionRequired = DatabaseHelper::getMinimumServerVersion($db, $options); // Check minimum database version if (version_compare($dbVersion, $minDbVersionRequired) < 0) { if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) { - Factory::getApplication()->enqueueMessage( - Text::sprintf( - 'INSTL_DATABASE_INVALID_MARIADB_VERSION', - $minDbVersionRequired, - $dbVersion - ), - 'error' + $errorMessage = Text::sprintf( + 'INSTL_DATABASE_INVALID_MARIADB_VERSION', + $minDbVersionRequired, + $dbVersion ); } else { - Factory::getApplication()->enqueueMessage( - Text::sprintf( - 'INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', - $minDbVersionRequired, - $dbVersion - ), - 'error' + $errorMessage = Text::sprintf( + 'INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', + $minDbVersionRequired, + $dbVersion ); } + Factory::getApplication()->enqueueMessage($errorMessage, 'error'); + $db->disconnect(); return false;