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.4KB

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