|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @copyright Copyright (c) 2019 Janis Köhr <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @author Christoph Wurst <[email protected]> |
|
9
|
|
|
* @author Janis Köhr <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU AGPL version 3 or any later version |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
16
|
|
|
* License, or (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
namespace OCA\Theming\Migration; |
|
28
|
|
|
|
|
29
|
|
|
use OCA\Theming\AppInfo\Application; |
|
30
|
|
|
use OCA\Theming\Service\ThemesService; |
|
31
|
|
|
use OCA\Theming\Themes\DarkHighContrastTheme; |
|
32
|
|
|
use OCA\Theming\Themes\DarkTheme; |
|
33
|
|
|
use OCA\Theming\Themes\DyslexiaFont; |
|
34
|
|
|
use OCA\Theming\Themes\HighContrastTheme; |
|
35
|
|
|
use OCP\IConfig; |
|
36
|
|
|
use OCP\IUser; |
|
37
|
|
|
use OCP\IUserManager; |
|
38
|
|
|
use OCP\Migration\IOutput; |
|
39
|
|
|
use OCP\Migration\IRepairStep; |
|
40
|
|
|
|
|
41
|
|
|
class MigrateUserConfig implements IRepairStep { |
|
42
|
|
|
|
|
43
|
|
|
protected IUserManager $userManager; |
|
44
|
|
|
protected IConfig $config; |
|
45
|
|
|
protected ThemesService $themesService; |
|
46
|
|
|
protected DarkTheme $darkTheme; |
|
47
|
|
|
protected DarkHighContrastTheme $darkHighContrastTheme; |
|
48
|
|
|
protected HighContrastTheme $highContrastTheme; |
|
49
|
|
|
protected DyslexiaFont $dyslexiaFont; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* MigrateUserConfig constructor. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(IConfig $config, |
|
55
|
|
|
IUserManager $userManager, |
|
56
|
|
|
ThemesService $themesService, |
|
57
|
|
|
DarkTheme $darkTheme, |
|
58
|
|
|
DarkHighContrastTheme $darkHighContrastTheme, |
|
59
|
|
|
HighContrastTheme $highContrastTheme, |
|
60
|
|
|
DyslexiaFont $dyslexiaFont) { |
|
61
|
|
|
$this->config = $config; |
|
62
|
|
|
$this->userManager = $userManager; |
|
63
|
|
|
$this->themesService = $themesService; |
|
64
|
|
|
|
|
65
|
|
|
$this->darkTheme = $darkTheme; |
|
66
|
|
|
$this->darkHighContrastTheme = $darkHighContrastTheme; |
|
67
|
|
|
$this->highContrastTheme = $highContrastTheme; |
|
68
|
|
|
$this->dyslexiaFont = $dyslexiaFont; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns the step's name |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
* @since 25.0.0 |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getName() { |
|
78
|
|
|
return 'Migrate old user accessibility config'; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Run repair step. |
|
83
|
|
|
* Must throw exception on error. |
|
84
|
|
|
* |
|
85
|
|
|
* @param IOutput $output |
|
86
|
|
|
* @throws \Exception in case of failure |
|
87
|
|
|
* @since 25.0.0 |
|
88
|
|
|
*/ |
|
89
|
|
|
public function run(IOutput $output) { |
|
90
|
|
|
$output->startProgress(); |
|
91
|
|
|
$this->userManager->callForSeenUsers(function (IUser $user) use ($output) { |
|
92
|
|
|
$config = []; |
|
93
|
|
|
|
|
94
|
|
|
$font = $this->config->getUserValue($user->getUID(), 'accessibility', 'font', false); |
|
95
|
|
|
$highcontrast = $this->config->getUserValue($user->getUID(), 'accessibility', 'highcontrast', false); |
|
96
|
|
|
$theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', false); |
|
97
|
|
|
|
|
98
|
|
|
if ($highcontrast || $theme) { |
|
99
|
|
|
if ($theme === 'dark' && $highcontrast === 'highcontrast') { |
|
100
|
|
|
$config[] = $this->darkHighContrastTheme->getId(); |
|
101
|
|
|
} else if ($theme === 'dark') { |
|
102
|
|
|
$config[] = $this->darkTheme->getId(); |
|
103
|
|
|
} else if ($highcontrast === 'highcontrast') { |
|
104
|
|
|
$config[] = $this->highContrastTheme->getId(); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if ($font === 'fontdyslexic') { |
|
109
|
|
|
$config[] = $this->dyslexiaFont->getId(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if (!empty($config)) { |
|
113
|
|
|
$this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', json_encode(array_unique($config))); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$output->advance(); |
|
117
|
|
|
}); |
|
118
|
|
|
|
|
119
|
|
|
$this->config->deleteAppFromAllUsers('accessibility'); |
|
120
|
|
|
|
|
121
|
|
|
$output->finishProgress(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|