From 51f3f2cce10868167bf9056bb9fce32b93fd453f Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Mon, 11 Sep 2023 14:44:44 +0200 Subject: [PATCH 1/5] fix(php): Repair the SQL request when upgrading When we upgrade the workspace app 2.0.1 to 3.0.X. We have a problem using double quotes for an expression, because the expression is interpreted as a column. Signed-off-by: Baptiste Fotia --- lib/Db/GroupFoldersGroupsMapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Db/GroupFoldersGroupsMapper.php b/lib/Db/GroupFoldersGroupsMapper.php index 9f7635eb7..790968f41 100644 --- a/lib/Db/GroupFoldersGroupsMapper.php +++ b/lib/Db/GroupFoldersGroupsMapper.php @@ -60,8 +60,8 @@ public function getSpacenamesGroupIds() { 'gf_groups.folder_id' ) ) - ->where('group_id not like "SPACE-GE%"') - ->andWhere('group_id not like "SPACE-U%"'); + ->where('group_id not like \'SPACE-GE%\'') + ->andWhere('group_id not like \'SPACE-U%\''); return $qb->executeQuery()->fetchAll(); } From 3425eaa206a51b1a3bc5d5076509dcc24f31bb6f Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Mon, 11 Sep 2023 19:07:49 +0200 Subject: [PATCH 2/5] feat(php): Rerun the change groupnames for pgsql Rerun the change groupnames for pgsql when the control migration is to false. Signed-off-by: Baptiste Fotia --- appinfo/info.xml | 1 + .../ReRunChangeGroupnamesForPgSql.php | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/Migration/ReRunChangeGroupnamesForPgSql.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 22fb00ecb..1529d4f11 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -90,6 +90,7 @@ For this version, you should refresh your browser from the Workspace app with `C OCA\Workspace\Migration\ChangeGroupnamesV300 OCA\Workspace\Migration\FixMigrationToV300 + OCA\Workspace\Migration\ReRunChangeGroupnamesForPgSql OCA\Workspace\Migration\RegisterWorkspaceUsersGroup diff --git a/lib/Migration/ReRunChangeGroupnamesForPgSql.php b/lib/Migration/ReRunChangeGroupnamesForPgSql.php new file mode 100644 index 000000000..027e78fec --- /dev/null +++ b/lib/Migration/ReRunChangeGroupnamesForPgSql.php @@ -0,0 +1,45 @@ +config->getSystemValue('dbtype'); + + if ($sgbdName !== 'pgsql') + { + return; + } + + $statusMigration = boolval($this->appConfig->getAppValue(Upgrade::CONTROL_MIGRATION_V3, '1')); + + if ($statusMigration === true) + { + return; + } + + $this->upgrade->upgrade(); + } +} From a9c70be7efc0ba639cf38b41c9c8ed9dd86c9e4f Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Tue, 26 Mar 2024 16:35:27 +0100 Subject: [PATCH 3/5] style(php): Run composer run cs:fix Signed-off-by: Baptiste Fotia --- .../ReRunChangeGroupnamesForPgSql.php | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/lib/Migration/ReRunChangeGroupnamesForPgSql.php b/lib/Migration/ReRunChangeGroupnamesForPgSql.php index 027e78fec..60b5faa51 100644 --- a/lib/Migration/ReRunChangeGroupnamesForPgSql.php +++ b/lib/Migration/ReRunChangeGroupnamesForPgSql.php @@ -2,44 +2,38 @@ namespace OCA\Workspace\Migration; -use OCP\IConfig; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; use OCA\Workspace\Upgrade\Upgrade; use OCA\Workspace\Upgrade\UpgradeV300; use OCP\AppFramework\Services\IAppConfig; +use OCP\IConfig; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class ReRunChangeGroupnamesForPgSql implements IRepairStep { + public function __construct( + private IConfig $config, + private IAppConfig $appConfig, + private UpgradeV300 $upgrade, + ) { + } + + public function getName(): string { + return 'Rerun the change groupnames repair step for a Nextcloud instance using PostgreSQL.'; + } + + public function run(IOutput $output): void { + $sgbdName = $this->config->getSystemValue('dbtype'); + + if ($sgbdName !== 'pgsql') { + return; + } + + $statusMigration = boolval($this->appConfig->getAppValue(Upgrade::CONTROL_MIGRATION_V3, '1')); + + if ($statusMigration === true) { + return; + } -class ReRunChangeGroupnamesForPgSql implements IRepairStep -{ - public function __construct( - private IConfig $config, - private IAppConfig $appConfig, - private UpgradeV300 $upgrade, - ) - { - } - - public function getName(): string - { - return 'Rerun the change groupnames repair step for a Nextcloud instance using PostgreSQL.'; - } - - public function run(IOutput $output): void - { - $sgbdName = $this->config->getSystemValue('dbtype'); - - if ($sgbdName !== 'pgsql') - { - return; - } - - $statusMigration = boolval($this->appConfig->getAppValue(Upgrade::CONTROL_MIGRATION_V3, '1')); - - if ($statusMigration === true) - { - return; - } - - $this->upgrade->upgrade(); - } + $this->upgrade->upgrade(); + } } From 61a9b70f6f93bf68738c3fd3ca2a93f3d4d3fb1c Mon Sep 17 00:00:00 2001 From: zak39 Date: Thu, 22 Aug 2024 15:54:57 +0200 Subject: [PATCH 4/5] fix(mapper): Set parameters in the sql request Instead of to pass the values as string, I defined them as parameter in the where clause. --- lib/Db/GroupFoldersGroupsMapper.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Db/GroupFoldersGroupsMapper.php b/lib/Db/GroupFoldersGroupsMapper.php index 790968f41..45657ec21 100644 --- a/lib/Db/GroupFoldersGroupsMapper.php +++ b/lib/Db/GroupFoldersGroupsMapper.php @@ -60,8 +60,11 @@ public function getSpacenamesGroupIds() { 'gf_groups.folder_id' ) ) - ->where('group_id not like \'SPACE-GE%\'') - ->andWhere('group_id not like \'SPACE-U%\''); + ->where('group_id not like :managerGroup') + ->andWhere('group_id not like :userGroup') + ->setParameter('managerGroup', 'SPACE-GE%') + ->setParameter('userGroup', 'SPACE-U%') + ; return $qb->executeQuery()->fetchAll(); } From fc82b225aa752699befcccea6df32d961e38c434 Mon Sep 17 00:00:00 2001 From: zak39 Date: Thu, 22 Aug 2024 15:57:56 +0200 Subject: [PATCH 5/5] chore(): Run composer cs:fix --- lib/Db/GroupFoldersGroupsMapper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Db/GroupFoldersGroupsMapper.php b/lib/Db/GroupFoldersGroupsMapper.php index 45657ec21..2bd7793ca 100644 --- a/lib/Db/GroupFoldersGroupsMapper.php +++ b/lib/Db/GroupFoldersGroupsMapper.php @@ -62,9 +62,9 @@ public function getSpacenamesGroupIds() { ) ->where('group_id not like :managerGroup') ->andWhere('group_id not like :userGroup') - ->setParameter('managerGroup', 'SPACE-GE%') - ->setParameter('userGroup', 'SPACE-U%') - ; + ->setParameter('managerGroup', 'SPACE-GE%') + ->setParameter('userGroup', 'SPACE-U%') + ; return $qb->executeQuery()->fetchAll(); }