From 0e721780472fecf0b70ae412c01fd008deb61314 Mon Sep 17 00:00:00 2001 From: catch Date: Sun, 10 Jul 2022 17:33:48 +0900 Subject: [PATCH] Issue #3291949 by alexpott, daffie: Improve the MySQL transaction isolation warning (cherry picked from commit 90f0da7baf979056e9083ce70814476ad40157a7) --- core/modules/mysql/mysql.install | 18 ++++++++---------- .../tests/src/Functional/RequirementsTest.php | 17 ++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/modules/mysql/mysql.install b/core/modules/mysql/mysql.install index a585abc5517..2f4f217dda0 100644 --- a/core/modules/mysql/mysql.install +++ b/core/modules/mysql/mysql.install @@ -28,16 +28,14 @@ function mysql_requirements($phase) { $isolation_level = $connection->query($query)->fetchField(); - if ($isolation_level !== 'READ-COMMITTED') { - $requirements['mysql_transaction_level'] = [ - 'title' => t('Database Isolation Level'), - 'severity' => REQUIREMENT_WARNING, - 'value' => t('Transaction Isolation Level: @value', ['@value' => $isolation_level]), - 'description' => t('For the best performance and to minimize locking issues, the READ-COMMITTED transaction isolation level is recommended.', [ - ':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level', - ]), - ]; - } + $requirements['mysql_transaction_level'] = [ + 'title' => t('Database Isolation Level'), + 'severity' => $isolation_level === 'READ-COMMITTED' ? REQUIREMENT_OK : REQUIREMENT_WARNING, + 'value' => $isolation_level, + 'description' => t('For the best performance and to minimize locking issues, the READ-COMMITTED transaction isolation level is recommended. See the setting MySQL transaction isolation level page for more information.', [ + ':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level', + ]), + ]; } } diff --git a/core/modules/mysql/tests/src/Functional/RequirementsTest.php b/core/modules/mysql/tests/src/Functional/RequirementsTest.php index e10c5f04156..d7ba5f18dce 100644 --- a/core/modules/mysql/tests/src/Functional/RequirementsTest.php +++ b/core/modules/mysql/tests/src/Functional/RequirementsTest.php @@ -45,28 +45,31 @@ class RequirementsTest extends BrowserTestBase { ]); $this->drupalLogin($admin_user); - // Change the isolation level to force the warning message. + // Set the isolation level to a level that produces a warning. $this->writeIsolationLevelSettings('REPEATABLE READ'); - // Check if the warning message is being displayed. + // Check the message is not a warning. $this->drupalGet('admin/reports/status'); $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [ ':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED', ]); $this->assertCount(1, $elements); - $this->assertStringStartsWith('Transaction Isolation Level', $elements[0]->getParent()->getText()); + $this->assertStringStartsWith('REPEATABLE-READ', $elements[0]->getParent()->getText()); + // Ensure it is a warning. + $this->assertStringContainsString('warning', $elements[0]->getParent()->getParent()->find('css', 'summary')->getAttribute('class')); // Rollback the isolation level to read committed. $this->writeIsolationLevelSettings('READ COMMITTED'); - // Check if the warning message is gone. + // Check the message is not a warning. $this->drupalGet('admin/reports/status'); - $this->assertSession()->pageTextNotContains('Database Isolation Level'); $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [ ':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED', ]); - - $this->assertCount(0, $elements); + $this->assertCount(1, $elements); + $this->assertStringStartsWith('READ-COMMITTED', $elements[0]->getParent()->getText()); + // Ensure it is a not a warning. + $this->assertStringNotContainsString('warning', $elements[0]->getParent()->getParent()->find('css', 'summary')->getAttribute('class')); } /**