From 97fc6000022344dcbe7fda63c2a553f2225cb4dd Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Sat, 11 Feb 2023 00:21:49 +1300 Subject: [PATCH] ENH Add support for CMS5 --- .github/workflows/ci.yml | 11 ++++++++--- code/PostgreSQLConnector.php | 6 +----- code/PostgreSQLDatabase.php | 3 ++- code/PostgreSQLSchemaManager.php | 24 ++++++++++++------------ composer.json | 3 ++- phpunit.xml.dist | 20 ++++++-------------- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1b2b1c..7d2b00b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,24 +7,29 @@ on: # Every Thursday at 12:20pm UTC schedule: - cron: '20 12 * * 4' - jobs: ci: name: CI # Only run cron on the silverstripe account if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule') - uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 + uses: "silverstripe/gha-ci/.github/workflows/ci.yml@v1" with: # set phpunit to false to prevent automatic generation of mysql phpunit jobs phpunit: false + preserve_vendor_tests: true extra_jobs: | - php: 8.1 db: pgsql phpunit: true composer_args: --prefer-lowest + phpunit_suite: all - php: 8.1 db: pgsql phpunit: true - - php: 8.1 + phpunit_suite: all + - php: 8.2 db: pgsql phpunit: true + phpunit_suite: all + + diff --git a/code/PostgreSQLConnector.php b/code/PostgreSQLConnector.php index 0af69d0..48cb00d 100644 --- a/code/PostgreSQLConnector.php +++ b/code/PostgreSQLConnector.php @@ -11,9 +11,6 @@ use ErrorException; * The connector doesn't know anything about schema selection, so code related to * masking multiple databases as schemas should be handled in the database controller * and schema manager. - * - * @package sapphire - * @subpackage model */ class PostgreSQLConnector extends DBConnector { @@ -116,8 +113,7 @@ class PostgreSQLConnector extends DBConnector public function getGeneratedID($table) { - $result = $this->query("SELECT currval('\"{$table}_ID_seq\"')")->first(); - return $result['currval']; + return $this->query("SELECT currval('\"{$table}_ID_seq\"')")->value(); } public function getLastError() diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index bc7f248..0187a33 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -574,13 +574,14 @@ class PostgreSQLDatabase extends Database return $this->transactionNesting; } - public function transactionEnd($chain = false) + public function transactionEnd($chain = false): ?bool { --$this->transactionNesting; if ($this->transactionNesting <= 0) { $this->transactionNesting = 0; $this->query('COMMIT;'); } + return null; } public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false) diff --git a/code/PostgreSQLSchemaManager.php b/code/PostgreSQLSchemaManager.php index cae1473..2a9d2b1 100644 --- a/code/PostgreSQLSchemaManager.php +++ b/code/PostgreSQLSchemaManager.php @@ -79,7 +79,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager public function postgresDatabaseExists($name) { $result = $this->preparedQuery("SELECT datname FROM pg_database WHERE datname = ?;", array($name)); - return $result->first() ? true : false; + return $result->value() ? true : false; } public function databaseExists($name) @@ -146,7 +146,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager return $this->preparedQuery( "SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = ?;", array($name) - )->first() ? true : false; + )->value() ? true : false; } /** @@ -462,18 +462,18 @@ class PostgreSQLSchemaManager extends DBSchemaManager $stats = $this->preparedQuery( "SELECT relid FROM pg_stat_user_tables WHERE relname = ?;", array($table) - )->first(); + )->record(); $oid = $stats['relid']; //Now we can run a long query to get the clustered status: //If anyone knows a better way to get the clustered status, then feel free to replace this! $clustered = $this->preparedQuery( " - SELECT c2.relname, i.indisclustered + SELECT c2.relname, i.indisclustered FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c.oid = ? AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND indisclustered='t';", array($oid) - )->first(); + )->value(); if ($clustered) { $this->query("ALTER TABLE \"$table\" SET WITHOUT CLUSTER;"); @@ -830,9 +830,9 @@ class PostgreSQLSchemaManager extends DBSchemaManager protected function extractTriggerColumns($triggerName, $table) { $trigger = $this->preparedQuery( - "SELECT t.tgargs + "SELECT t.tgargs FROM pg_catalog.pg_trigger t - INNER JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid + INNER JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = ? AND n.nspname = ? @@ -842,7 +842,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager $this->database->currentSchema(), $triggerName ] - )->first(); + )->record(); // Convert stream to string if (is_resource($trigger['tgargs'])) { @@ -968,7 +968,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager WHERE r.contype = 'c' AND conname = ? AND n.nspname = ? ORDER BY 1;", array($constraint, $this->database->currentSchema()) - )->first(); + )->record(); if (!$cache) { return $value; } @@ -1048,7 +1048,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager FROM information_schema.triggers WHERE trigger_name = ? AND trigger_schema = ?;", array($triggerName, $this->database->currentSchema()) - )->first(); + )->value(); if ($exists) { $this->query("DROP trigger IF EXISTS $triggerName ON \"$tableName\";"); } @@ -1364,7 +1364,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager $existing = $this->preparedQuery( "SELECT spcname, spclocation FROM pg_tablespace WHERE spcname = ?;", array($name) - )->first(); + )->record(); //NOTE: this location must be empty for this to work //We can't seem to change the location of the tablespace through any ALTER commands :( @@ -1489,7 +1489,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager $result = $this->preparedQuery( "SELECT lanname FROM pg_language WHERE lanname = ?;", array($language) - )->first(); + )->value(); if (!$result) { $this->query("CREATE LANGUAGE $language;"); diff --git a/composer.json b/composer.json index 32a05d7..77a1be4 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ ], "require": { "silverstripe/framework": "^5", - "silverstripe/vendor-plugin": "^2" + "silverstripe/vendor-plugin": "^2", + "ext-pgsql": "*" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4550b92..3c95d3f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,9 @@ - - - tests - - - - - . - - tests/ - - - - + + + tests + vendor/silverstripe/framework/tests/php + +