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 ;
Issue #1650930 by mkalkbrenner, gidarai, daffie, JeroenT, murilohp, jungle, acbramley, shahankitb1982, anmolgoyal74, claudiu.cristea, klausi, super_romeo, ankithashetty, longwave, pooja saraah, sahil.goyal, mikeytown2, deviantintegral, mhavelant, elgandoz, catch, andypost, pounard, neclimdul, Damien Tournoud, Charlie ChX Negyesi, danblack, larowlan: Use READ COMMITTED by default for MySQL transactions
2023-04-26 08:38:10 +00:00
use Drupal\Core\Render\Markup ;
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
/**
* 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
2024-05-04 11:48:13 +00:00
$query = $connection -> isMariaDb () ? 'SELECT @@SESSION.tx_isolation' : 'SELECT @@SESSION.transaction_isolation' ;
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
$isolation_level = $connection -> query ( $query ) -> fetchField ();
Issue #1650930 by mkalkbrenner, gidarai, daffie, JeroenT, murilohp, jungle, acbramley, shahankitb1982, anmolgoyal74, claudiu.cristea, klausi, super_romeo, ankithashetty, longwave, pooja saraah, sahil.goyal, mikeytown2, deviantintegral, mhavelant, elgandoz, catch, andypost, pounard, neclimdul, Damien Tournoud, Charlie ChX Negyesi, danblack, larowlan: Use READ COMMITTED by default for MySQL transactions
2023-04-26 08:38:10 +00:00
$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 = REQUIREMENT_OK ;
}
else {
$severity_level = REQUIREMENT_ERROR ;
}
}
else {
if ( $isolation_level == 'REPEATABLE-READ' ) {
$severity_level = REQUIREMENT_WARNING ;
}
else {
$severity_level = REQUIREMENT_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' ,
]);
2022-07-10 08:33:48 +00:00
$requirements [ 'mysql_transaction_level' ] = [
Issue #1650930 by mkalkbrenner, gidarai, daffie, JeroenT, murilohp, jungle, acbramley, shahankitb1982, anmolgoyal74, claudiu.cristea, klausi, super_romeo, ankithashetty, longwave, pooja saraah, sahil.goyal, mikeytown2, deviantintegral, mhavelant, elgandoz, catch, andypost, pounard, neclimdul, Damien Tournoud, Charlie ChX Negyesi, danblack, larowlan: Use READ COMMITTED by default for MySQL transactions
2023-04-26 08:38:10 +00:00
'title' => t ( 'Transaction isolation level' ),
'severity' => $severity_level ,
2022-07-10 08:33:48 +00:00
'value' => $isolation_level ,
Issue #1650930 by mkalkbrenner, gidarai, daffie, JeroenT, murilohp, jungle, acbramley, shahankitb1982, anmolgoyal74, claudiu.cristea, klausi, super_romeo, ankithashetty, longwave, pooja saraah, sahil.goyal, mikeytown2, deviantintegral, mhavelant, elgandoz, catch, andypost, pounard, neclimdul, Damien Tournoud, Charlie ChX Negyesi, danblack, larowlan: Use READ COMMITTED by default for MySQL transactions
2023-04-26 08:38:10 +00:00
'description' => Markup :: create ( implode ( ' ' , $description )),
2022-07-10 08:33:48 +00:00
];
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 ;
}