From 4755465a01567c6aea8abddc9639755b5779f4ce Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 14:53:16 +0100 Subject: [PATCH 1/9] Add minimum db version check to setup model --- installation/src/Model/SetupModel.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index 9c392445b552a..c096ab5fde87f 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -519,6 +519,8 @@ public function validateDbConnection() ); $db->connect(); + + $dbVersion = $db->getVersion(); } catch (\RuntimeException $e) { @@ -527,6 +529,28 @@ public function validateDbConnection() return false; } + // Check minimum database version + if (!$db->isMinimumVersion()) + { + if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) + { + Factory::getApplication()->enqueueMessage( + Text::sprintf('INSTL_DATABASE_INVALID_MARIADB_VERSION', $db->getMinimum(), $dbVersion), + 'error' + ); + } + else + { + Factory::getApplication()->enqueueMessage( + Text::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', $db->getMinimum(), $dbVersion), + 'error' + ); + } + + return false; + } + + // Check database connection encryption if ($options->db_encryption !== 0 && empty($db->getConnectionEncryption())) { if ($db->isConnectionEncryptionSupported()) From 1156b925e8b2b99b328376dc4316dcb8fe61394f Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 20:29:50 +0100 Subject: [PATCH 2/9] Add check for the CMS' database version requirement --- installation/src/Model/SetupModel.php | 80 +++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 10 deletions(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index c096ab5fde87f..d7ac18bac8b0d 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -28,6 +28,33 @@ */ class SetupModel extends BaseInstallationModel { + /** + * The minimum database server version for MariaDB databases as reqruied by the CMS. + * This is not necessarily equal to what the database driver requires. + * + * @var string + * @since 4.0.0 + */ + protected static $dbMinimumMariaDb = '10.0'; + + /** + * The minimum database server version for MySQL databases as reqruied 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 reqruied 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. * @@ -519,8 +546,6 @@ public function validateDbConnection() ); $db->connect(); - - $dbVersion = $db->getVersion(); } catch (\RuntimeException $e) { @@ -529,23 +554,58 @@ public function validateDbConnection() return false; } - // Check minimum database version - if (!$db->isMinimumVersion()) + $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 (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) + if ($db->isMariaDb()) { - Factory::getApplication()->enqueueMessage( - Text::sprintf('INSTL_DATABASE_INVALID_MARIADB_VERSION', $db->getMinimum(), $dbVersion), - 'error' - ); + $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; + } + + // Check minimum database version as reqruied by the CMS + if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) + { + // MariaDB: Check with sanitized version string + if (version_compare(preg_replace('/^5\.5\.5-/', '', $dbVersion), $minDbVersionRequired) < 0) { Factory::getApplication()->enqueueMessage( - Text::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', $db->getMinimum(), $dbVersion), + Text::sprintf('INSTL_DATABASE_INVALID_MARIADB_VERSION', $minDbVersionRequired, $dbVersion), 'error' ); + + return false; } + } + elseif (version_compare($dbVersion, $minDbVersionRequired) < 0) + { + Factory::getApplication()->enqueueMessage( + Text::sprintf( + 'INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', + $minDbVersionRequired, + $dbVersion + ), + 'error' + ); return false; } From 614bc99a78cbedb13c9823e4e3c7ff7efade2161 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 21:16:26 +0100 Subject: [PATCH 3/9] Thanks @Quy for having found my silly typo - 1 Co-Authored-By: Quy --- installation/src/Model/SetupModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index d7ac18bac8b0d..dc4b6b02f28b6 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -29,7 +29,7 @@ class SetupModel extends BaseInstallationModel { /** - * The minimum database server version for MariaDB databases as reqruied by the CMS. + * 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 From 648f1a87112747471f5db78dcc462f8795d52627 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 21:17:58 +0100 Subject: [PATCH 4/9] Thanks @Quy for having found my silly typo - 2 and 3 --- installation/src/Model/SetupModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index dc4b6b02f28b6..fafe1a46519f1 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -38,7 +38,7 @@ class SetupModel extends BaseInstallationModel protected static $dbMinimumMariaDb = '10.0'; /** - * The minimum database server version for MySQL databases as reqruied by the CMS. + * 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 @@ -47,7 +47,7 @@ class SetupModel extends BaseInstallationModel protected static $dbMinimumMySql = '5.6'; /** - * The minimum database server version for PostgreSQL databases as reqruied by the CMS. + * 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 From 737ed900054658934c55848f90235b51f02d397c Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 23:54:37 +0100 Subject: [PATCH 5/9] Another typo, thanks @zero-24 Co-Authored-By: Tobias Zulauf --- installation/src/Model/SetupModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index fafe1a46519f1..1b07bcc044c2b 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -582,7 +582,7 @@ public function validateDbConnection() $minDbVersionRequired = $minDbVersionCms; } - // Check minimum database version as reqruied by the CMS + // Check minimum database version as required by the CMS if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) { // MariaDB: Check with sanitized version string From 0e79335f11fba4db7bbbb1e43bc48dd5508c245e Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sat, 29 Feb 2020 23:55:19 +0100 Subject: [PATCH 6/9] CS Co-Authored-By: Tobias Zulauf --- installation/src/Model/SetupModel.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index 1b07bcc044c2b..5bd80ed7d48a2 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -589,7 +589,11 @@ public function validateDbConnection() if (version_compare(preg_replace('/^5\.5\.5-/', '', $dbVersion), $minDbVersionRequired) < 0) { Factory::getApplication()->enqueueMessage( - Text::sprintf('INSTL_DATABASE_INVALID_MARIADB_VERSION', $minDbVersionRequired, $dbVersion), + Text::sprintf( + 'INSTL_DATABASE_INVALID_MARIADB_VERSION', + $minDbVersionRequired, + $dbVersion + ), 'error' ); From e7056debd7c91f99113c0ca2e4efb9cf5d22d62f Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 1 Mar 2020 00:04:48 +0100 Subject: [PATCH 7/9] Fix MariaDb version requirement Co-Authored-By: Tobias Zulauf --- installation/src/Model/SetupModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index 5bd80ed7d48a2..c2de705bd5abd 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -35,7 +35,7 @@ class SetupModel extends BaseInstallationModel * @var string * @since 4.0.0 */ - protected static $dbMinimumMariaDb = '10.0'; + protected static $dbMinimumMariaDb = '10.1'; /** * The minimum database server version for MySQL databases as required by the CMS. From 44bc30f1f59b07641dbc81f74ccebbe149fd6cdc Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 1 Mar 2020 13:25:23 +0100 Subject: [PATCH 8/9] Same version check for MariaDB --- installation/src/Model/SetupModel.php | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index c2de705bd5abd..6acf5ccc8adf6 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -582,11 +582,10 @@ public function validateDbConnection() $minDbVersionRequired = $minDbVersionCms; } - // Check minimum database version as required by the CMS - if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) + // Check minimum database version + if (version_compare($dbVersion, $minDbVersionRequired) < 0) { - // MariaDB: Check with sanitized version string - if (version_compare(preg_replace('/^5\.5\.5-/', '', $dbVersion), $minDbVersionRequired) < 0) + if (in_array($options->db_type, ['mysql', 'mysqli']) && $db->isMariaDb()) { Factory::getApplication()->enqueueMessage( Text::sprintf( @@ -596,20 +595,18 @@ public function validateDbConnection() ), 'error' ); - - return false; } - } - elseif (version_compare($dbVersion, $minDbVersionRequired) < 0) - { - Factory::getApplication()->enqueueMessage( - Text::sprintf( - 'INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', - $minDbVersionRequired, - $dbVersion - ), - 'error' - ); + else + { + Factory::getApplication()->enqueueMessage( + Text::sprintf( + 'INSTL_DATABASE_INVALID_' . strtoupper($options->db_type) . '_VERSION', + $minDbVersionRequired, + $dbVersion + ), + 'error' + ); + } return false; } From e2fb85ba60ec65ca73b013657745b1f93c8d4e55 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 1 Mar 2020 17:06:33 +0100 Subject: [PATCH 9/9] Disconnect after unsuccessful version check --- installation/src/Model/SetupModel.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/installation/src/Model/SetupModel.php b/installation/src/Model/SetupModel.php index 6acf5ccc8adf6..c9a68d21e4d47 100644 --- a/installation/src/Model/SetupModel.php +++ b/installation/src/Model/SetupModel.php @@ -608,6 +608,8 @@ public function validateDbConnection() ); } + $db->disconnect(); + return false; }