-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix missing background on upgrade #34461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
107a974
Fix missing background on upgrade
Pytal 6e4a90b
Fix SQL errors
nickvergessen 7599cbb
New code being new
nickvergessen 7f5ef4d
Delete theming background preferences
Pytal b4f6329
fix querybuilder instance recuse
blizzz 4d98128
Fix migration parameter handling
nickvergessen 59e0710
graceful background image handling
blizzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2022 Arthur Schiwon <[email protected]> | ||
| * | ||
| * @author Arthur Schiwon <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Theming\Jobs; | ||
|
|
||
| use OCA\Theming\AppInfo\Application; | ||
| use OCP\App\IAppManager; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\BackgroundJob\IJobList; | ||
| use OCP\BackgroundJob\QueuedJob; | ||
| use OCP\Files\AppData\IAppDataFactory; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\Files\NotPermittedException; | ||
| use OCP\IConfig; | ||
|
|
||
| class MigrateBackgroundImages extends QueuedJob { | ||
| public const TIME_SENSITIVE = 0; | ||
|
|
||
| private IConfig $config; | ||
| private IAppManager $appManager; | ||
| private IAppDataFactory $appDataFactory; | ||
| private IJobList $jobList; | ||
|
|
||
| public function __construct(ITimeFactory $time, IAppDataFactory $appDataFactory, IConfig $config, IAppManager $appManager, IJobList $jobList) { | ||
| parent::__construct($time); | ||
| $this->config = $config; | ||
| $this->appManager = $appManager; | ||
| $this->appDataFactory = $appDataFactory; | ||
| $this->jobList = $jobList; | ||
| } | ||
|
|
||
| protected function run($argument): void { | ||
| if (!$this->appManager->isEnabledForUser('dashboard')) { | ||
| return; | ||
| } | ||
|
|
||
| $themingData = $this->appDataFactory->get(Application::APP_ID); | ||
| $dashboardData = $this->appDataFactory->get('dashboard'); | ||
|
|
||
| $userIds = $this->config->getUsersForUserValue('theming', 'background', 'custom'); | ||
|
|
||
| $notSoFastMode = \count($userIds) > 5000; | ||
| $reTrigger = false; | ||
| $processed = 0; | ||
|
|
||
| foreach ($userIds as $userId) { | ||
| try { | ||
| // precondition | ||
| if ($notSoFastMode) { | ||
| if ($this->config->getUserValue($userId, 'theming', 'background-migrated', '0') === '1') { | ||
| // already migrated | ||
| continue; | ||
| } | ||
| $reTrigger = true; | ||
| } | ||
|
|
||
| // migration | ||
| $file = $dashboardData->getFolder($userId)->getFile('background.jpg'); | ||
| try { | ||
| $targetDir = $themingData->getFolder($userId); | ||
| } catch (NotFoundException $e) { | ||
| $targetDir = $themingData->newFolder($userId); | ||
| } | ||
| if (!$targetDir->fileExists('background.jpg')) { | ||
| $targetDir->newFile('background.jpg', $file->getContent()); | ||
| } | ||
| $file->delete(); | ||
| } catch (NotFoundException|NotPermittedException $e) { | ||
| } | ||
| // capture state | ||
| if ($notSoFastMode) { | ||
| $this->config->setUserValue($userId, 'theming', 'background-migrated', '1'); | ||
| $processed++; | ||
| } | ||
| if ($processed > 4999) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if ($reTrigger) { | ||
| $this->jobList->add(self::class); | ||
| } | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
apps/theming/lib/Migration/InitBackgroundImagesMigration.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2022 Arthur Schiwon <[email protected]> | ||
| * | ||
| * @author Arthur Schiwon <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Theming\Migration; | ||
|
|
||
| use OCA\Theming\Jobs\MigrateBackgroundImages; | ||
| use OCP\BackgroundJob\IJobList; | ||
| use OCP\Migration\IOutput; | ||
|
|
||
| class InitBackgroundImagesMigration implements \OCP\Migration\IRepairStep { | ||
|
|
||
| private IJobList $jobList; | ||
|
|
||
| public function __construct(IJobList $jobList) { | ||
| $this->jobList = $jobList; | ||
| } | ||
|
|
||
| public function getName() { | ||
| return 'Initialize migration of background images from dashboard to theming app'; | ||
| } | ||
|
|
||
| public function run(IOutput $output) { | ||
Check noticeCode scanning / Psalm MissingReturnType
Method OCA\Theming\Migration\InitBackgroundImagesMigration::run does not have a return type, expecting void
|
||
| $this->jobList->add(MigrateBackgroundImages::class); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright 2022 Christopher Ng <[email protected]> | ||
| * | ||
| * @author Christopher Ng <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OC\Core\Migrations; | ||
|
|
||
| use Closure; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
|
|
||
| /** | ||
| * User background settings handling was moved from the | ||
| * dashboard app to the theming app so we migrate the | ||
| * respective preference values here | ||
| * | ||
| */ | ||
| class Version25000Date20221007010957 extends SimpleMigrationStep { | ||
| protected IDBConnection $connection; | ||
|
|
||
| public function __construct(IDBConnection $connection) { | ||
| $this->connection = $connection; | ||
| } | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
| * @param array $options | ||
| */ | ||
| public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
| $cleanUpQuery = $this->connection->getQueryBuilder(); | ||
| $cleanUpQuery->delete('preferences') | ||
| ->where($cleanUpQuery->expr()->eq('appid', $cleanUpQuery->createNamedParameter('theming'))) | ||
| ->andWhere($cleanUpQuery->expr()->orX( | ||
| $cleanUpQuery->expr()->eq('configkey', $cleanUpQuery->createNamedParameter('background')), | ||
| $cleanUpQuery->expr()->eq('configkey', $cleanUpQuery->createNamedParameter('backgroundVersion')), | ||
| )); | ||
| $cleanUpQuery->executeStatement(); | ||
|
|
||
| $updateQuery = $this->connection->getQueryBuilder(); | ||
| $updateQuery->update('preferences') | ||
| ->set('appid', $updateQuery->createNamedParameter('theming')) | ||
| ->where($updateQuery->expr()->eq('appid', $updateQuery->createNamedParameter('dashboard'))) | ||
| ->andWhere($updateQuery->expr()->orX( | ||
| $updateQuery->expr()->eq('configkey', $updateQuery->createNamedParameter('background')), | ||
| $updateQuery->expr()->eq('configkey', $updateQuery->createNamedParameter('backgroundVersion')), | ||
| )); | ||
| $updateQuery->executeStatement(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Psalm
MissingParamType