Skip to content

Commit fe42614

Browse files
author
Maxime Rainville
authored
ENH Add support for CMS5 (#144)
1 parent 15d4e95 commit fe42614

File tree

6 files changed

+31
-36
lines changed

6 files changed

+31
-36
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@ on:
77
# Every Thursday at 12:20pm UTC
88
schedule:
99
- cron: '20 12 * * 4'
10-
1110
jobs:
1211
ci:
1312
name: CI
1413
# Only run cron on the silverstripe account
1514
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
16-
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
15+
uses: "silverstripe/gha-ci/.github/workflows/ci.yml@v1"
1716
with:
1817
# set phpunit to false to prevent automatic generation of mysql phpunit jobs
1918
phpunit: false
19+
preserve_vendor_tests: true
2020
extra_jobs: |
2121
- php: 8.1
2222
db: pgsql
2323
phpunit: true
2424
composer_args: --prefer-lowest
25+
phpunit_suite: all
2526
- php: 8.1
2627
db: pgsql
2728
phpunit: true
28-
- php: 8.1
29+
phpunit_suite: all
30+
- php: 8.2
2931
db: pgsql
3032
phpunit: true
33+
phpunit_suite: all
34+
35+

code/PostgreSQLConnector.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
* The connector doesn't know anything about schema selection, so code related to
1212
* masking multiple databases as schemas should be handled in the database controller
1313
* and schema manager.
14-
*
15-
* @package sapphire
16-
* @subpackage model
1714
*/
1815
class PostgreSQLConnector extends DBConnector
1916
{
@@ -116,8 +113,7 @@ public function affectedRows()
116113

117114
public function getGeneratedID($table)
118115
{
119-
$result = $this->query("SELECT currval('\"{$table}_ID_seq\"')")->first();
120-
return $result['currval'];
116+
return $this->query("SELECT currval('\"{$table}_ID_seq\"')")->value();
121117
}
122118

123119
public function getLastError()

code/PostgreSQLDatabase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,14 @@ public function transactionDepth()
574574
return $this->transactionNesting;
575575
}
576576

577-
public function transactionEnd($chain = false)
577+
public function transactionEnd($chain = false): ?bool
578578
{
579579
--$this->transactionNesting;
580580
if ($this->transactionNesting <= 0) {
581581
$this->transactionNesting = 0;
582582
$this->query('COMMIT;');
583583
}
584+
return null;
584585
}
585586

586587
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false)

code/PostgreSQLSchemaManager.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function createDatabase($name)
7979
public function postgresDatabaseExists($name)
8080
{
8181
$result = $this->preparedQuery("SELECT datname FROM pg_database WHERE datname = ?;", array($name));
82-
return $result->first() ? true : false;
82+
return $result->value() ? true : false;
8383
}
8484

8585
public function databaseExists($name)
@@ -146,7 +146,7 @@ public function schemaExists($name)
146146
return $this->preparedQuery(
147147
"SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = ?;",
148148
array($name)
149-
)->first() ? true : false;
149+
)->value() ? true : false;
150150
}
151151

152152
/**
@@ -462,18 +462,18 @@ public function alterTable(
462462
$stats = $this->preparedQuery(
463463
"SELECT relid FROM pg_stat_user_tables WHERE relname = ?;",
464464
array($table)
465-
)->first();
465+
)->record();
466466
$oid = $stats['relid'];
467467

468468
//Now we can run a long query to get the clustered status:
469469
//If anyone knows a better way to get the clustered status, then feel free to replace this!
470470
$clustered = $this->preparedQuery(
471471
"
472-
SELECT c2.relname, i.indisclustered
472+
SELECT c2.relname, i.indisclustered
473473
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
474474
WHERE c.oid = ? AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND indisclustered='t';",
475475
array($oid)
476-
)->first();
476+
)->value();
477477

478478
if ($clustered) {
479479
$this->query("ALTER TABLE \"$table\" SET WITHOUT CLUSTER;");
@@ -830,9 +830,9 @@ public function alterIndex($tableName, $indexName, $indexSpec)
830830
protected function extractTriggerColumns($triggerName, $table)
831831
{
832832
$trigger = $this->preparedQuery(
833-
"SELECT t.tgargs
833+
"SELECT t.tgargs
834834
FROM pg_catalog.pg_trigger t
835-
INNER JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
835+
INNER JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
836836
INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
837837
WHERE c.relname = ?
838838
AND n.nspname = ?
@@ -842,7 +842,7 @@ protected function extractTriggerColumns($triggerName, $table)
842842
$this->database->currentSchema(),
843843
$triggerName
844844
]
845-
)->first();
845+
)->record();
846846

847847
// Convert stream to string
848848
if (is_resource($trigger['tgargs'])) {
@@ -968,7 +968,7 @@ protected function constraintExists($constraint, $cache = true)
968968
WHERE r.contype = 'c' AND conname = ? AND n.nspname = ?
969969
ORDER BY 1;",
970970
array($constraint, $this->database->currentSchema())
971-
)->first();
971+
)->record();
972972
if (!$cache) {
973973
return $value;
974974
}
@@ -1048,7 +1048,7 @@ protected function dropTrigger($triggerName, $tableName)
10481048
FROM information_schema.triggers
10491049
WHERE trigger_name = ? AND trigger_schema = ?;",
10501050
array($triggerName, $this->database->currentSchema())
1051-
)->first();
1051+
)->value();
10521052
if ($exists) {
10531053
$this->query("DROP trigger IF EXISTS $triggerName ON \"$tableName\";");
10541054
}
@@ -1364,7 +1364,7 @@ public function createOrReplaceTablespace($name, $location)
13641364
$existing = $this->preparedQuery(
13651365
"SELECT spcname, spclocation FROM pg_tablespace WHERE spcname = ?;",
13661366
array($name)
1367-
)->first();
1367+
)->record();
13681368

13691369
//NOTE: this location must be empty for this to work
13701370
//We can't seem to change the location of the tablespace through any ALTER commands :(
@@ -1489,7 +1489,7 @@ public function createLanguage($language)
14891489
$result = $this->preparedQuery(
14901490
"SELECT lanname FROM pg_language WHERE lanname = ?;",
14911491
array($language)
1492-
)->first();
1492+
)->value();
14931493

14941494
if (!$result) {
14951495
$this->query("CREATE LANGUAGE $language;");

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
],
1717
"require": {
1818
"silverstripe/framework": "^5",
19-
"silverstripe/vendor-plugin": "^2"
19+
"silverstripe/vendor-plugin": "^2",
20+
"ext-pgsql": "*"
2021
},
2122
"require-dev": {
2223
"phpunit/phpunit": "^9.5",

phpunit.xml.dist

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
3-
4-
<testsuite name="Default">
5-
<directory>tests</directory>
6-
</testsuite>
7-
8-
<filter>
9-
<whitelist addUncoveredFilesFromWhitelist="true">
10-
<directory suffix=".php">.</directory>
11-
<exclude>
12-
<directory suffix=".php">tests/</directory>
13-
</exclude>
14-
</whitelist>
15-
</filter>
16-
3+
<testsuites>
4+
<testsuite name="postgresql">
5+
<directory>tests</directory>
6+
<directory>vendor/silverstripe/framework/tests/php</directory>
7+
</testsuite>
8+
</testsuites>
179
</phpunit>

0 commit comments

Comments
 (0)