diff options
Diffstat (limited to 'core/modules/pgsql')
-rw-r--r-- | core/modules/pgsql/pgsql.install | 36 | ||||
-rw-r--r-- | core/modules/pgsql/src/Driver/Database/pgsql/Schema.php | 3 | ||||
-rw-r--r-- | core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php | 55 | ||||
-rw-r--r-- | core/modules/pgsql/src/Install/Requirements/PgsqlRequirements.php | 50 | ||||
-rw-r--r-- | core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecationTest.php (renamed from core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecation.php) | 9 |
5 files changed, 113 insertions, 40 deletions
diff --git a/core/modules/pgsql/pgsql.install b/core/modules/pgsql/pgsql.install index 3adeb4f5dff3..682ef7d605b5 100644 --- a/core/modules/pgsql/pgsql.install +++ b/core/modules/pgsql/pgsql.install @@ -5,42 +5,6 @@ * Install, update and uninstall functions for the pgsql module. */ -use Drupal\Core\Database\Database; - -/** - * Implements hook_requirements(). - */ -function pgsql_requirements(): array { - $requirements = []; - // Test with PostgreSQL databases for the status of the pg_trgm extension. - if (Database::isActiveConnection()) { - $connection = Database::getConnection(); - - // Set the requirement just for postgres. - if ($connection->driver() == 'pgsql') { - $requirements['pgsql_extension_pg_trgm'] = [ - 'severity' => REQUIREMENT_OK, - 'title' => t('PostgreSQL pg_trgm extension'), - 'value' => t('Available'), - 'description' => 'The pg_trgm PostgreSQL extension is present.', - ]; - - // If the extension is not available, set the requirement error. - if (!$connection->schema()->extensionExists('pg_trgm')) { - $requirements['pgsql_extension_pg_trgm']['severity'] = REQUIREMENT_ERROR; - $requirements['pgsql_extension_pg_trgm']['value'] = t('Not created'); - $requirements['pgsql_extension_pg_trgm']['description'] = t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is 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', - ]); - } - - } - } - - return $requirements; -} - /** * Implements hook_update_last_removed(). */ diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php index a4585e15da7a..440dc7179dbf 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php @@ -1072,7 +1072,8 @@ EOD; /** * Calculates a base-64 encoded PostgreSQL-safe sha-256 hash. * - * The hash is modified to according to @link https://www.postgresql.org/docs/current/sql-syntax-lexical.html PostgreSQL Lexical Structure@endlink. + * The hash is modified to according to PostgreSQL Lexical Structure. See + * https://www.postgresql.org/docs/current/sql-syntax-lexical.html. * * @param string $data * String to be hashed. diff --git a/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php b/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php new file mode 100644 index 000000000000..65fa78a5e71c --- /dev/null +++ b/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php @@ -0,0 +1,55 @@ +<?php + +namespace Drupal\pgsql\Hook; + +use Drupal\Core\Database\Database; +use Drupal\Core\Extension\Requirement\RequirementSeverity; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Hook\Attribute\Hook; + +/** + * Hook implementations for pgsql module. + */ +class PgsqlRequirementsHooks { + + use StringTranslationTrait; + + /** + * Implements hook_update_requirements(). + * + * Implements hook_runtime_requirements(). + */ + #[Hook('update_requirements')] + #[Hook('runtime_requirements')] + public function checkRequirements(): array { + $requirements = []; + // Test with PostgreSQL databases for the status of the pg_trgm extension. + if (Database::isActiveConnection()) { + $connection = Database::getConnection(); + + // Set the requirement just for postgres. + if ($connection->driver() == 'pgsql') { + $requirements['pgsql_extension_pg_trgm'] = [ + 'severity' => RequirementSeverity::OK, + 'title' => $this->t('PostgreSQL pg_trgm extension'), + 'value' => $this->t('Available'), + 'description' => $this->t('The pg_trgm PostgreSQL extension is present.'), + ]; + + // If the extension is not available, set the requirement error. + if (!$connection->schema()->extensionExists('pg_trgm')) { + $requirements['pgsql_extension_pg_trgm']['severity'] = RequirementSeverity::Error; + $requirements['pgsql_extension_pg_trgm']['value'] = $this->t('Not created'); + $requirements['pgsql_extension_pg_trgm']['description'] = $this->t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 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', + ]); + } + + } + } + + return $requirements; + } + +} diff --git a/core/modules/pgsql/src/Install/Requirements/PgsqlRequirements.php b/core/modules/pgsql/src/Install/Requirements/PgsqlRequirements.php new file mode 100644 index 000000000000..ab4b936dcba4 --- /dev/null +++ b/core/modules/pgsql/src/Install/Requirements/PgsqlRequirements.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\pgsql\Install\Requirements; + +use Drupal\Core\Database\Database; +use Drupal\Core\Extension\InstallRequirementsInterface; +use Drupal\Core\Extension\Requirement\RequirementSeverity; + +/** + * Install time requirements for the pgsql module. + */ +class PgsqlRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + // Test with PostgreSQL databases for the status of the pg_trgm extension. + if (Database::isActiveConnection()) { + $connection = Database::getConnection(); + + // Set the requirement just for postgres. + if ($connection->driver() == 'pgsql') { + $requirements['pgsql_extension_pg_trgm'] = [ + 'severity' => RequirementSeverity::OK, + 'title' => t('PostgreSQL pg_trgm extension'), + 'value' => t('Available'), + 'description' => t('The pg_trgm PostgreSQL extension is present.'), + ]; + + // If the extension is not available, set the requirement error. + if (!$connection->schema()->extensionExists('pg_trgm')) { + $requirements['pgsql_extension_pg_trgm']['severity'] = RequirementSeverity::Error; + $requirements['pgsql_extension_pg_trgm']['value'] = t('Not created'); + $requirements['pgsql_extension_pg_trgm']['description'] = t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 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', + ]); + } + + } + } + + return $requirements; + } + +} diff --git a/core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecation.php b/core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecationTest.php index db2c1b88ea37..043b5838d5ab 100644 --- a/core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecation.php +++ b/core/modules/pgsql/tests/src/Kernel/EntityQueryServiceDeprecationTest.php @@ -8,17 +8,20 @@ use Drupal\Core\Entity\Query\Sql\QueryFactory as BaseQueryFactory; use Drupal\Core\Entity\Query\Sql\pgsql\QueryFactory as DeprecatedQueryFactory; use Drupal\KernelTests\KernelTestBase; use Drupal\pgsql\EntityQuery\QueryFactory; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; /** * Tests the move of the 'pgsql.entity.query.sql' service. */ -class EntityQueryServiceDeprecation extends KernelTestBase { +#[Group('Database')] +#[Group('pgsql')] +class EntityQueryServiceDeprecationTest extends KernelTestBase { /** * Tests that the core provided service is deprecated. - * - * @group legacy */ + #[IgnoreDeprecations] public function testPostgresServiceDeprecated(): void { $running_driver = $this->container->get('database')->driver(); if ($running_driver === 'pgsql') { |