From 8f60c3922c66d45b30ed692a1e27138ec8cbf414 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Tue, 27 Dec 2022 08:52:47 -0600
Subject: [PATCH] Issue #3118730 by andypost, catch: Explicitly test for
 pg_trgm extention in installer

---
 core/modules/pgsql/pgsql.install   | 42 ++++++++++++++++++++++++++++++
 core/modules/system/system.install | 28 --------------------
 2 files changed, 42 insertions(+), 28 deletions(-)
 create mode 100644 core/modules/pgsql/pgsql.install

diff --git a/core/modules/pgsql/pgsql.install b/core/modules/pgsql/pgsql.install
new file mode 100644
index 000000000000..c25620d78955
--- /dev/null
+++ b/core/modules/pgsql/pgsql.install
@@ -0,0 +1,42 @@
+<?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;
+}
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 2fd5cc4e61cc..3c589e3a5b40 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -562,34 +562,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'] = [
-- 
GitLab