You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepairUserConfig.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /** @var IUserManager */
  34. protected $userManager;
  35. /** @var IConfig */
  36. protected $config;
  37. /**
  38. * MigrateUserConfig constructor.
  39. *
  40. * @param IConfig $config
  41. * @param IUserManager $userManager
  42. */
  43. public function __construct(IConfig $config,
  44. IUserManager $userManager) {
  45. $this->config = $config;
  46. $this->userManager = $userManager;
  47. }
  48. /**
  49. * Returns the step's name
  50. *
  51. * @return string
  52. * @since 9.1.0
  53. */
  54. public function getName() {
  55. return 'Migrate old user config';
  56. }
  57. /**
  58. * Run repair step.
  59. * Must throw exception on error.
  60. *
  61. * @param IOutput $output
  62. * @throws \Exception in case of failure
  63. * @since 9.1.0
  64. */
  65. public function run(IOutput $output) {
  66. $output->startProgress();
  67. $this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
  68. $theme = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'theme', false);
  69. if ($theme === 'themedark') {
  70. $this->config->setUserValue($user->getUID(), Application::APP_ID, 'theme', 'dark');
  71. }
  72. if ($theme === 'themehighcontrast') {
  73. $this->config->setUserValue($user->getUID(), Application::APP_ID, 'highcontrast', 'highcontrast');
  74. $this->config->deleteUserValue($user->getUID(), Application::APP_ID, 'theme');
  75. }
  76. $output->advance();
  77. });
  78. $output->finishProgress();
  79. }
  80. }