From f98229d2b6e4600fd76b1a037054d50107cc1c23 Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Fri, 2 Aug 2024 14:41:12 +0200 Subject: [PATCH] fix(migrations): duplicated preference Signed-off-by: Benjamin Gaussorgues --- .../Version30000Date20240417075404.php | 56 +++++++++++++++++++ .../Version3000Date20240417075404.php | 41 -------------- 2 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 lib/Migration/Version30000Date20240417075404.php delete mode 100644 lib/Migration/Version3000Date20240417075404.php diff --git a/lib/Migration/Version30000Date20240417075404.php b/lib/Migration/Version30000Date20240417075404.php new file mode 100644 index 000000000..891841835 --- /dev/null +++ b/lib/Migration/Version30000Date20240417075404.php @@ -0,0 +1,56 @@ +db->getQueryBuilder(); + $select->select('userid') + ->from('preferences') + ->where($select->expr()->eq('appid', $select->expr()->literal('photos'))) + ->andWhere($select->expr()->eq('configkey', $select->expr()->literal('photosSourceFolders'))); + + // Remove old entries for users who already have the new one + $delete = $this->db->getQueryBuilder(); + $delete->delete('preferences') + ->where($delete->expr()->eq('appid', $delete->expr()->literal('photos'))) + ->andWhere($delete->expr()->eq('configkey', $delete->expr()->literal('photosSourceFolder'))) + ->andWhere($delete->expr()->in('userid', $delete->createFunction($select->getSQL()))) + ->executeStatement(); + + // Update remaining old entries to new ones + $update = $this->db->getQueryBuilder(); + $update->update('preferences') + ->set('configvalue', $update->func()->concat($update->expr()->literal('["'), 'configvalue', $update->expr()->literal('"]'))) + ->set('configkey', $update->expr()->literal('photosSourceFolders')) + ->where($update->expr()->eq('appid', $update->expr()->literal('photos'))) + ->andWhere($update->expr()->eq('configkey', $update->expr()->literal('photosSourceFolder'))) + ->executeStatement(); + } +} diff --git a/lib/Migration/Version3000Date20240417075404.php b/lib/Migration/Version3000Date20240417075404.php deleted file mode 100644 index cb9abe508..000000000 --- a/lib/Migration/Version3000Date20240417075404.php +++ /dev/null @@ -1,41 +0,0 @@ -db->getQueryBuilder(); - $query->update('preferences') - ->set('configvalue', $query->func()->concat($query->expr()->literal('["'), 'configvalue', $query->expr()->literal('"]'))) - ->set('configkey', $query->expr()->literal('photosSourceFolders')) - ->where($query->expr()->eq('appid', $query->expr()->literal('photos'))) - ->andWhere($query->expr()->eq('configkey', $query->expr()->literal('photosSourceFolder'))) - ->executeStatement(); - } -}