aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/PgSqlTools.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/DB/PgSqlTools.php')
-rw-r--r--lib/private/DB/PgSqlTools.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/private/DB/PgSqlTools.php b/lib/private/DB/PgSqlTools.php
index 724344ac2a1..d555bfb391b 100644
--- a/lib/private/DB/PgSqlTools.php
+++ b/lib/private/DB/PgSqlTools.php
@@ -26,7 +26,10 @@
namespace OC\DB;
+use Doctrine\DBAL\Schema\AbstractAsset;
use OCP\IConfig;
+use function preg_match;
+use function preg_quote;
/**
* Various PostgreSQL specific helper functions.
@@ -50,20 +53,30 @@ class PgSqlTools {
* @return null
*/
public function resynchronizeDatabaseSequences(Connection $conn) {
- $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
$databaseName = $conn->getDatabase();
- $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
+ $conn->getConfiguration()->setSchemaAssetsFilter(function ($asset) {
+ /** @var string|AbstractAsset $asset */
+ $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
+ if ($asset instanceof AbstractAsset) {
+ return preg_match($filterExpression, $asset->getName()) !== false;
+ }
+ return preg_match($filterExpression, $asset) !== false;
+ });
foreach ($conn->getSchemaManager()->listSequences() as $sequence) {
$sequenceName = $sequence->getName();
$sqlInfo = 'SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE column_default = ? AND table_catalog = ?';
- $sequenceInfo = $conn->fetchAssoc($sqlInfo, [
+ $result = $conn->executeQuery($sqlInfo, [
"nextval('$sequenceName'::regclass)",
$databaseName
]);
+ $sequenceInfo = $result->fetchAssociative();
+ $result->free();
+ /** @var string $tableName */
$tableName = $sequenceInfo['table_name'];
+ /** @var string $columnName */
$columnName = $sequenceInfo['column_name'];
$sqlMaxId = "SELECT MAX($columnName) FROM $tableName";
$sqlSetval = "SELECT setval('$sequenceName', ($sqlMaxId))";