Verified Commit fd82a96f authored by Jess's avatar Jess
Browse files

Issue #3118730 by andypost, daffie, catch, xjm: Explicitly test for pg_trgm extention in installer

parent db906a7b
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, update and uninstall functions for the pgsql module.
 */

use Drupal\Core\Database\Database;

/**
 * Implements hook_requirements().
 */
function pgsql_requirements() {
  $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;
}
+0 −28
Original line number Diff line number Diff line
@@ -570,34 +570,6 @@ function system_requirements($phase) {
    }
  }

  // Test with PostgreSQL databases for the status of the pg_trgm extension.
  if ($phase === 'runtime' || $phase === 'update') {
    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',
          ]);
        }

      }
    }
  }

  if ($phase === 'runtime' || $phase === 'update') {
    // Test database JSON support.
    $requirements['database_support_json'] = [