diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php index 47b973b..b230e06 100644 --- a/core/lib/Drupal/Core/Database/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Install/Tasks.php @@ -152,6 +152,19 @@ public function runTasks() { } /** + * Checks engine version requirements for the status report. + * + * This method is called during runtime and update requirements checks. + * + * @return string[] + * A list of error messages. + */ + final public function engineVersionRequirementsCheck() { + $this->checkEngineVersion(); + return $this->results['fail']; + } + + /** * Check if we can connect to the database. */ protected function connect() { diff --git a/core/modules/system/system.install b/core/modules/system/system.install index ee35c1c..0a8166a 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -427,9 +427,11 @@ function system_requirements($phase) { $requirements['database_extensions']['value'] = t('Enabled'); } } - else { + + if ($phase === 'runtime' || $phase === 'update') { // Database information. $class = Database::getConnection()->getDriverClass('Install\\Tasks'); + /** @var \Drupal\Core\Database\Install\Tasks $tasks */ $tasks = new $class(); $requirements['database_system'] = [ 'title' => t('Database system'), @@ -439,6 +441,19 @@ function system_requirements($phase) { 'title' => t('Database system version'), 'value' => Database::getConnection()->version(), ]; + + $errors = $tasks->engineVersionRequirementsCheck(); + $error_count = count($errors); + if ($error_count > 0) { + $error_message = [ + '#theme' => 'item_list', + '#items' => $errors, + // Use the comma-list style to display a single error without bullets. + '#context' => ['list_style' => $error_count == 1 ? 'comma-list' : ''], + ]; + $requirements['database_system_version']['severity'] = REQUIREMENT_ERROR; + $requirements['database_system_version']['description'] = $error_message; + } } // Test PHP memory_limit diff --git a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Connection.php b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Connection.php new file mode 100644 index 0000000..ee24a40 --- /dev/null +++ b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Connection.php @@ -0,0 +1,56 @@ +databaseVersion; + } + + /** + * {@inheritdoc} + */ + public function clientVersion() { + return $this->databaseVersion; + } + + /** + * {@inheritdoc} + */ + protected function getServerVersion(): string { + return $this->databaseVersion; + } + +} diff --git a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Insert.php b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Insert.php new file mode 100644 index 0000000..86affc1 --- /dev/null +++ b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Insert.php @@ -0,0 +1,10 @@ +ensureUpdatesToRun(); + } + + /** + * Tests that updates fail if the database does not meet the minimum version. + */ + public function testUpdate() { + if (Database::getConnection()->driver() !== 'mysql') { + $this->markTestSkipped('This test only works with the mysql driver'); + } + + // Use a database driver that fakes the database version to one that does + // not meet requirements. + $connection = Database::getConnectionInfo()['default']; + unset($connection['init_commands'], $connection['pdo'], $connection['prefix']); + $connection['driver'] = 'DrivertestMysqlDeprecatedVersion'; + $connection['namespace'] = 'Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion'; + $connection['autoload'] = 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion'; + $settings['databases']['default']['default'] = (object) [ + 'value' => $connection, + 'required' => TRUE, + ]; + $settings['settings'] = [ + 'update_free_access' => (object) [ + 'value' => TRUE, + 'required' => TRUE, + ], + ]; + $this->writeSettings($settings); + + $this->drupalGet(Url::fromRoute('system.db_update')); + $this->assertSession()->pageTextContains('Errors found'); + $this->assertSession()->pageTextContains('The database server version 10.2.31-MariaDB-1:10.2.31+maria~bionic-log is less than the minimum required version'); + } + +}