Commit 84e8b971 authored by catch's avatar catch
Browse files

Issue #3214921 by daffie, xurizaemon, alexpott, mondrake, andypost, Taran2L,...

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
parent f96b7fba
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1060,6 +1060,23 @@ protected function hashBase64($data) {
    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();
  }

}

/**
+15 −0
Original line number Diff line number Diff line
@@ -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'] = [
+15 −0
Original line number Diff line number Diff line
@@ -1347,4 +1347,19 @@ public function testDefaultAfterAlter() {
    $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'));
  }

}