Version25000Date20221007010957.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use Closure;
  9. use OCP\IDBConnection;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. /**
  13. * User background settings handling was moved from the
  14. * dashboard app to the theming app so we migrate the
  15. * respective preference values here
  16. *
  17. */
  18. class Version25000Date20221007010957 extends SimpleMigrationStep {
  19. public function __construct(
  20. protected IDBConnection $connection,
  21. ) {
  22. }
  23. /**
  24. * @param IOutput $output
  25. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  26. * @param array $options
  27. */
  28. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  29. $cleanUpQuery = $this->connection->getQueryBuilder();
  30. $cleanUpQuery->delete('preferences')
  31. ->where($cleanUpQuery->expr()->eq('appid', $cleanUpQuery->createNamedParameter('theming')))
  32. ->andWhere($cleanUpQuery->expr()->orX(
  33. $cleanUpQuery->expr()->eq('configkey', $cleanUpQuery->createNamedParameter('background')),
  34. $cleanUpQuery->expr()->eq('configkey', $cleanUpQuery->createNamedParameter('backgroundVersion')),
  35. ));
  36. $cleanUpQuery->executeStatement();
  37. $updateQuery = $this->connection->getQueryBuilder();
  38. $updateQuery->update('preferences')
  39. ->set('appid', $updateQuery->createNamedParameter('theming'))
  40. ->where($updateQuery->expr()->eq('appid', $updateQuery->createNamedParameter('dashboard')))
  41. ->andWhere($updateQuery->expr()->orX(
  42. $updateQuery->expr()->eq('configkey', $updateQuery->createNamedParameter('background')),
  43. $updateQuery->expr()->eq('configkey', $updateQuery->createNamedParameter('backgroundVersion')),
  44. ));
  45. $updateQuery->executeStatement();
  46. }
  47. }