Issue #2733675 by smccabe, murilohp, andregp, Johnny Santos, ankithashetty, mglaman, jonathanshaw, daffie, alexpott, catch, froboy: Warning when mysql is not set to READ-COMMITTED
2022-06-17 10:00:43 +00:00
< ? php
/**
* @ file
* Install , update and uninstall functions for the mysql module .
*/
use Drupal\Core\Database\Database ;
/**
* Implements hook_requirements () .
*/
function mysql_requirements ( $phase ) {
$requirements = [];
if ( $phase === 'runtime' ) {
// Test with MySql databases.
if ( Database :: isActiveConnection ()) {
$connection = Database :: getConnection ();
2022-07-16 14:56:39 +00:00
// Only show requirements when MySQL is the default database connection.
if ( ! ( $connection -> driver () === 'mysql' && $connection -> getProvider () === 'mysql' )) {
return [];
}
Issue #2733675 by smccabe, murilohp, andregp, Johnny Santos, ankithashetty, mglaman, jonathanshaw, daffie, alexpott, catch, froboy: Warning when mysql is not set to READ-COMMITTED
2022-06-17 10:00:43 +00:00
$query = 'SELECT @@SESSION.tx_isolation' ;
2022-10-03 08:58:14 +00:00
// The database variable "tx_isolation" has been removed in MySQL v8.0.3 and
Issue #2733675 by smccabe, murilohp, andregp, Johnny Santos, ankithashetty, mglaman, jonathanshaw, daffie, alexpott, catch, froboy: Warning when mysql is not set to READ-COMMITTED
2022-06-17 10:00:43 +00:00
// has been replaced by "transaction_isolation".
// @see https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_tx_isolation
2022-10-03 08:58:14 +00:00
// @see https://dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html
if ( ! $connection -> isMariaDb () && version_compare ( $connection -> version (), '8.0.2-AnyName' , '>' )) {
Issue #2733675 by smccabe, murilohp, andregp, Johnny Santos, ankithashetty, mglaman, jonathanshaw, daffie, alexpott, catch, froboy: Warning when mysql is not set to READ-COMMITTED
2022-06-17 10:00:43 +00:00
$query = 'SELECT @@SESSION.transaction_isolation' ;
}
$isolation_level = $connection -> query ( $query ) -> fetchField ();
2022-07-10 08:33:48 +00:00
$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 <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' ,
]),
];
Issue #2733675 by smccabe, murilohp, andregp, Johnny Santos, ankithashetty, mglaman, jonathanshaw, daffie, alexpott, catch, froboy: Warning when mysql is not set to READ-COMMITTED
2022-06-17 10:00:43 +00:00
}
}
return $requirements ;
}