Issue #3214921 by daffie, xurizaemon, alexpott, mondrake, andypost, Taran2L, Mixologic, longwave: Add a requirements warning in Drupal 9 when PostgreSQL is used and the pg_trgm extension is not created

merge-requests/1400/head
catch 2021-11-08 14:22:26 +00:00
parent f96b7fbab0
commit 84e8b971c8
3 changed files with 47 additions and 0 deletions

View File

@ -1060,6 +1060,23 @@ EOD;
return strtr($hash, ['+' => '_', '/' => '_', '=' => '']);
}
/**
* Determines whether the PostgreSQL extension is created.
*
* @param string $name
* The name of the extension.
*
* @return bool
* Return TRUE when the extension is created, FALSE otherwise.
*
* @internal
*/
public function extensionExists($name): bool {
return (bool) $this->connection->query('SELECT installed_version FROM pg_available_extensions WHERE name = :name', [
':name' => $name,
])->fetchField();
}
}
/**

View File

@ -472,6 +472,21 @@ function system_requirements($phase) {
}
}
// Test with PostgreSQL databases for the status of the pg_trgm extension.
if ($phase === 'runtime') {
if (Database::isActiveConnection() && (Database::getConnection()->driver() == 'pgsql') && !Database::getConnection()->schema()->extensionExists('pg_trgm')) {
$requirements['pgsql_extension_pg_trgm'] = [
'severity' => REQUIREMENT_WARNING,
'title' => t('PostgreSQL pg_trgm extension'),
'value' => t('Not created'),
'description' => t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension will be required by Drupal 10 to improve performance when using PostgreSQL. See <a href=":requirements">Drupal database server requirements</a> for more information.', [
':pg_trgm' => 'https://www.postgresql.org/docs/current/pgtrgm.html',
':requirements' => 'https://www.drupal.org/docs/system-requirements/database-server-requirements',
]),
];
}
}
// Test PHP memory_limit
$memory_limit = ini_get('memory_limit');
$requirements['php_memory_limit'] = [

View File

@ -1347,4 +1347,19 @@ class SchemaTest extends KernelTestBase {
$this->assertSame('default value', $result->column7);
}
/**
* @covers \Drupal\Core\Database\Driver\pgsql\Schema::extensionExists
*/
public function testPgsqlExtensionExists() {
if ($this->connection->databaseType() !== 'pgsql') {
$this->markTestSkipped("This test only runs for PostgreSQL.");
}
// Test the method for a non existing extension.
$this->assertFalse($this->schema->extensionExists('non_existing_extension'));
// Test the method for an existing extension.
$this->assertTrue($this->schema->extensionExists('pg_trgm'));
}
}