Skip to content

Commit

Permalink
ENH Add support for CMS5 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville authored Mar 2, 2023
1 parent 15d4e95 commit fe42614
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions code/PostgreSQLConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
* 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
{
Expand Down Expand Up @@ -116,8 +113,7 @@ public function affectedRows()

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()
Expand Down
3 changes: 2 additions & 1 deletion code/PostgreSQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,14 @@ public function transactionDepth()
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)
Expand Down
24 changes: 12 additions & 12 deletions code/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function createDatabase($name)
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)
Expand Down Expand Up @@ -146,7 +146,7 @@ public function schemaExists($name)
return $this->preparedQuery(
"SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = ?;",
array($name)
)->first() ? true : false;
)->value() ? true : false;
}

/**
Expand Down Expand Up @@ -462,18 +462,18 @@ public function alterTable(
$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;");
Expand Down Expand Up @@ -830,9 +830,9 @@ public function alterIndex($tableName, $indexName, $indexSpec)
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 = ?
Expand All @@ -842,7 +842,7 @@ protected function extractTriggerColumns($triggerName, $table)
$this->database->currentSchema(),
$triggerName
]
)->first();
)->record();

// Convert stream to string
if (is_resource($trigger['tgargs'])) {
Expand Down Expand Up @@ -968,7 +968,7 @@ protected function constraintExists($constraint, $cache = true)
WHERE r.contype = 'c' AND conname = ? AND n.nspname = ?
ORDER BY 1;",
array($constraint, $this->database->currentSchema())
)->first();
)->record();
if (!$cache) {
return $value;
}
Expand Down Expand Up @@ -1048,7 +1048,7 @@ protected function dropTrigger($triggerName, $tableName)
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\";");
}
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public function createOrReplaceTablespace($name, $location)
$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 :(
Expand Down Expand Up @@ -1489,7 +1489,7 @@ public function createLanguage($language)
$result = $this->preparedQuery(
"SELECT lanname FROM pg_language WHERE lanname = ?;",
array($language)
)->first();
)->value();

if (!$result) {
$this->query("CREATE LANGUAGE $language;");
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"require": {
"silverstripe/framework": "^5",
"silverstripe/vendor-plugin": "^2"
"silverstripe/vendor-plugin": "^2",
"ext-pgsql": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit fe42614

Please sign in to comment.