Issue #3192487 by andypost, murilohp, Gábor Hojtsy, daffie, pobster, apaderno: Warn about upcoming JSON database support requirement in Drupal 9

(cherry picked from commit 206d6ee658)
merge-requests/1307/merge
catch 2022-01-18 11:32:59 +00:00
parent 4387ed5ba7
commit 2a40c8fc16
4 changed files with 51 additions and 0 deletions

View File

@ -2185,4 +2185,19 @@ abstract class Connection {
return \Drupal::service('pager.manager');
}
/**
* Runs a simple query to validate json datatype support.
*
* @return bool
* Returns the query result.
*/
public function hasJson(): bool {
try {
return (bool) $this->query('SELECT JSON_TYPE(\'1\')');
}
catch (\Exception $e) {
return FALSE;
}
}
}

View File

@ -368,6 +368,18 @@ class Connection extends DatabaseConnection {
}
}
/**
* {@inheritDoc}
*/
public function hasJson(): bool {
try {
return (bool) $this->query('SELECT JSON_TYPEOF(\'1\')');
}
catch (\Exception $e) {
return FALSE;
}
}
}
/**

View File

@ -487,6 +487,22 @@ function system_requirements($phase) {
}
}
if ($phase == 'runtime') {
// Test JSON support. To be required from Drupal 10.0.
// @todo remove in https://www.drupal.org/project/drupal/issues/3203193
$requirements['database_support_json'] = [
'title' => t('Database support for JSON'),
'severity' => REQUIREMENT_OK,
'value' => t('Available'),
'description' => t('Is required in Drupal 10.0.'),
];
if (!Database::getConnection()->hasJson()) {
$requirements['database_support_json']['value'] = t('Not available');
$requirements['database_support_json']['severity'] = REQUIREMENT_WARNING;
}
}
// Test PHP memory_limit
$memory_limit = ini_get('memory_limit');
$requirements['php_memory_limit'] = [

View File

@ -91,6 +91,14 @@ class StatusTest extends BrowserTestBase {
$this->drupalGet('admin/reports/status');
$this->assertSession()->elementExists('xpath', '//details[contains(@class, "system-status-report__entry")]//div[contains(text(), "Cron has not run recently")]');
\Drupal::state()->set('system.cron_last', $cron_last_run);
// Check if JSON database support is enabled.
$this->assertSession()->pageTextContains('Database support for JSON');
$elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'Is required in Drupal 10.0.',
]);
$this->assertCount(1, $elements);
$this->assertStringStartsWith('Available', $elements[0]->getParent()->getText());
}
}