Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions installation/src/Helper/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
33 changes: 30 additions & 3 deletions installation/src/Model/DatabaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
78 changes: 12 additions & 66 deletions installation/src/Model/SetupModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down