Skip to content

Commit

Permalink
fix(migrations): duplicated preference
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <[email protected]>
  • Loading branch information
Altahrim committed Aug 2, 2024
1 parent 8dc9c28 commit 699c2e0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>Photos</name>
<summary>Your memories under your control</summary>
<description>Your memories under your control</description>
<version>3.0.0</version>
<version>3.0.1</version>
<licence>agpl</licence>
<author mail="[email protected]">John Molakvoæ</author>
<namespace>Photos</namespace>
Expand Down
56 changes: 56 additions & 0 deletions lib/Migration/Version30000Date20240417075404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Photos\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Migrate the photosSourceFolder user config to photosSourceFolders
*/
class Version30000Date20240417075404 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $db,
) {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$select = $this->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();
}
}
41 changes: 0 additions & 41 deletions lib/Migration/Version3000Date20240417075404.php

This file was deleted.

0 comments on commit 699c2e0

Please sign in to comment.