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
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

View File

@ -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()

View File

@ -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)

View File

@ -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;");

View File

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

View File

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