summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/mysqli
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/mysqli')
-rw-r--r--core/modules/mysqli/mysqli.install78
-rw-r--r--core/modules/mysqli/src/Hook/MysqliHooks.php70
2 files changed, 70 insertions, 78 deletions
diff --git a/core/modules/mysqli/mysqli.install b/core/modules/mysqli/mysqli.install
deleted file mode 100644
index 7f1147d63adb..000000000000
--- a/core/modules/mysqli/mysqli.install
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-
-/**
- * @file
- * Install, update and uninstall functions for the mysqli module.
- */
-
-use Drupal\Core\Database\Database;
-use Drupal\Core\Extension\Requirement\RequirementSeverity;
-use Drupal\Core\Render\Markup;
-
-/**
- * Implements hook_requirements().
- */
-function mysqli_requirements($phase): array {
- $requirements = [];
-
- if ($phase === 'runtime') {
- // Test with MySql databases.
- if (Database::isActiveConnection()) {
- $connection = Database::getConnection();
- // Only show requirements when MySQLi is the default database connection.
- if (!($connection->driver() === 'mysqli' && $connection->getProvider() === 'mysqli')) {
- return [];
- }
-
- $query = $connection->isMariaDb() ? 'SELECT @@SESSION.tx_isolation' : 'SELECT @@SESSION.transaction_isolation';
-
- $isolation_level = $connection->query($query)->fetchField();
-
- $tables_missing_primary_key = [];
- $tables = $connection->schema()->findTables('%');
- foreach ($tables as $table) {
- $primary_key_column = Database::getConnection()->query("SHOW KEYS FROM {" . $table . "} WHERE Key_name = 'PRIMARY'")->fetchAllAssoc('Column_name');
- if (empty($primary_key_column)) {
- $tables_missing_primary_key[] = $table;
- }
- }
-
- $description = [];
- if ($isolation_level == 'READ-COMMITTED') {
- if (empty($tables_missing_primary_key)) {
- $severity_level = RequirementSeverity::OK;
- }
- else {
- $severity_level = RequirementSeverity::Error;
- }
- }
- else {
- if ($isolation_level == 'REPEATABLE-READ') {
- $severity_level = RequirementSeverity::Warning;
- }
- else {
- $severity_level = RequirementSeverity::Error;
- $description[] = t('This is not supported by Drupal.');
- }
- $description[] = t('The recommended level for Drupal is "READ COMMITTED".');
- }
-
- if (!empty($tables_missing_primary_key)) {
- $description[] = t('For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: @tables.', ['@tables' => implode(', ', $tables_missing_primary_key)]);
- }
-
- $description[] = t('See the <a href=":performance_doc">setting MySQL transaction isolation level</a> page for more information.', [
- ':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level',
- ]);
-
- $requirements['mysql_transaction_level'] = [
- 'title' => t('Transaction isolation level'),
- 'severity' => $severity_level,
- 'value' => $isolation_level,
- 'description' => Markup::create(implode(' ', $description)),
- ];
- }
- }
-
- return $requirements;
-}
diff --git a/core/modules/mysqli/src/Hook/MysqliHooks.php b/core/modules/mysqli/src/Hook/MysqliHooks.php
index 5fae187d16c7..340b17373a12 100644
--- a/core/modules/mysqli/src/Hook/MysqliHooks.php
+++ b/core/modules/mysqli/src/Hook/MysqliHooks.php
@@ -2,7 +2,10 @@
namespace Drupal\mysqli\Hook;
+use Drupal\Core\Database\Database;
+use Drupal\Core\Extension\Requirement\RequirementSeverity;
use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -29,4 +32,71 @@ class MysqliHooks {
return NULL;
}
+ /**
+ * Implements hook_runtime_requirements().
+ */
+ #[Hook('runtime_requirements')]
+ public function runtimeRequirements(): array {
+ $requirements = [];
+
+ // Test with MySql databases.
+ if (Database::isActiveConnection()) {
+ $connection = Database::getConnection();
+ // Only show requirements when MySQLi is the default database connection.
+ if (!($connection->driver() === 'mysqli' && $connection->getProvider() === 'mysqli')) {
+ return [];
+ }
+
+ $query = $connection->isMariaDb() ? 'SELECT @@SESSION.tx_isolation' : 'SELECT @@SESSION.transaction_isolation';
+
+ $isolation_level = $connection->query($query)->fetchField();
+
+ $tables_missing_primary_key = [];
+ $tables = $connection->schema()->findTables('%');
+ foreach ($tables as $table) {
+ $primary_key_column = Database::getConnection()->query("SHOW KEYS FROM {" . $table . "} WHERE Key_name = 'PRIMARY'")->fetchAllAssoc('Column_name');
+ if (empty($primary_key_column)) {
+ $tables_missing_primary_key[] = $table;
+ }
+ }
+
+ $description = [];
+ if ($isolation_level == 'READ-COMMITTED') {
+ if (empty($tables_missing_primary_key)) {
+ $severity_level = RequirementSeverity::OK;
+ }
+ else {
+ $severity_level = RequirementSeverity::Error;
+ }
+ }
+ else {
+ if ($isolation_level == 'REPEATABLE-READ') {
+ $severity_level = RequirementSeverity::Warning;
+ }
+ else {
+ $severity_level = RequirementSeverity::Error;
+ $description[] = $this->t('This is not supported by Drupal.');
+ }
+ $description[] = $this->t('The recommended level for Drupal is "READ COMMITTED".');
+ }
+
+ if (!empty($tables_missing_primary_key)) {
+ $description[] = $this->t('For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: @tables.', ['@tables' => implode(', ', $tables_missing_primary_key)]);
+ }
+
+ $description[] = $this->t('See the <a href=":performance_doc">setting MySQL transaction isolation level</a> page for more information.', [
+ ':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level',
+ ]);
+
+ $requirements['mysql_transaction_level'] = [
+ 'title' => $this->t('Transaction isolation level'),
+ 'severity' => $severity_level,
+ 'value' => $isolation_level,
+ 'description' => Markup::create(implode(' ', $description)),
+ ];
+ }
+
+ return $requirements;
+ }
+
}