ENH Add support for CMS5 (#144)

This commit is contained in:
Maxime Rainville 2023-03-03 10:46:09 +13:00 committed by GitHub
parent 15d4e9550b
commit fe426145d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 36 deletions

View File

@ -7,24 +7,29 @@ on:
# Every Thursday at 12:20pm UTC # Every Thursday at 12:20pm UTC
schedule: schedule:
- cron: '20 12 * * 4' - cron: '20 12 * * 4'
jobs: jobs:
ci: ci:
name: CI name: CI
# Only run cron on the silverstripe account # Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule') 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: with:
# set phpunit to false to prevent automatic generation of mysql phpunit jobs # set phpunit to false to prevent automatic generation of mysql phpunit jobs
phpunit: false phpunit: false
preserve_vendor_tests: true
extra_jobs: | extra_jobs: |
- php: 8.1 - php: 8.1
db: pgsql db: pgsql
phpunit: true phpunit: true
composer_args: --prefer-lowest composer_args: --prefer-lowest
phpunit_suite: all
- php: 8.1 - php: 8.1
db: pgsql db: pgsql
phpunit: true phpunit: true
- php: 8.1 phpunit_suite: all
- php: 8.2
db: pgsql db: pgsql
phpunit: true phpunit: true
phpunit_suite: all

View File

@ -11,9 +11,6 @@ use ErrorException;
* The connector doesn't know anything about schema selection, so code related to * 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 * masking multiple databases as schemas should be handled in the database controller
* and schema manager. * and schema manager.
*
* @package sapphire
* @subpackage model
*/ */
class PostgreSQLConnector extends DBConnector class PostgreSQLConnector extends DBConnector
{ {
@ -116,8 +113,7 @@ class PostgreSQLConnector extends DBConnector
public function getGeneratedID($table) public function getGeneratedID($table)
{ {
$result = $this->query("SELECT currval('\"{$table}_ID_seq\"')")->first(); return $this->query("SELECT currval('\"{$table}_ID_seq\"')")->value();
return $result['currval'];
} }
public function getLastError() public function getLastError()

View File

@ -574,13 +574,14 @@ class PostgreSQLDatabase extends Database
return $this->transactionNesting; return $this->transactionNesting;
} }
public function transactionEnd($chain = false) public function transactionEnd($chain = false): ?bool
{ {
--$this->transactionNesting; --$this->transactionNesting;
if ($this->transactionNesting <= 0) { if ($this->transactionNesting <= 0) {
$this->transactionNesting = 0; $this->transactionNesting = 0;
$this->query('COMMIT;'); $this->query('COMMIT;');
} }
return null;
} }
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false) public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false)

View File

@ -79,7 +79,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
public function postgresDatabaseExists($name) public function postgresDatabaseExists($name)
{ {
$result = $this->preparedQuery("SELECT datname FROM pg_database WHERE datname = ?;", array($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) public function databaseExists($name)
@ -146,7 +146,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
return $this->preparedQuery( return $this->preparedQuery(
"SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = ?;", "SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = ?;",
array($name) array($name)
)->first() ? true : false; )->value() ? true : false;
} }
/** /**
@ -462,7 +462,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
$stats = $this->preparedQuery( $stats = $this->preparedQuery(
"SELECT relid FROM pg_stat_user_tables WHERE relname = ?;", "SELECT relid FROM pg_stat_user_tables WHERE relname = ?;",
array($table) array($table)
)->first(); )->record();
$oid = $stats['relid']; $oid = $stats['relid'];
//Now we can run a long query to get the clustered status: //Now we can run a long query to get the clustered status:
@ -473,7 +473,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i 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';", WHERE c.oid = ? AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND indisclustered='t';",
array($oid) array($oid)
)->first(); )->value();
if ($clustered) { if ($clustered) {
$this->query("ALTER TABLE \"$table\" SET WITHOUT CLUSTER;"); $this->query("ALTER TABLE \"$table\" SET WITHOUT CLUSTER;");
@ -842,7 +842,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
$this->database->currentSchema(), $this->database->currentSchema(),
$triggerName $triggerName
] ]
)->first(); )->record();
// Convert stream to string // Convert stream to string
if (is_resource($trigger['tgargs'])) { if (is_resource($trigger['tgargs'])) {
@ -968,7 +968,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
WHERE r.contype = 'c' AND conname = ? AND n.nspname = ? WHERE r.contype = 'c' AND conname = ? AND n.nspname = ?
ORDER BY 1;", ORDER BY 1;",
array($constraint, $this->database->currentSchema()) array($constraint, $this->database->currentSchema())
)->first(); )->record();
if (!$cache) { if (!$cache) {
return $value; return $value;
} }
@ -1048,7 +1048,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
FROM information_schema.triggers FROM information_schema.triggers
WHERE trigger_name = ? AND trigger_schema = ?;", WHERE trigger_name = ? AND trigger_schema = ?;",
array($triggerName, $this->database->currentSchema()) array($triggerName, $this->database->currentSchema())
)->first(); )->value();
if ($exists) { if ($exists) {
$this->query("DROP trigger IF EXISTS $triggerName ON \"$tableName\";"); $this->query("DROP trigger IF EXISTS $triggerName ON \"$tableName\";");
} }
@ -1364,7 +1364,7 @@ class PostgreSQLSchemaManager extends DBSchemaManager
$existing = $this->preparedQuery( $existing = $this->preparedQuery(
"SELECT spcname, spclocation FROM pg_tablespace WHERE spcname = ?;", "SELECT spcname, spclocation FROM pg_tablespace WHERE spcname = ?;",
array($name) array($name)
)->first(); )->record();
//NOTE: this location must be empty for this to work //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 :( //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( $result = $this->preparedQuery(
"SELECT lanname FROM pg_language WHERE lanname = ?;", "SELECT lanname FROM pg_language WHERE lanname = ?;",
array($language) array($language)
)->first(); )->value();
if (!$result) { if (!$result) {
$this->query("CREATE LANGUAGE $language;"); $this->query("CREATE LANGUAGE $language;");

View File

@ -16,7 +16,8 @@
], ],
"require": { "require": {
"silverstripe/framework": "^5", "silverstripe/framework": "^5",
"silverstripe/vendor-plugin": "^2" "silverstripe/vendor-plugin": "^2",
"ext-pgsql": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.5",

View File

@ -1,17 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true"> <phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default"> <testsuite name="postgresql">
<directory>tests</directory> <directory>tests</directory>
</testsuite> <directory>vendor/silverstripe/framework/tests/php</directory>
</testsuite>
<filter> </testsuites>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
</phpunit> </phpunit>