RepairUserConfig.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Janis Köhr <janiskoehr@icloud.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Janis Köhr <janis.koehr@novatec-gmbh.de>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Accessibility\Migration;
  26. use OCA\Accessibility\AppInfo\Application;
  27. use OCP\IConfig;
  28. use OCP\IUser;
  29. use OCP\IUserManager;
  30. use OCP\Migration\IOutput;
  31. use OCP\Migration\IRepairStep;
  32. class RepairUserConfig implements IRepairStep {
  33. protected IUserManager $userManager;
  34. protected IConfig $config;
  35. /**
  36. * MigrateUserConfig constructor.
  37. */
  38. public function __construct(IConfig $config,
  39. IUserManager $userManager) {
  40. $this->config = $config;
  41. $this->userManager = $userManager;
  42. }
  43. /**
  44. * Returns the step's name
  45. *
  46. * @return string
  47. * @since 9.1.0
  48. */
  49. public function getName() {
  50. return 'Migrate old user config';
  51. }
  52. /**
  53. * Run repair step.
  54. * Must throw exception on error.
  55. *
  56. * @param IOutput $output
  57. * @throws \Exception in case of failure
  58. * @since 9.1.0
  59. */
  60. public function run(IOutput $output) {
  61. $output->startProgress();
  62. $this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
  63. $theme = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'theme', false);
  64. if ($theme === 'themedark') {
  65. $this->config->setUserValue($user->getUID(), Application::APP_ID, 'theme', 'dark');
  66. }
  67. if ($theme === 'themehighcontrast') {
  68. $this->config->setUserValue($user->getUID(), Application::APP_ID, 'highcontrast', 'highcontrast');
  69. $this->config->deleteUserValue($user->getUID(), Application::APP_ID, 'theme');
  70. }
  71. $output->advance();
  72. });
  73. $output->finishProgress();
  74. }
  75. }