@@ -31,40 +31,40 @@ |
||
31 | 31 | |
32 | 32 | class ClearFrontendCaches implements IRepairStep { |
33 | 33 | |
34 | - /** @var ICacheFactory */ |
|
35 | - protected $cacheFactory; |
|
34 | + /** @var ICacheFactory */ |
|
35 | + protected $cacheFactory; |
|
36 | 36 | |
37 | - /** @var SCSSCacher */ |
|
38 | - protected $scssCacher; |
|
37 | + /** @var SCSSCacher */ |
|
38 | + protected $scssCacher; |
|
39 | 39 | |
40 | - /** @var JSCombiner */ |
|
41 | - protected $jsCombiner; |
|
40 | + /** @var JSCombiner */ |
|
41 | + protected $jsCombiner; |
|
42 | 42 | |
43 | - public function __construct(ICacheFactory $cacheFactory, |
|
44 | - SCSSCacher $SCSSCacher, |
|
45 | - JSCombiner $JSCombiner) { |
|
46 | - $this->cacheFactory = $cacheFactory; |
|
47 | - $this->scssCacher = $SCSSCacher; |
|
48 | - $this->jsCombiner = $JSCombiner; |
|
49 | - } |
|
43 | + public function __construct(ICacheFactory $cacheFactory, |
|
44 | + SCSSCacher $SCSSCacher, |
|
45 | + JSCombiner $JSCombiner) { |
|
46 | + $this->cacheFactory = $cacheFactory; |
|
47 | + $this->scssCacher = $SCSSCacher; |
|
48 | + $this->jsCombiner = $JSCombiner; |
|
49 | + } |
|
50 | 50 | |
51 | - public function getName() { |
|
52 | - return 'Clear frontend caches'; |
|
53 | - } |
|
51 | + public function getName() { |
|
52 | + return 'Clear frontend caches'; |
|
53 | + } |
|
54 | 54 | |
55 | - public function run(IOutput $output) { |
|
56 | - try { |
|
57 | - $c = $this->cacheFactory->createDistributed('imagePath'); |
|
58 | - $c->clear(); |
|
59 | - $output->info('Image cache cleared'); |
|
55 | + public function run(IOutput $output) { |
|
56 | + try { |
|
57 | + $c = $this->cacheFactory->createDistributed('imagePath'); |
|
58 | + $c->clear(); |
|
59 | + $output->info('Image cache cleared'); |
|
60 | 60 | |
61 | - $this->scssCacher->resetCache(); |
|
62 | - $output->info('SCSS cache cleared'); |
|
61 | + $this->scssCacher->resetCache(); |
|
62 | + $output->info('SCSS cache cleared'); |
|
63 | 63 | |
64 | - $this->jsCombiner->resetCache(); |
|
65 | - $output->info('JS cache cleared'); |
|
66 | - } catch (\Exception $e) { |
|
67 | - $output->warning('Unable to clear the frontend cache'); |
|
68 | - } |
|
69 | - } |
|
64 | + $this->jsCombiner->resetCache(); |
|
65 | + $output->info('JS cache cleared'); |
|
66 | + } catch (\Exception $e) { |
|
67 | + $output->warning('Unable to clear the frontend cache'); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | use Symfony\Component\EventDispatcher\GenericEvent; |
37 | 37 | |
38 | 38 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
39 | - @set_time_limit(0); |
|
39 | + @set_time_limit(0); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | require_once '../../lib/base.php'; |
@@ -50,189 +50,189 @@ discard block |
||
50 | 50 | $eventSource->send('success', (string)$l->t('Preparing update')); |
51 | 51 | |
52 | 52 | class FeedBackHandler { |
53 | - /** @var integer */ |
|
54 | - private $progressStateMax = 100; |
|
55 | - /** @var integer */ |
|
56 | - private $progressStateStep = 0; |
|
57 | - /** @var string */ |
|
58 | - private $currentStep; |
|
59 | - /** @var \OCP\IEventSource */ |
|
60 | - private $eventSource; |
|
61 | - /** @var \OCP\IL10N */ |
|
62 | - private $l10n; |
|
63 | - |
|
64 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
65 | - $this->eventSource = $eventSource; |
|
66 | - $this->l10n = $l10n; |
|
67 | - } |
|
68 | - |
|
69 | - public function handleRepairFeedback($event) { |
|
70 | - if (!$event instanceof GenericEvent) { |
|
71 | - return; |
|
72 | - } |
|
73 | - |
|
74 | - switch ($event->getSubject()) { |
|
75 | - case '\OC\Repair::startProgress': |
|
76 | - $this->progressStateMax = $event->getArgument(0); |
|
77 | - $this->progressStateStep = 0; |
|
78 | - $this->currentStep = $event->getArgument(1); |
|
79 | - break; |
|
80 | - case '\OC\Repair::advance': |
|
81 | - $this->progressStateStep += $event->getArgument(0); |
|
82 | - $desc = $event->getArgument(1); |
|
83 | - if (empty($desc)) { |
|
84 | - $desc = $this->currentStep; |
|
85 | - } |
|
86 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
87 | - break; |
|
88 | - case '\OC\Repair::finishProgress': |
|
89 | - $this->progressStateMax = $this->progressStateStep; |
|
90 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
91 | - break; |
|
92 | - case '\OC\Repair::step': |
|
93 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
94 | - break; |
|
95 | - case '\OC\Repair::info': |
|
96 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
97 | - break; |
|
98 | - case '\OC\Repair::warning': |
|
99 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
100 | - break; |
|
101 | - case '\OC\Repair::error': |
|
102 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
103 | - break; |
|
104 | - } |
|
105 | - } |
|
53 | + /** @var integer */ |
|
54 | + private $progressStateMax = 100; |
|
55 | + /** @var integer */ |
|
56 | + private $progressStateStep = 0; |
|
57 | + /** @var string */ |
|
58 | + private $currentStep; |
|
59 | + /** @var \OCP\IEventSource */ |
|
60 | + private $eventSource; |
|
61 | + /** @var \OCP\IL10N */ |
|
62 | + private $l10n; |
|
63 | + |
|
64 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
65 | + $this->eventSource = $eventSource; |
|
66 | + $this->l10n = $l10n; |
|
67 | + } |
|
68 | + |
|
69 | + public function handleRepairFeedback($event) { |
|
70 | + if (!$event instanceof GenericEvent) { |
|
71 | + return; |
|
72 | + } |
|
73 | + |
|
74 | + switch ($event->getSubject()) { |
|
75 | + case '\OC\Repair::startProgress': |
|
76 | + $this->progressStateMax = $event->getArgument(0); |
|
77 | + $this->progressStateStep = 0; |
|
78 | + $this->currentStep = $event->getArgument(1); |
|
79 | + break; |
|
80 | + case '\OC\Repair::advance': |
|
81 | + $this->progressStateStep += $event->getArgument(0); |
|
82 | + $desc = $event->getArgument(1); |
|
83 | + if (empty($desc)) { |
|
84 | + $desc = $this->currentStep; |
|
85 | + } |
|
86 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
87 | + break; |
|
88 | + case '\OC\Repair::finishProgress': |
|
89 | + $this->progressStateMax = $this->progressStateStep; |
|
90 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
91 | + break; |
|
92 | + case '\OC\Repair::step': |
|
93 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
94 | + break; |
|
95 | + case '\OC\Repair::info': |
|
96 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
97 | + break; |
|
98 | + case '\OC\Repair::warning': |
|
99 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
100 | + break; |
|
101 | + case '\OC\Repair::error': |
|
102 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
103 | + break; |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | if (\OCP\Util::needUpgrade()) { |
109 | - $config = \OC::$server->getSystemConfig(); |
|
110 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | - $eventSource->close(); |
|
113 | - exit(); |
|
114 | - } |
|
115 | - |
|
116 | - // if a user is currently logged in, their session must be ignored to |
|
117 | - // avoid side effects |
|
118 | - \OC_User::setIncognitoMode(true); |
|
119 | - |
|
120 | - $logger = \OC::$server->getLogger(); |
|
121 | - $config = \OC::$server->getConfig(); |
|
122 | - $updater = new \OC\Updater( |
|
123 | - $config, |
|
124 | - \OC::$server->getIntegrityCodeChecker(), |
|
125 | - $logger, |
|
126 | - \OC::$server->query(\OC\Installer::class) |
|
127 | - ); |
|
128 | - $incompatibleApps = []; |
|
129 | - |
|
130 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | - if ($event instanceof GenericEvent) { |
|
133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | - } |
|
135 | - }); |
|
136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | - if ($event instanceof GenericEvent) { |
|
138 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | - } |
|
140 | - }); |
|
141 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | - |
|
150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | - }); |
|
153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | - }); |
|
156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | - }); |
|
159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | - }); |
|
162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | - }); |
|
165 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | - }); |
|
168 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | - }); |
|
171 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | - }); |
|
174 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | - }); |
|
177 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | - }); |
|
180 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | - }); |
|
183 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | - }); |
|
186 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | - }); |
|
189 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | - $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | - }); |
|
192 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | - $incompatibleApps[] = $app; |
|
194 | - }); |
|
195 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | - $eventSource->send('failure', $message); |
|
197 | - $eventSource->close(); |
|
198 | - $config->setSystemValue('maintenance', false); |
|
199 | - }); |
|
200 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | - }); |
|
203 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | - }); |
|
206 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | - }); |
|
209 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | - }); |
|
212 | - |
|
213 | - try { |
|
214 | - $updater->upgrade(); |
|
215 | - } catch (\Exception $e) { |
|
216 | - \OC::$server->getLogger()->logException($e, [ |
|
217 | - 'level' => ILogger::ERROR, |
|
218 | - 'app' => 'update', |
|
219 | - ]); |
|
220 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | - $eventSource->close(); |
|
222 | - exit(); |
|
223 | - } |
|
224 | - |
|
225 | - $disabledApps = []; |
|
226 | - foreach ($incompatibleApps as $app) { |
|
227 | - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | - } |
|
229 | - |
|
230 | - if (!empty($disabledApps)) { |
|
231 | - $eventSource->send('notice', |
|
232 | - (string)$l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | - } |
|
109 | + $config = \OC::$server->getSystemConfig(); |
|
110 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | + $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | + $eventSource->close(); |
|
113 | + exit(); |
|
114 | + } |
|
115 | + |
|
116 | + // if a user is currently logged in, their session must be ignored to |
|
117 | + // avoid side effects |
|
118 | + \OC_User::setIncognitoMode(true); |
|
119 | + |
|
120 | + $logger = \OC::$server->getLogger(); |
|
121 | + $config = \OC::$server->getConfig(); |
|
122 | + $updater = new \OC\Updater( |
|
123 | + $config, |
|
124 | + \OC::$server->getIntegrityCodeChecker(), |
|
125 | + $logger, |
|
126 | + \OC::$server->query(\OC\Installer::class) |
|
127 | + ); |
|
128 | + $incompatibleApps = []; |
|
129 | + |
|
130 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | + if ($event instanceof GenericEvent) { |
|
133 | + $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | + } |
|
135 | + }); |
|
136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | + if ($event instanceof GenericEvent) { |
|
138 | + $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | + } |
|
140 | + }); |
|
141 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | + |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | + }); |
|
153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | + }); |
|
156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | + }); |
|
159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | + }); |
|
162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | + }); |
|
165 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | + }); |
|
168 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | + }); |
|
171 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | + }); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | + }); |
|
177 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | + }); |
|
180 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | + }); |
|
183 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | + }); |
|
186 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | + $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | + }); |
|
189 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | + $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | + }); |
|
192 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | + $incompatibleApps[] = $app; |
|
194 | + }); |
|
195 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | + $eventSource->send('failure', $message); |
|
197 | + $eventSource->close(); |
|
198 | + $config->setSystemValue('maintenance', false); |
|
199 | + }); |
|
200 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | + }); |
|
203 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | + }); |
|
206 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | + $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | + }); |
|
209 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | + $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | + }); |
|
212 | + |
|
213 | + try { |
|
214 | + $updater->upgrade(); |
|
215 | + } catch (\Exception $e) { |
|
216 | + \OC::$server->getLogger()->logException($e, [ |
|
217 | + 'level' => ILogger::ERROR, |
|
218 | + 'app' => 'update', |
|
219 | + ]); |
|
220 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | + $eventSource->close(); |
|
222 | + exit(); |
|
223 | + } |
|
224 | + |
|
225 | + $disabledApps = []; |
|
226 | + foreach ($incompatibleApps as $app) { |
|
227 | + $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | + } |
|
229 | + |
|
230 | + if (!empty($disabledApps)) { |
|
231 | + $eventSource->send('notice', |
|
232 | + (string)$l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | + } |
|
234 | 234 | } else { |
235 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
235 | + $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $eventSource->send('done', ''); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | // need to send an initial message to force-init the event source, |
48 | 48 | // which will then trigger its own CSRF check and produces its own CSRF error |
49 | 49 | // message |
50 | -$eventSource->send('success', (string)$l->t('Preparing update')); |
|
50 | +$eventSource->send('success', (string) $l->t('Preparing update')); |
|
51 | 51 | |
52 | 52 | class FeedBackHandler { |
53 | 53 | /** @var integer */ |
@@ -83,23 +83,23 @@ discard block |
||
83 | 83 | if (empty($desc)) { |
84 | 84 | $desc = $this->currentStep; |
85 | 85 | } |
86 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | + $this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
87 | 87 | break; |
88 | 88 | case '\OC\Repair::finishProgress': |
89 | 89 | $this->progressStateMax = $this->progressStateStep; |
90 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | + $this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
91 | 91 | break; |
92 | 92 | case '\OC\Repair::step': |
93 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
93 | + $this->eventSource->send('success', (string) $this->l10n->t('Repair step:').' '.$event->getArgument(0)); |
|
94 | 94 | break; |
95 | 95 | case '\OC\Repair::info': |
96 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
96 | + $this->eventSource->send('success', (string) $this->l10n->t('Repair info:').' '.$event->getArgument(0)); |
|
97 | 97 | break; |
98 | 98 | case '\OC\Repair::warning': |
99 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
99 | + $this->eventSource->send('notice', (string) $this->l10n->t('Repair warning:').' '.$event->getArgument(0)); |
|
100 | 100 | break; |
101 | 101 | case '\OC\Repair::error': |
102 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
102 | + $this->eventSource->send('notice', (string) $this->l10n->t('Repair error:').' '.$event->getArgument(0)); |
|
103 | 103 | break; |
104 | 104 | } |
105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | if (\OCP\Util::needUpgrade()) { |
109 | 109 | $config = \OC::$server->getSystemConfig(); |
110 | 110 | if ($config->getValue('upgrade.disable-web', false)) { |
111 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
111 | + $eventSource->send('failure', (string) $l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | 112 | $eventSource->close(); |
113 | 113 | exit(); |
114 | 114 | } |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | $incompatibleApps = []; |
129 | 129 | |
130 | 130 | $dispatcher = \OC::$server->getEventDispatcher(); |
131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
132 | 132 | if ($event instanceof GenericEvent) { |
133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
133 | + $eventSource->send('success', (string) $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | 134 | } |
135 | 135 | }); |
136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
137 | 137 | if ($event instanceof GenericEvent) { |
138 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
138 | + $eventSource->send('success', (string) $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | 139 | } |
140 | 140 | }); |
141 | 141 | $feedBack = new FeedBackHandler($eventSource, $l); |
@@ -147,67 +147,67 @@ discard block |
||
147 | 147 | $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
148 | 148 | $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
149 | 149 | |
150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string) $l->t('Turned on maintenance mode')); |
|
152 | 152 | }); |
153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string) $l->t('Turned off maintenance mode')); |
|
155 | 155 | }); |
156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string) $l->t('Maintenance mode is kept active')); |
|
158 | 158 | }); |
159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string) $l->t('Updating database schema')); |
|
161 | 161 | }); |
162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string) $l->t('Updated database')); |
|
164 | 164 | }); |
165 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
165 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string) $l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | 167 | }); |
168 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
168 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string) $l->t('Checked database schema update')); |
|
170 | 170 | }); |
171 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
171 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string) $l->t('Checking updates of apps')); |
|
173 | 173 | }); |
174 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string) $l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | 176 | }); |
177 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
177 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string) $l->t('Update app "%s" from appstore', [$app])); |
|
179 | 179 | }); |
180 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
180 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string) $l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | 182 | }); |
183 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
183 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string) $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | 185 | }); |
186 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
186 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($eventSource, $l) { |
|
187 | + $eventSource->send('success', (string) $l->t('Checked database schema update for apps')); |
|
188 | 188 | }); |
189 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | - $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
189 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($eventSource, $l) { |
|
190 | + $eventSource->send('success', (string) $l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | 191 | }); |
192 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
192 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use (&$incompatibleApps) { |
|
193 | 193 | $incompatibleApps[] = $app; |
194 | 194 | }); |
195 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
195 | + $updater->listen('\OC\Updater', 'failure', function($message) use ($eventSource, $config) { |
|
196 | 196 | $eventSource->send('failure', $message); |
197 | 197 | $eventSource->close(); |
198 | 198 | $config->setSystemValue('maintenance', false); |
199 | 199 | }); |
200 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
200 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string) $l->t('Set log level to debug')); |
|
202 | 202 | }); |
203 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
203 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string) $l->t('Reset log level')); |
|
205 | 205 | }); |
206 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
206 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
207 | + $eventSource->send('success', (string) $l->t('Starting code integrity check')); |
|
208 | 208 | }); |
209 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
209 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
210 | + $eventSource->send('success', (string) $l->t('Finished code integrity check')); |
|
211 | 211 | }); |
212 | 212 | |
213 | 213 | try { |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | 'level' => ILogger::ERROR, |
218 | 218 | 'app' => 'update', |
219 | 219 | ]); |
220 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
220 | + $eventSource->send('failure', get_class($e).': '.$e->getMessage()); |
|
221 | 221 | $eventSource->close(); |
222 | 222 | exit(); |
223 | 223 | } |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | |
230 | 230 | if (!empty($disabledApps)) { |
231 | 231 | $eventSource->send('notice', |
232 | - (string)$l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
232 | + (string) $l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | 233 | } |
234 | 234 | } else { |
235 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
235 | + $eventSource->send('notice', (string) $l->t('Already up to date')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $eventSource->send('done', ''); |
@@ -69,348 +69,348 @@ |
||
69 | 69 | * @package OC\Core\Controller |
70 | 70 | */ |
71 | 71 | class LostController extends Controller { |
72 | - /** @var IURLGenerator */ |
|
73 | - protected $urlGenerator; |
|
74 | - /** @var IUserManager */ |
|
75 | - protected $userManager; |
|
76 | - /** @var Defaults */ |
|
77 | - protected $defaults; |
|
78 | - /** @var IL10N */ |
|
79 | - protected $l10n; |
|
80 | - /** @var string */ |
|
81 | - protected $from; |
|
82 | - /** @var IManager */ |
|
83 | - protected $encryptionManager; |
|
84 | - /** @var IConfig */ |
|
85 | - protected $config; |
|
86 | - /** @var ISecureRandom */ |
|
87 | - protected $secureRandom; |
|
88 | - /** @var IMailer */ |
|
89 | - protected $mailer; |
|
90 | - /** @var ITimeFactory */ |
|
91 | - protected $timeFactory; |
|
92 | - /** @var ICrypto */ |
|
93 | - protected $crypto; |
|
94 | - /** @var ILogger */ |
|
95 | - private $logger; |
|
96 | - /** @var Manager */ |
|
97 | - private $twoFactorManager; |
|
98 | - /** @var IInitialStateService */ |
|
99 | - private $initialStateService; |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $appName |
|
103 | - * @param IRequest $request |
|
104 | - * @param IURLGenerator $urlGenerator |
|
105 | - * @param IUserManager $userManager |
|
106 | - * @param Defaults $defaults |
|
107 | - * @param IL10N $l10n |
|
108 | - * @param IConfig $config |
|
109 | - * @param ISecureRandom $secureRandom |
|
110 | - * @param string $defaultMailAddress |
|
111 | - * @param IManager $encryptionManager |
|
112 | - * @param IMailer $mailer |
|
113 | - * @param ITimeFactory $timeFactory |
|
114 | - * @param ICrypto $crypto |
|
115 | - */ |
|
116 | - public function __construct($appName, |
|
117 | - IRequest $request, |
|
118 | - IURLGenerator $urlGenerator, |
|
119 | - IUserManager $userManager, |
|
120 | - Defaults $defaults, |
|
121 | - IL10N $l10n, |
|
122 | - IConfig $config, |
|
123 | - ISecureRandom $secureRandom, |
|
124 | - $defaultMailAddress, |
|
125 | - IManager $encryptionManager, |
|
126 | - IMailer $mailer, |
|
127 | - ITimeFactory $timeFactory, |
|
128 | - ICrypto $crypto, |
|
129 | - ILogger $logger, |
|
130 | - Manager $twoFactorManager, |
|
131 | - IInitialStateService $initialStateService) { |
|
132 | - parent::__construct($appName, $request); |
|
133 | - $this->urlGenerator = $urlGenerator; |
|
134 | - $this->userManager = $userManager; |
|
135 | - $this->defaults = $defaults; |
|
136 | - $this->l10n = $l10n; |
|
137 | - $this->secureRandom = $secureRandom; |
|
138 | - $this->from = $defaultMailAddress; |
|
139 | - $this->encryptionManager = $encryptionManager; |
|
140 | - $this->config = $config; |
|
141 | - $this->mailer = $mailer; |
|
142 | - $this->timeFactory = $timeFactory; |
|
143 | - $this->crypto = $crypto; |
|
144 | - $this->logger = $logger; |
|
145 | - $this->twoFactorManager = $twoFactorManager; |
|
146 | - $this->initialStateService = $initialStateService; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Someone wants to reset their password: |
|
151 | - * |
|
152 | - * @PublicPage |
|
153 | - * @NoCSRFRequired |
|
154 | - * |
|
155 | - * @param string $token |
|
156 | - * @param string $userId |
|
157 | - * @return TemplateResponse |
|
158 | - */ |
|
159 | - public function resetform($token, $userId) { |
|
160 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | - return new TemplateResponse('core', 'error', [ |
|
162 | - 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | - ], |
|
164 | - 'guest' |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - try { |
|
169 | - $this->checkPasswordResetToken($token, $userId); |
|
170 | - } catch (\Exception $e) { |
|
171 | - return new TemplateResponse( |
|
172 | - 'core', 'error', [ |
|
173 | - "errors" => [["error" => $e->getMessage()]] |
|
174 | - ], |
|
175 | - 'guest' |
|
176 | - ); |
|
177 | - } |
|
178 | - $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | - $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | - $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | - ); |
|
182 | - |
|
183 | - return new TemplateResponse( |
|
184 | - 'core', |
|
185 | - 'login', |
|
186 | - [], |
|
187 | - 'guest' |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $token |
|
193 | - * @param string $userId |
|
194 | - * @throws \Exception |
|
195 | - */ |
|
196 | - protected function checkPasswordResetToken($token, $userId) { |
|
197 | - $user = $this->userManager->get($userId); |
|
198 | - if ($user === null || !$user->isEnabled()) { |
|
199 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | - } |
|
201 | - |
|
202 | - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | - if ($encryptedToken === null) { |
|
204 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | - } |
|
206 | - |
|
207 | - try { |
|
208 | - $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | - $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | - } catch (\Exception $e) { |
|
211 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | - } |
|
213 | - |
|
214 | - $splittedToken = explode(':', $decryptedToken); |
|
215 | - if (count($splittedToken) !== 2) { |
|
216 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | - } |
|
218 | - |
|
219 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 24 * 7) || |
|
220 | - $user->getLastLogin() > $splittedToken[0]) { |
|
221 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | - } |
|
223 | - |
|
224 | - if (!hash_equals($splittedToken[1], $token)) { |
|
225 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param $message |
|
231 | - * @param array $additional |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - private function error($message, array $additional = []) { |
|
235 | - return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array $data |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - private function success($data = []) { |
|
243 | - return array_merge($data, ['status' => 'success']); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @PublicPage |
|
248 | - * @BruteForceProtection(action=passwordResetEmail) |
|
249 | - * @AnonRateThrottle(limit=10, period=300) |
|
250 | - * |
|
251 | - * @param string $user |
|
252 | - * @return JSONResponse |
|
253 | - */ |
|
254 | - public function email($user) { |
|
255 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | - return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | - } |
|
258 | - |
|
259 | - \OCP\Util::emitHook( |
|
260 | - '\OCA\Files_Sharing\API\Server2Server', |
|
261 | - 'preLoginNameUsedAsUserName', |
|
262 | - ['uid' => &$user] |
|
263 | - ); |
|
264 | - |
|
265 | - // FIXME: use HTTP error codes |
|
266 | - try { |
|
267 | - $this->sendEmail($user); |
|
268 | - } catch (ResetPasswordException $e) { |
|
269 | - // Ignore the error since we do not want to leak this info |
|
270 | - $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | - } catch (\Exception $e) { |
|
272 | - $this->logger->logException($e); |
|
273 | - } |
|
274 | - |
|
275 | - $response = new JSONResponse($this->success()); |
|
276 | - $response->throttle(); |
|
277 | - return $response; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @PublicPage |
|
282 | - * @param string $token |
|
283 | - * @param string $userId |
|
284 | - * @param string $password |
|
285 | - * @param boolean $proceed |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function setPassword($token, $userId, $password, $proceed) { |
|
289 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | - return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | - } |
|
292 | - |
|
293 | - if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | - foreach ($encryptionModules as $module) { |
|
296 | - /** @var IEncryptionModule $instance */ |
|
297 | - $instance = call_user_func($module['callback']); |
|
298 | - // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | - if ($instance->needDetailedAccessList()) { |
|
300 | - return $this->error('', ['encryption' => true]); |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - try { |
|
306 | - $this->checkPasswordResetToken($token, $userId); |
|
307 | - $user = $this->userManager->get($userId); |
|
308 | - |
|
309 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | - |
|
311 | - if (!$user->setPassword($password)) { |
|
312 | - throw new \Exception(); |
|
313 | - } |
|
314 | - |
|
315 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | - |
|
317 | - $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | - |
|
319 | - $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | - @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | - } catch (HintException $e) { |
|
322 | - return $this->error($e->getHint()); |
|
323 | - } catch (\Exception $e) { |
|
324 | - return $this->error($e->getMessage()); |
|
325 | - } |
|
326 | - |
|
327 | - return $this->success(['user' => $userId]); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $input |
|
332 | - * @throws ResetPasswordException |
|
333 | - * @throws \OCP\PreConditionNotMetException |
|
334 | - */ |
|
335 | - protected function sendEmail($input) { |
|
336 | - $user = $this->findUserByIdOrMail($input); |
|
337 | - $email = $user->getEMailAddress(); |
|
338 | - |
|
339 | - if (empty($email)) { |
|
340 | - throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | - } |
|
342 | - |
|
343 | - // Generate the token. It is stored encrypted in the database with the |
|
344 | - // secret being the users' email address appended with the system secret. |
|
345 | - // This makes the token automatically invalidate once the user changes |
|
346 | - // their email address. |
|
347 | - $token = $this->secureRandom->generate( |
|
348 | - 21, |
|
349 | - ISecureRandom::CHAR_DIGITS. |
|
350 | - ISecureRandom::CHAR_LOWER. |
|
351 | - ISecureRandom::CHAR_UPPER |
|
352 | - ); |
|
353 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | - |
|
357 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | - |
|
359 | - $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | - 'link' => $link, |
|
361 | - ]); |
|
362 | - |
|
363 | - $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | - $emailTemplate->addHeader(); |
|
365 | - $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | - |
|
367 | - $emailTemplate->addBodyText( |
|
368 | - htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | - $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | - ); |
|
371 | - |
|
372 | - $emailTemplate->addBodyButton( |
|
373 | - htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | - $link, |
|
375 | - false |
|
376 | - ); |
|
377 | - $emailTemplate->addFooter(); |
|
378 | - |
|
379 | - try { |
|
380 | - $message = $this->mailer->createMessage(); |
|
381 | - $message->setTo([$email => $user->getUID()]); |
|
382 | - $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | - $message->useTemplate($emailTemplate); |
|
384 | - $this->mailer->send($message); |
|
385 | - } catch (\Exception $e) { |
|
386 | - // Log the exception and continue |
|
387 | - $this->logger->logException($e); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @param string $input |
|
393 | - * @return IUser |
|
394 | - * @throws ResetPasswordException |
|
395 | - */ |
|
396 | - protected function findUserByIdOrMail($input) { |
|
397 | - $user = $this->userManager->get($input); |
|
398 | - if ($user instanceof IUser) { |
|
399 | - if (!$user->isEnabled()) { |
|
400 | - throw new ResetPasswordException('User is disabled'); |
|
401 | - } |
|
402 | - |
|
403 | - return $user; |
|
404 | - } |
|
405 | - |
|
406 | - $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | - return $user->isEnabled(); |
|
408 | - }); |
|
409 | - |
|
410 | - if (count($users) === 1) { |
|
411 | - return reset($users); |
|
412 | - } |
|
413 | - |
|
414 | - throw new ResetPasswordException('Could not find user'); |
|
415 | - } |
|
72 | + /** @var IURLGenerator */ |
|
73 | + protected $urlGenerator; |
|
74 | + /** @var IUserManager */ |
|
75 | + protected $userManager; |
|
76 | + /** @var Defaults */ |
|
77 | + protected $defaults; |
|
78 | + /** @var IL10N */ |
|
79 | + protected $l10n; |
|
80 | + /** @var string */ |
|
81 | + protected $from; |
|
82 | + /** @var IManager */ |
|
83 | + protected $encryptionManager; |
|
84 | + /** @var IConfig */ |
|
85 | + protected $config; |
|
86 | + /** @var ISecureRandom */ |
|
87 | + protected $secureRandom; |
|
88 | + /** @var IMailer */ |
|
89 | + protected $mailer; |
|
90 | + /** @var ITimeFactory */ |
|
91 | + protected $timeFactory; |
|
92 | + /** @var ICrypto */ |
|
93 | + protected $crypto; |
|
94 | + /** @var ILogger */ |
|
95 | + private $logger; |
|
96 | + /** @var Manager */ |
|
97 | + private $twoFactorManager; |
|
98 | + /** @var IInitialStateService */ |
|
99 | + private $initialStateService; |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $appName |
|
103 | + * @param IRequest $request |
|
104 | + * @param IURLGenerator $urlGenerator |
|
105 | + * @param IUserManager $userManager |
|
106 | + * @param Defaults $defaults |
|
107 | + * @param IL10N $l10n |
|
108 | + * @param IConfig $config |
|
109 | + * @param ISecureRandom $secureRandom |
|
110 | + * @param string $defaultMailAddress |
|
111 | + * @param IManager $encryptionManager |
|
112 | + * @param IMailer $mailer |
|
113 | + * @param ITimeFactory $timeFactory |
|
114 | + * @param ICrypto $crypto |
|
115 | + */ |
|
116 | + public function __construct($appName, |
|
117 | + IRequest $request, |
|
118 | + IURLGenerator $urlGenerator, |
|
119 | + IUserManager $userManager, |
|
120 | + Defaults $defaults, |
|
121 | + IL10N $l10n, |
|
122 | + IConfig $config, |
|
123 | + ISecureRandom $secureRandom, |
|
124 | + $defaultMailAddress, |
|
125 | + IManager $encryptionManager, |
|
126 | + IMailer $mailer, |
|
127 | + ITimeFactory $timeFactory, |
|
128 | + ICrypto $crypto, |
|
129 | + ILogger $logger, |
|
130 | + Manager $twoFactorManager, |
|
131 | + IInitialStateService $initialStateService) { |
|
132 | + parent::__construct($appName, $request); |
|
133 | + $this->urlGenerator = $urlGenerator; |
|
134 | + $this->userManager = $userManager; |
|
135 | + $this->defaults = $defaults; |
|
136 | + $this->l10n = $l10n; |
|
137 | + $this->secureRandom = $secureRandom; |
|
138 | + $this->from = $defaultMailAddress; |
|
139 | + $this->encryptionManager = $encryptionManager; |
|
140 | + $this->config = $config; |
|
141 | + $this->mailer = $mailer; |
|
142 | + $this->timeFactory = $timeFactory; |
|
143 | + $this->crypto = $crypto; |
|
144 | + $this->logger = $logger; |
|
145 | + $this->twoFactorManager = $twoFactorManager; |
|
146 | + $this->initialStateService = $initialStateService; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Someone wants to reset their password: |
|
151 | + * |
|
152 | + * @PublicPage |
|
153 | + * @NoCSRFRequired |
|
154 | + * |
|
155 | + * @param string $token |
|
156 | + * @param string $userId |
|
157 | + * @return TemplateResponse |
|
158 | + */ |
|
159 | + public function resetform($token, $userId) { |
|
160 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | + return new TemplateResponse('core', 'error', [ |
|
162 | + 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | + ], |
|
164 | + 'guest' |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + try { |
|
169 | + $this->checkPasswordResetToken($token, $userId); |
|
170 | + } catch (\Exception $e) { |
|
171 | + return new TemplateResponse( |
|
172 | + 'core', 'error', [ |
|
173 | + "errors" => [["error" => $e->getMessage()]] |
|
174 | + ], |
|
175 | + 'guest' |
|
176 | + ); |
|
177 | + } |
|
178 | + $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | + $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | + $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | + ); |
|
182 | + |
|
183 | + return new TemplateResponse( |
|
184 | + 'core', |
|
185 | + 'login', |
|
186 | + [], |
|
187 | + 'guest' |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $token |
|
193 | + * @param string $userId |
|
194 | + * @throws \Exception |
|
195 | + */ |
|
196 | + protected function checkPasswordResetToken($token, $userId) { |
|
197 | + $user = $this->userManager->get($userId); |
|
198 | + if ($user === null || !$user->isEnabled()) { |
|
199 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | + } |
|
201 | + |
|
202 | + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | + if ($encryptedToken === null) { |
|
204 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | + } |
|
206 | + |
|
207 | + try { |
|
208 | + $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | + $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | + } catch (\Exception $e) { |
|
211 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | + } |
|
213 | + |
|
214 | + $splittedToken = explode(':', $decryptedToken); |
|
215 | + if (count($splittedToken) !== 2) { |
|
216 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | + } |
|
218 | + |
|
219 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 24 * 7) || |
|
220 | + $user->getLastLogin() > $splittedToken[0]) { |
|
221 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | + } |
|
223 | + |
|
224 | + if (!hash_equals($splittedToken[1], $token)) { |
|
225 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param $message |
|
231 | + * @param array $additional |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + private function error($message, array $additional = []) { |
|
235 | + return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array $data |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + private function success($data = []) { |
|
243 | + return array_merge($data, ['status' => 'success']); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @PublicPage |
|
248 | + * @BruteForceProtection(action=passwordResetEmail) |
|
249 | + * @AnonRateThrottle(limit=10, period=300) |
|
250 | + * |
|
251 | + * @param string $user |
|
252 | + * @return JSONResponse |
|
253 | + */ |
|
254 | + public function email($user) { |
|
255 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | + return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | + } |
|
258 | + |
|
259 | + \OCP\Util::emitHook( |
|
260 | + '\OCA\Files_Sharing\API\Server2Server', |
|
261 | + 'preLoginNameUsedAsUserName', |
|
262 | + ['uid' => &$user] |
|
263 | + ); |
|
264 | + |
|
265 | + // FIXME: use HTTP error codes |
|
266 | + try { |
|
267 | + $this->sendEmail($user); |
|
268 | + } catch (ResetPasswordException $e) { |
|
269 | + // Ignore the error since we do not want to leak this info |
|
270 | + $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | + } catch (\Exception $e) { |
|
272 | + $this->logger->logException($e); |
|
273 | + } |
|
274 | + |
|
275 | + $response = new JSONResponse($this->success()); |
|
276 | + $response->throttle(); |
|
277 | + return $response; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @PublicPage |
|
282 | + * @param string $token |
|
283 | + * @param string $userId |
|
284 | + * @param string $password |
|
285 | + * @param boolean $proceed |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function setPassword($token, $userId, $password, $proceed) { |
|
289 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | + return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | + } |
|
292 | + |
|
293 | + if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | + foreach ($encryptionModules as $module) { |
|
296 | + /** @var IEncryptionModule $instance */ |
|
297 | + $instance = call_user_func($module['callback']); |
|
298 | + // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | + if ($instance->needDetailedAccessList()) { |
|
300 | + return $this->error('', ['encryption' => true]); |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + try { |
|
306 | + $this->checkPasswordResetToken($token, $userId); |
|
307 | + $user = $this->userManager->get($userId); |
|
308 | + |
|
309 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | + |
|
311 | + if (!$user->setPassword($password)) { |
|
312 | + throw new \Exception(); |
|
313 | + } |
|
314 | + |
|
315 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | + |
|
317 | + $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | + |
|
319 | + $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | + @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | + } catch (HintException $e) { |
|
322 | + return $this->error($e->getHint()); |
|
323 | + } catch (\Exception $e) { |
|
324 | + return $this->error($e->getMessage()); |
|
325 | + } |
|
326 | + |
|
327 | + return $this->success(['user' => $userId]); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $input |
|
332 | + * @throws ResetPasswordException |
|
333 | + * @throws \OCP\PreConditionNotMetException |
|
334 | + */ |
|
335 | + protected function sendEmail($input) { |
|
336 | + $user = $this->findUserByIdOrMail($input); |
|
337 | + $email = $user->getEMailAddress(); |
|
338 | + |
|
339 | + if (empty($email)) { |
|
340 | + throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | + } |
|
342 | + |
|
343 | + // Generate the token. It is stored encrypted in the database with the |
|
344 | + // secret being the users' email address appended with the system secret. |
|
345 | + // This makes the token automatically invalidate once the user changes |
|
346 | + // their email address. |
|
347 | + $token = $this->secureRandom->generate( |
|
348 | + 21, |
|
349 | + ISecureRandom::CHAR_DIGITS. |
|
350 | + ISecureRandom::CHAR_LOWER. |
|
351 | + ISecureRandom::CHAR_UPPER |
|
352 | + ); |
|
353 | + $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | + |
|
357 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | + |
|
359 | + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | + 'link' => $link, |
|
361 | + ]); |
|
362 | + |
|
363 | + $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | + $emailTemplate->addHeader(); |
|
365 | + $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | + |
|
367 | + $emailTemplate->addBodyText( |
|
368 | + htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | + $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | + ); |
|
371 | + |
|
372 | + $emailTemplate->addBodyButton( |
|
373 | + htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | + $link, |
|
375 | + false |
|
376 | + ); |
|
377 | + $emailTemplate->addFooter(); |
|
378 | + |
|
379 | + try { |
|
380 | + $message = $this->mailer->createMessage(); |
|
381 | + $message->setTo([$email => $user->getUID()]); |
|
382 | + $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | + $message->useTemplate($emailTemplate); |
|
384 | + $this->mailer->send($message); |
|
385 | + } catch (\Exception $e) { |
|
386 | + // Log the exception and continue |
|
387 | + $this->logger->logException($e); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @param string $input |
|
393 | + * @return IUser |
|
394 | + * @throws ResetPasswordException |
|
395 | + */ |
|
396 | + protected function findUserByIdOrMail($input) { |
|
397 | + $user = $this->userManager->get($input); |
|
398 | + if ($user instanceof IUser) { |
|
399 | + if (!$user->isEnabled()) { |
|
400 | + throw new ResetPasswordException('User is disabled'); |
|
401 | + } |
|
402 | + |
|
403 | + return $user; |
|
404 | + } |
|
405 | + |
|
406 | + $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | + return $user->isEnabled(); |
|
408 | + }); |
|
409 | + |
|
410 | + if (count($users) === 1) { |
|
411 | + return reset($users); |
|
412 | + } |
|
413 | + |
|
414 | + throw new ResetPasswordException('Could not find user'); |
|
415 | + } |
|
416 | 416 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $this->sendEmail($user); |
268 | 268 | } catch (ResetPasswordException $e) { |
269 | 269 | // Ignore the error since we do not want to leak this info |
270 | - $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
270 | + $this->logger->warning('Could not send password reset email: '.$e->getMessage()); |
|
271 | 271 | } catch (\Exception $e) { |
272 | 272 | $this->logger->logException($e); |
273 | 273 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $email = $user->getEMailAddress(); |
338 | 338 | |
339 | 339 | if (empty($email)) { |
340 | - throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
340 | + throw new ResetPasswordException('Could not send reset e-mail since there is no email for username '.$input); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | // Generate the token. It is stored encrypted in the database with the |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | ISecureRandom::CHAR_LOWER. |
351 | 351 | ISecureRandom::CHAR_UPPER |
352 | 352 | ); |
353 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
353 | + $tokenValue = $this->timeFactory->getTime().':'.$token; |
|
354 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email.$this->config->getSystemValue('secret')); |
|
355 | 355 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
356 | 356 | |
357 | 357 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | return $user; |
404 | 404 | } |
405 | 405 | |
406 | - $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
406 | + $users = array_filter($this->userManager->getByEmail($input), function(IUser $user) { |
|
407 | 407 | return $user->isEnabled(); |
408 | 408 | }); |
409 | 409 |
@@ -43,104 +43,104 @@ |
||
43 | 43 | |
44 | 44 | class SvgController extends Controller { |
45 | 45 | |
46 | - /** @var string */ |
|
47 | - protected $serverRoot; |
|
48 | - |
|
49 | - /** @var ITimeFactory */ |
|
50 | - protected $timeFactory; |
|
51 | - |
|
52 | - /** @var IAppManager */ |
|
53 | - protected $appManager; |
|
54 | - |
|
55 | - /** @var IconsCacher */ |
|
56 | - private $iconsCacher; |
|
57 | - |
|
58 | - public function __construct(string $appName, |
|
59 | - IRequest $request, |
|
60 | - ITimeFactory $timeFactory, |
|
61 | - IAppManager $appManager, |
|
62 | - IconsCacher $iconsCacher) { |
|
63 | - parent::__construct($appName, $request); |
|
64 | - |
|
65 | - $this->serverRoot = \OC::$SERVERROOT; |
|
66 | - $this->timeFactory = $timeFactory; |
|
67 | - $this->appManager = $appManager; |
|
68 | - $this->iconsCacher = $iconsCacher; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @PublicPage |
|
73 | - * @NoCSRFRequired |
|
74 | - * @NoSameSiteCookieRequired |
|
75 | - * |
|
76 | - * Generate svg from filename with the requested color |
|
77 | - * |
|
78 | - * @param string $folder |
|
79 | - * @param string $fileName |
|
80 | - * @param string $color |
|
81 | - * @return DataDisplayResponse|NotFoundResponse |
|
82 | - */ |
|
83 | - public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
84 | - $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
85 | - return $this->getSvg($path, $color, $fileName); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @PublicPage |
|
90 | - * @NoCSRFRequired |
|
91 | - * @NoSameSiteCookieRequired |
|
92 | - * |
|
93 | - * Generate svg from filename with the requested color |
|
94 | - * |
|
95 | - * @param string $app |
|
96 | - * @param string $fileName |
|
97 | - * @param string $color |
|
98 | - * @return DataDisplayResponse|NotFoundResponse |
|
99 | - */ |
|
100 | - public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
101 | - try { |
|
102 | - $appPath = $this->appManager->getAppPath($app); |
|
103 | - } catch (AppPathNotFoundException $e) { |
|
104 | - return new NotFoundResponse(); |
|
105 | - } |
|
106 | - |
|
107 | - $path = $appPath . "/img/$fileName.svg"; |
|
108 | - return $this->getSvg($path, $color, $fileName); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Generate svg from filename with the requested color |
|
113 | - * |
|
114 | - * @param string $path |
|
115 | - * @param string $color |
|
116 | - * @param string $fileName |
|
117 | - * @return DataDisplayResponse|NotFoundResponse |
|
118 | - */ |
|
119 | - private function getSvg(string $path, string $color, string $fileName) { |
|
120 | - if (!file_exists($path)) { |
|
121 | - return new NotFoundResponse(); |
|
122 | - } |
|
123 | - |
|
124 | - $svg = file_get_contents($path); |
|
125 | - |
|
126 | - if ($svg === null) { |
|
127 | - return new NotFoundResponse(); |
|
128 | - } |
|
129 | - |
|
130 | - $svg = $this->iconsCacher->colorizeSvg($svg, $color); |
|
131 | - |
|
132 | - $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
133 | - |
|
134 | - // Set cache control |
|
135 | - $ttl = 31536000; |
|
136 | - $response->cacheFor($ttl); |
|
137 | - $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
138 | - $expires = new \DateTime(); |
|
139 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
140 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
141 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
142 | - $response->addHeader('Pragma', 'cache'); |
|
143 | - |
|
144 | - return $response; |
|
145 | - } |
|
46 | + /** @var string */ |
|
47 | + protected $serverRoot; |
|
48 | + |
|
49 | + /** @var ITimeFactory */ |
|
50 | + protected $timeFactory; |
|
51 | + |
|
52 | + /** @var IAppManager */ |
|
53 | + protected $appManager; |
|
54 | + |
|
55 | + /** @var IconsCacher */ |
|
56 | + private $iconsCacher; |
|
57 | + |
|
58 | + public function __construct(string $appName, |
|
59 | + IRequest $request, |
|
60 | + ITimeFactory $timeFactory, |
|
61 | + IAppManager $appManager, |
|
62 | + IconsCacher $iconsCacher) { |
|
63 | + parent::__construct($appName, $request); |
|
64 | + |
|
65 | + $this->serverRoot = \OC::$SERVERROOT; |
|
66 | + $this->timeFactory = $timeFactory; |
|
67 | + $this->appManager = $appManager; |
|
68 | + $this->iconsCacher = $iconsCacher; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @PublicPage |
|
73 | + * @NoCSRFRequired |
|
74 | + * @NoSameSiteCookieRequired |
|
75 | + * |
|
76 | + * Generate svg from filename with the requested color |
|
77 | + * |
|
78 | + * @param string $folder |
|
79 | + * @param string $fileName |
|
80 | + * @param string $color |
|
81 | + * @return DataDisplayResponse|NotFoundResponse |
|
82 | + */ |
|
83 | + public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') { |
|
84 | + $path = $this->serverRoot . "/core/img/$folder/$fileName.svg"; |
|
85 | + return $this->getSvg($path, $color, $fileName); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @PublicPage |
|
90 | + * @NoCSRFRequired |
|
91 | + * @NoSameSiteCookieRequired |
|
92 | + * |
|
93 | + * Generate svg from filename with the requested color |
|
94 | + * |
|
95 | + * @param string $app |
|
96 | + * @param string $fileName |
|
97 | + * @param string $color |
|
98 | + * @return DataDisplayResponse|NotFoundResponse |
|
99 | + */ |
|
100 | + public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') { |
|
101 | + try { |
|
102 | + $appPath = $this->appManager->getAppPath($app); |
|
103 | + } catch (AppPathNotFoundException $e) { |
|
104 | + return new NotFoundResponse(); |
|
105 | + } |
|
106 | + |
|
107 | + $path = $appPath . "/img/$fileName.svg"; |
|
108 | + return $this->getSvg($path, $color, $fileName); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Generate svg from filename with the requested color |
|
113 | + * |
|
114 | + * @param string $path |
|
115 | + * @param string $color |
|
116 | + * @param string $fileName |
|
117 | + * @return DataDisplayResponse|NotFoundResponse |
|
118 | + */ |
|
119 | + private function getSvg(string $path, string $color, string $fileName) { |
|
120 | + if (!file_exists($path)) { |
|
121 | + return new NotFoundResponse(); |
|
122 | + } |
|
123 | + |
|
124 | + $svg = file_get_contents($path); |
|
125 | + |
|
126 | + if ($svg === null) { |
|
127 | + return new NotFoundResponse(); |
|
128 | + } |
|
129 | + |
|
130 | + $svg = $this->iconsCacher->colorizeSvg($svg, $color); |
|
131 | + |
|
132 | + $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); |
|
133 | + |
|
134 | + // Set cache control |
|
135 | + $ttl = 31536000; |
|
136 | + $response->cacheFor($ttl); |
|
137 | + $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"'); |
|
138 | + $expires = new \DateTime(); |
|
139 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
140 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
141 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
142 | + $response->addHeader('Pragma', 'cache'); |
|
143 | + |
|
144 | + return $response; |
|
145 | + } |
|
146 | 146 | } |
@@ -36,117 +36,117 @@ |
||
36 | 36 | use OCP\ILogger; |
37 | 37 | |
38 | 38 | class SetupController { |
39 | - /** @var Setup */ |
|
40 | - protected $setupHelper; |
|
41 | - /** @var string */ |
|
42 | - private $autoConfigFile; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param Setup $setupHelper |
|
46 | - */ |
|
47 | - public function __construct(Setup $setupHelper) { |
|
48 | - $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
49 | - $this->setupHelper = $setupHelper; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param $post |
|
54 | - */ |
|
55 | - public function run($post) { |
|
56 | - // Check for autosetup: |
|
57 | - $post = $this->loadAutoConfig($post); |
|
58 | - $opts = $this->setupHelper->getSystemInfo(); |
|
59 | - |
|
60 | - // convert 'abcpassword' to 'abcpass' |
|
61 | - if (isset($post['adminpassword'])) { |
|
62 | - $post['adminpass'] = $post['adminpassword']; |
|
63 | - } |
|
64 | - if (isset($post['dbpassword'])) { |
|
65 | - $post['dbpass'] = $post['dbpassword']; |
|
66 | - } |
|
67 | - |
|
68 | - if (!is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
69 | - $this->displaySetupForbidden(); |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($post['install']) and $post['install'] == 'true') { |
|
74 | - // We have to launch the installation process : |
|
75 | - $e = $this->setupHelper->install($post); |
|
76 | - $errors = ['errors' => $e]; |
|
77 | - |
|
78 | - if (count($e) > 0) { |
|
79 | - $options = array_merge($opts, $post, $errors); |
|
80 | - $this->display($options); |
|
81 | - } else { |
|
82 | - $this->finishSetup(isset($post['install-recommended-apps'])); |
|
83 | - } |
|
84 | - } else { |
|
85 | - $options = array_merge($opts, $post); |
|
86 | - $this->display($options); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - private function displaySetupForbidden() { |
|
91 | - \OC_Template::printGuestPage('', 'installation_forbidden'); |
|
92 | - } |
|
93 | - |
|
94 | - public function display($post) { |
|
95 | - $defaults = [ |
|
96 | - 'adminlogin' => '', |
|
97 | - 'adminpass' => '', |
|
98 | - 'dbuser' => '', |
|
99 | - 'dbpass' => '', |
|
100 | - 'dbname' => '', |
|
101 | - 'dbtablespace' => '', |
|
102 | - 'dbhost' => 'localhost', |
|
103 | - 'dbtype' => '', |
|
104 | - ]; |
|
105 | - $parameters = array_merge($defaults, $post); |
|
106 | - |
|
107 | - \OC_Util::addScript('setup'); |
|
108 | - \OC_Template::printGuestPage('', 'installation', $parameters); |
|
109 | - } |
|
110 | - |
|
111 | - private function finishSetup(bool $installRecommended) { |
|
112 | - if (file_exists($this->autoConfigFile)) { |
|
113 | - unlink($this->autoConfigFile); |
|
114 | - } |
|
115 | - \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
116 | - |
|
117 | - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
118 | - if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
119 | - \OC_Template::printGuestPage('', 'installation_incomplete'); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - if ($installRecommended) { |
|
124 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
125 | - $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended'); |
|
126 | - header('Location: ' . $location); |
|
127 | - exit(); |
|
128 | - } |
|
129 | - \OC_Util::redirectToDefaultPage(); |
|
130 | - } |
|
131 | - |
|
132 | - public function loadAutoConfig($post) { |
|
133 | - if (file_exists($this->autoConfigFile)) { |
|
134 | - \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); |
|
135 | - $AUTOCONFIG = []; |
|
136 | - include $this->autoConfigFile; |
|
137 | - $post = array_merge($post, $AUTOCONFIG); |
|
138 | - } |
|
139 | - |
|
140 | - $dbIsSet = isset($post['dbtype']); |
|
141 | - $directoryIsSet = isset($post['directory']); |
|
142 | - $adminAccountIsSet = isset($post['adminlogin']); |
|
143 | - |
|
144 | - if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) { |
|
145 | - $post['install'] = 'true'; |
|
146 | - } |
|
147 | - $post['dbIsSet'] = $dbIsSet; |
|
148 | - $post['directoryIsSet'] = $directoryIsSet; |
|
149 | - |
|
150 | - return $post; |
|
151 | - } |
|
39 | + /** @var Setup */ |
|
40 | + protected $setupHelper; |
|
41 | + /** @var string */ |
|
42 | + private $autoConfigFile; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param Setup $setupHelper |
|
46 | + */ |
|
47 | + public function __construct(Setup $setupHelper) { |
|
48 | + $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
49 | + $this->setupHelper = $setupHelper; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param $post |
|
54 | + */ |
|
55 | + public function run($post) { |
|
56 | + // Check for autosetup: |
|
57 | + $post = $this->loadAutoConfig($post); |
|
58 | + $opts = $this->setupHelper->getSystemInfo(); |
|
59 | + |
|
60 | + // convert 'abcpassword' to 'abcpass' |
|
61 | + if (isset($post['adminpassword'])) { |
|
62 | + $post['adminpass'] = $post['adminpassword']; |
|
63 | + } |
|
64 | + if (isset($post['dbpassword'])) { |
|
65 | + $post['dbpass'] = $post['dbpassword']; |
|
66 | + } |
|
67 | + |
|
68 | + if (!is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
69 | + $this->displaySetupForbidden(); |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($post['install']) and $post['install'] == 'true') { |
|
74 | + // We have to launch the installation process : |
|
75 | + $e = $this->setupHelper->install($post); |
|
76 | + $errors = ['errors' => $e]; |
|
77 | + |
|
78 | + if (count($e) > 0) { |
|
79 | + $options = array_merge($opts, $post, $errors); |
|
80 | + $this->display($options); |
|
81 | + } else { |
|
82 | + $this->finishSetup(isset($post['install-recommended-apps'])); |
|
83 | + } |
|
84 | + } else { |
|
85 | + $options = array_merge($opts, $post); |
|
86 | + $this->display($options); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + private function displaySetupForbidden() { |
|
91 | + \OC_Template::printGuestPage('', 'installation_forbidden'); |
|
92 | + } |
|
93 | + |
|
94 | + public function display($post) { |
|
95 | + $defaults = [ |
|
96 | + 'adminlogin' => '', |
|
97 | + 'adminpass' => '', |
|
98 | + 'dbuser' => '', |
|
99 | + 'dbpass' => '', |
|
100 | + 'dbname' => '', |
|
101 | + 'dbtablespace' => '', |
|
102 | + 'dbhost' => 'localhost', |
|
103 | + 'dbtype' => '', |
|
104 | + ]; |
|
105 | + $parameters = array_merge($defaults, $post); |
|
106 | + |
|
107 | + \OC_Util::addScript('setup'); |
|
108 | + \OC_Template::printGuestPage('', 'installation', $parameters); |
|
109 | + } |
|
110 | + |
|
111 | + private function finishSetup(bool $installRecommended) { |
|
112 | + if (file_exists($this->autoConfigFile)) { |
|
113 | + unlink($this->autoConfigFile); |
|
114 | + } |
|
115 | + \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
116 | + |
|
117 | + if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
118 | + if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
119 | + \OC_Template::printGuestPage('', 'installation_incomplete'); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + if ($installRecommended) { |
|
124 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
125 | + $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended'); |
|
126 | + header('Location: ' . $location); |
|
127 | + exit(); |
|
128 | + } |
|
129 | + \OC_Util::redirectToDefaultPage(); |
|
130 | + } |
|
131 | + |
|
132 | + public function loadAutoConfig($post) { |
|
133 | + if (file_exists($this->autoConfigFile)) { |
|
134 | + \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); |
|
135 | + $AUTOCONFIG = []; |
|
136 | + include $this->autoConfigFile; |
|
137 | + $post = array_merge($post, $AUTOCONFIG); |
|
138 | + } |
|
139 | + |
|
140 | + $dbIsSet = isset($post['dbtype']); |
|
141 | + $directoryIsSet = isset($post['directory']); |
|
142 | + $adminAccountIsSet = isset($post['adminlogin']); |
|
143 | + |
|
144 | + if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) { |
|
145 | + $post['install'] = 'true'; |
|
146 | + } |
|
147 | + $post['dbIsSet'] = $dbIsSet; |
|
148 | + $post['directoryIsSet'] = $directoryIsSet; |
|
149 | + |
|
150 | + return $post; |
|
151 | + } |
|
152 | 152 | } |
@@ -123,7 +123,7 @@ |
||
123 | 123 | if ($installRecommended) { |
124 | 124 | $urlGenerator = \OC::$server->getURLGenerator(); |
125 | 125 | $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended'); |
126 | - header('Location: ' . $location); |
|
126 | + header('Location: '.$location); |
|
127 | 127 | exit(); |
128 | 128 | } |
129 | 129 | \OC_Util::redirectToDefaultPage(); |
@@ -53,274 +53,274 @@ |
||
53 | 53 | */ |
54 | 54 | class AvatarController extends Controller { |
55 | 55 | |
56 | - /** @var IAvatarManager */ |
|
57 | - protected $avatarManager; |
|
58 | - |
|
59 | - /** @var ICache */ |
|
60 | - protected $cache; |
|
61 | - |
|
62 | - /** @var IL10N */ |
|
63 | - protected $l; |
|
64 | - |
|
65 | - /** @var IUserManager */ |
|
66 | - protected $userManager; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var IRootFolder */ |
|
72 | - protected $rootFolder; |
|
73 | - |
|
74 | - /** @var ILogger */ |
|
75 | - protected $logger; |
|
76 | - |
|
77 | - /** @var string */ |
|
78 | - protected $userId; |
|
79 | - |
|
80 | - /** @var TimeFactory */ |
|
81 | - protected $timeFactory; |
|
82 | - |
|
83 | - public function __construct($appName, |
|
84 | - IRequest $request, |
|
85 | - IAvatarManager $avatarManager, |
|
86 | - ICache $cache, |
|
87 | - IL10N $l10n, |
|
88 | - IUserManager $userManager, |
|
89 | - IRootFolder $rootFolder, |
|
90 | - ILogger $logger, |
|
91 | - $userId, |
|
92 | - TimeFactory $timeFactory) { |
|
93 | - parent::__construct($appName, $request); |
|
94 | - |
|
95 | - $this->avatarManager = $avatarManager; |
|
96 | - $this->cache = $cache; |
|
97 | - $this->l = $l10n; |
|
98 | - $this->userManager = $userManager; |
|
99 | - $this->rootFolder = $rootFolder; |
|
100 | - $this->logger = $logger; |
|
101 | - $this->userId = $userId; |
|
102 | - $this->timeFactory = $timeFactory; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @NoAdminRequired |
|
108 | - * @NoCSRFRequired |
|
109 | - * @NoSameSiteCookieRequired |
|
110 | - * @PublicPage |
|
111 | - * |
|
112 | - * @param string $userId |
|
113 | - * @param int $size |
|
114 | - * @return JSONResponse|FileDisplayResponse |
|
115 | - */ |
|
116 | - public function getAvatar($userId, $size) { |
|
117 | - // min/max size |
|
118 | - if ($size > 2048) { |
|
119 | - $size = 2048; |
|
120 | - } elseif ($size <= 0) { |
|
121 | - $size = 64; |
|
122 | - } |
|
123 | - |
|
124 | - try { |
|
125 | - $avatar = $this->avatarManager->getAvatar($userId); |
|
126 | - $avatarFile = $avatar->getFile($size); |
|
127 | - $response = new FileDisplayResponse( |
|
128 | - $avatarFile, |
|
129 | - Http::STATUS_OK, |
|
130 | - ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
131 | - ); |
|
132 | - } catch (\Exception $e) { |
|
133 | - return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
134 | - } |
|
135 | - |
|
136 | - // Cache for 1 day |
|
137 | - $response->cacheFor(60 * 60 * 24); |
|
138 | - return $response; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @NoAdminRequired |
|
143 | - * |
|
144 | - * @param string $path |
|
145 | - * @return JSONResponse |
|
146 | - */ |
|
147 | - public function postAvatar($path) { |
|
148 | - $files = $this->request->getUploadedFile('files'); |
|
149 | - |
|
150 | - if (isset($path)) { |
|
151 | - $path = stripslashes($path); |
|
152 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
153 | - /** @var File $node */ |
|
154 | - $node = $userFolder->get($path); |
|
155 | - if (!($node instanceof File)) { |
|
156 | - return new JSONResponse(['data' => ['message' => $this->l->t('Please select a file.')]]); |
|
157 | - } |
|
158 | - if ($node->getSize() > 20 * 1024 * 1024) { |
|
159 | - return new JSONResponse( |
|
160 | - ['data' => ['message' => $this->l->t('File is too big')]], |
|
161 | - Http::STATUS_BAD_REQUEST |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
166 | - return new JSONResponse( |
|
167 | - ['data' => ['message' => $this->l->t('The selected file is not an image.')]], |
|
168 | - Http::STATUS_BAD_REQUEST |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - try { |
|
173 | - $content = $node->getContent(); |
|
174 | - } catch (\OCP\Files\NotPermittedException $e) { |
|
175 | - return new JSONResponse( |
|
176 | - ['data' => ['message' => $this->l->t('The selected file cannot be read.')]], |
|
177 | - Http::STATUS_BAD_REQUEST |
|
178 | - ); |
|
179 | - } |
|
180 | - } elseif (!is_null($files)) { |
|
181 | - if ( |
|
182 | - $files['error'][0] === 0 && |
|
183 | - is_uploaded_file($files['tmp_name'][0]) && |
|
184 | - !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) |
|
185 | - ) { |
|
186 | - if ($files['size'][0] > 20 * 1024 * 1024) { |
|
187 | - return new JSONResponse( |
|
188 | - ['data' => ['message' => $this->l->t('File is too big')]], |
|
189 | - Http::STATUS_BAD_REQUEST |
|
190 | - ); |
|
191 | - } |
|
192 | - $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); |
|
193 | - $content = $this->cache->get('avatar_upload'); |
|
194 | - unlink($files['tmp_name'][0]); |
|
195 | - } else { |
|
196 | - return new JSONResponse( |
|
197 | - ['data' => ['message' => $this->l->t('Invalid file provided')]], |
|
198 | - Http::STATUS_BAD_REQUEST |
|
199 | - ); |
|
200 | - } |
|
201 | - } else { |
|
202 | - //Add imgfile |
|
203 | - return new JSONResponse( |
|
204 | - ['data' => ['message' => $this->l->t('No image or file provided')]], |
|
205 | - Http::STATUS_BAD_REQUEST |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - try { |
|
210 | - $image = new \OC_Image(); |
|
211 | - $image->loadFromData($content); |
|
212 | - $image->readExif($content); |
|
213 | - $image->fixOrientation(); |
|
214 | - |
|
215 | - if ($image->valid()) { |
|
216 | - $mimeType = $image->mimeType(); |
|
217 | - if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
218 | - return new JSONResponse( |
|
219 | - ['data' => ['message' => $this->l->t('Unknown filetype')]], |
|
220 | - Http::STATUS_OK |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - $this->cache->set('tmpAvatar', $image->data(), 7200); |
|
225 | - return new JSONResponse( |
|
226 | - ['data' => 'notsquare'], |
|
227 | - Http::STATUS_OK |
|
228 | - ); |
|
229 | - } else { |
|
230 | - return new JSONResponse( |
|
231 | - ['data' => ['message' => $this->l->t('Invalid image')]], |
|
232 | - Http::STATUS_OK |
|
233 | - ); |
|
234 | - } |
|
235 | - } catch (\Exception $e) { |
|
236 | - $this->logger->logException($e, ['app' => 'core']); |
|
237 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @NoAdminRequired |
|
243 | - * |
|
244 | - * @return JSONResponse |
|
245 | - */ |
|
246 | - public function deleteAvatar() { |
|
247 | - try { |
|
248 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
249 | - $avatar->remove(); |
|
250 | - return new JSONResponse(); |
|
251 | - } catch (\Exception $e) { |
|
252 | - $this->logger->logException($e, ['app' => 'core']); |
|
253 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @NoAdminRequired |
|
259 | - * |
|
260 | - * @return JSONResponse|DataDisplayResponse |
|
261 | - */ |
|
262 | - public function getTmpAvatar() { |
|
263 | - $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
264 | - if (is_null($tmpAvatar)) { |
|
265 | - return new JSONResponse(['data' => [ |
|
266 | - 'message' => $this->l->t("No temporary profile picture available, try again") |
|
267 | - ]], |
|
268 | - Http::STATUS_NOT_FOUND); |
|
269 | - } |
|
270 | - |
|
271 | - $image = new \OC_Image(); |
|
272 | - $image->loadFromData($tmpAvatar); |
|
273 | - |
|
274 | - $resp = new DataDisplayResponse($image->data(), |
|
275 | - Http::STATUS_OK, |
|
276 | - ['Content-Type' => $image->mimeType()]); |
|
277 | - |
|
278 | - $resp->setETag((string)crc32($image->data())); |
|
279 | - $resp->cacheFor(0); |
|
280 | - $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); |
|
281 | - return $resp; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @NoAdminRequired |
|
286 | - * |
|
287 | - * @param array $crop |
|
288 | - * @return JSONResponse |
|
289 | - */ |
|
290 | - public function postCroppedAvatar($crop) { |
|
291 | - if (is_null($crop)) { |
|
292 | - return new JSONResponse(['data' => ['message' => $this->l->t("No crop data provided")]], |
|
293 | - Http::STATUS_BAD_REQUEST); |
|
294 | - } |
|
295 | - |
|
296 | - if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) { |
|
297 | - return new JSONResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], |
|
298 | - Http::STATUS_BAD_REQUEST); |
|
299 | - } |
|
300 | - |
|
301 | - $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
302 | - if (is_null($tmpAvatar)) { |
|
303 | - return new JSONResponse(['data' => [ |
|
304 | - 'message' => $this->l->t("No temporary profile picture available, try again") |
|
305 | - ]], |
|
306 | - Http::STATUS_BAD_REQUEST); |
|
307 | - } |
|
308 | - |
|
309 | - $image = new \OC_Image(); |
|
310 | - $image->loadFromData($tmpAvatar); |
|
311 | - $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); |
|
312 | - try { |
|
313 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
314 | - $avatar->set($image); |
|
315 | - // Clean up |
|
316 | - $this->cache->remove('tmpAvatar'); |
|
317 | - return new JSONResponse(['status' => 'success']); |
|
318 | - } catch (\OC\NotSquareException $e) { |
|
319 | - return new JSONResponse(['data' => ['message' => $this->l->t('Crop is not square')]], |
|
320 | - Http::STATUS_BAD_REQUEST); |
|
321 | - } catch (\Exception $e) { |
|
322 | - $this->logger->logException($e, ['app' => 'core']); |
|
323 | - return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
324 | - } |
|
325 | - } |
|
56 | + /** @var IAvatarManager */ |
|
57 | + protected $avatarManager; |
|
58 | + |
|
59 | + /** @var ICache */ |
|
60 | + protected $cache; |
|
61 | + |
|
62 | + /** @var IL10N */ |
|
63 | + protected $l; |
|
64 | + |
|
65 | + /** @var IUserManager */ |
|
66 | + protected $userManager; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var IRootFolder */ |
|
72 | + protected $rootFolder; |
|
73 | + |
|
74 | + /** @var ILogger */ |
|
75 | + protected $logger; |
|
76 | + |
|
77 | + /** @var string */ |
|
78 | + protected $userId; |
|
79 | + |
|
80 | + /** @var TimeFactory */ |
|
81 | + protected $timeFactory; |
|
82 | + |
|
83 | + public function __construct($appName, |
|
84 | + IRequest $request, |
|
85 | + IAvatarManager $avatarManager, |
|
86 | + ICache $cache, |
|
87 | + IL10N $l10n, |
|
88 | + IUserManager $userManager, |
|
89 | + IRootFolder $rootFolder, |
|
90 | + ILogger $logger, |
|
91 | + $userId, |
|
92 | + TimeFactory $timeFactory) { |
|
93 | + parent::__construct($appName, $request); |
|
94 | + |
|
95 | + $this->avatarManager = $avatarManager; |
|
96 | + $this->cache = $cache; |
|
97 | + $this->l = $l10n; |
|
98 | + $this->userManager = $userManager; |
|
99 | + $this->rootFolder = $rootFolder; |
|
100 | + $this->logger = $logger; |
|
101 | + $this->userId = $userId; |
|
102 | + $this->timeFactory = $timeFactory; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @NoAdminRequired |
|
108 | + * @NoCSRFRequired |
|
109 | + * @NoSameSiteCookieRequired |
|
110 | + * @PublicPage |
|
111 | + * |
|
112 | + * @param string $userId |
|
113 | + * @param int $size |
|
114 | + * @return JSONResponse|FileDisplayResponse |
|
115 | + */ |
|
116 | + public function getAvatar($userId, $size) { |
|
117 | + // min/max size |
|
118 | + if ($size > 2048) { |
|
119 | + $size = 2048; |
|
120 | + } elseif ($size <= 0) { |
|
121 | + $size = 64; |
|
122 | + } |
|
123 | + |
|
124 | + try { |
|
125 | + $avatar = $this->avatarManager->getAvatar($userId); |
|
126 | + $avatarFile = $avatar->getFile($size); |
|
127 | + $response = new FileDisplayResponse( |
|
128 | + $avatarFile, |
|
129 | + Http::STATUS_OK, |
|
130 | + ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
131 | + ); |
|
132 | + } catch (\Exception $e) { |
|
133 | + return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
134 | + } |
|
135 | + |
|
136 | + // Cache for 1 day |
|
137 | + $response->cacheFor(60 * 60 * 24); |
|
138 | + return $response; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @NoAdminRequired |
|
143 | + * |
|
144 | + * @param string $path |
|
145 | + * @return JSONResponse |
|
146 | + */ |
|
147 | + public function postAvatar($path) { |
|
148 | + $files = $this->request->getUploadedFile('files'); |
|
149 | + |
|
150 | + if (isset($path)) { |
|
151 | + $path = stripslashes($path); |
|
152 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
153 | + /** @var File $node */ |
|
154 | + $node = $userFolder->get($path); |
|
155 | + if (!($node instanceof File)) { |
|
156 | + return new JSONResponse(['data' => ['message' => $this->l->t('Please select a file.')]]); |
|
157 | + } |
|
158 | + if ($node->getSize() > 20 * 1024 * 1024) { |
|
159 | + return new JSONResponse( |
|
160 | + ['data' => ['message' => $this->l->t('File is too big')]], |
|
161 | + Http::STATUS_BAD_REQUEST |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
166 | + return new JSONResponse( |
|
167 | + ['data' => ['message' => $this->l->t('The selected file is not an image.')]], |
|
168 | + Http::STATUS_BAD_REQUEST |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + try { |
|
173 | + $content = $node->getContent(); |
|
174 | + } catch (\OCP\Files\NotPermittedException $e) { |
|
175 | + return new JSONResponse( |
|
176 | + ['data' => ['message' => $this->l->t('The selected file cannot be read.')]], |
|
177 | + Http::STATUS_BAD_REQUEST |
|
178 | + ); |
|
179 | + } |
|
180 | + } elseif (!is_null($files)) { |
|
181 | + if ( |
|
182 | + $files['error'][0] === 0 && |
|
183 | + is_uploaded_file($files['tmp_name'][0]) && |
|
184 | + !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) |
|
185 | + ) { |
|
186 | + if ($files['size'][0] > 20 * 1024 * 1024) { |
|
187 | + return new JSONResponse( |
|
188 | + ['data' => ['message' => $this->l->t('File is too big')]], |
|
189 | + Http::STATUS_BAD_REQUEST |
|
190 | + ); |
|
191 | + } |
|
192 | + $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); |
|
193 | + $content = $this->cache->get('avatar_upload'); |
|
194 | + unlink($files['tmp_name'][0]); |
|
195 | + } else { |
|
196 | + return new JSONResponse( |
|
197 | + ['data' => ['message' => $this->l->t('Invalid file provided')]], |
|
198 | + Http::STATUS_BAD_REQUEST |
|
199 | + ); |
|
200 | + } |
|
201 | + } else { |
|
202 | + //Add imgfile |
|
203 | + return new JSONResponse( |
|
204 | + ['data' => ['message' => $this->l->t('No image or file provided')]], |
|
205 | + Http::STATUS_BAD_REQUEST |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + try { |
|
210 | + $image = new \OC_Image(); |
|
211 | + $image->loadFromData($content); |
|
212 | + $image->readExif($content); |
|
213 | + $image->fixOrientation(); |
|
214 | + |
|
215 | + if ($image->valid()) { |
|
216 | + $mimeType = $image->mimeType(); |
|
217 | + if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
218 | + return new JSONResponse( |
|
219 | + ['data' => ['message' => $this->l->t('Unknown filetype')]], |
|
220 | + Http::STATUS_OK |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + $this->cache->set('tmpAvatar', $image->data(), 7200); |
|
225 | + return new JSONResponse( |
|
226 | + ['data' => 'notsquare'], |
|
227 | + Http::STATUS_OK |
|
228 | + ); |
|
229 | + } else { |
|
230 | + return new JSONResponse( |
|
231 | + ['data' => ['message' => $this->l->t('Invalid image')]], |
|
232 | + Http::STATUS_OK |
|
233 | + ); |
|
234 | + } |
|
235 | + } catch (\Exception $e) { |
|
236 | + $this->logger->logException($e, ['app' => 'core']); |
|
237 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @NoAdminRequired |
|
243 | + * |
|
244 | + * @return JSONResponse |
|
245 | + */ |
|
246 | + public function deleteAvatar() { |
|
247 | + try { |
|
248 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
249 | + $avatar->remove(); |
|
250 | + return new JSONResponse(); |
|
251 | + } catch (\Exception $e) { |
|
252 | + $this->logger->logException($e, ['app' => 'core']); |
|
253 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @NoAdminRequired |
|
259 | + * |
|
260 | + * @return JSONResponse|DataDisplayResponse |
|
261 | + */ |
|
262 | + public function getTmpAvatar() { |
|
263 | + $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
264 | + if (is_null($tmpAvatar)) { |
|
265 | + return new JSONResponse(['data' => [ |
|
266 | + 'message' => $this->l->t("No temporary profile picture available, try again") |
|
267 | + ]], |
|
268 | + Http::STATUS_NOT_FOUND); |
|
269 | + } |
|
270 | + |
|
271 | + $image = new \OC_Image(); |
|
272 | + $image->loadFromData($tmpAvatar); |
|
273 | + |
|
274 | + $resp = new DataDisplayResponse($image->data(), |
|
275 | + Http::STATUS_OK, |
|
276 | + ['Content-Type' => $image->mimeType()]); |
|
277 | + |
|
278 | + $resp->setETag((string)crc32($image->data())); |
|
279 | + $resp->cacheFor(0); |
|
280 | + $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); |
|
281 | + return $resp; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @NoAdminRequired |
|
286 | + * |
|
287 | + * @param array $crop |
|
288 | + * @return JSONResponse |
|
289 | + */ |
|
290 | + public function postCroppedAvatar($crop) { |
|
291 | + if (is_null($crop)) { |
|
292 | + return new JSONResponse(['data' => ['message' => $this->l->t("No crop data provided")]], |
|
293 | + Http::STATUS_BAD_REQUEST); |
|
294 | + } |
|
295 | + |
|
296 | + if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) { |
|
297 | + return new JSONResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], |
|
298 | + Http::STATUS_BAD_REQUEST); |
|
299 | + } |
|
300 | + |
|
301 | + $tmpAvatar = $this->cache->get('tmpAvatar'); |
|
302 | + if (is_null($tmpAvatar)) { |
|
303 | + return new JSONResponse(['data' => [ |
|
304 | + 'message' => $this->l->t("No temporary profile picture available, try again") |
|
305 | + ]], |
|
306 | + Http::STATUS_BAD_REQUEST); |
|
307 | + } |
|
308 | + |
|
309 | + $image = new \OC_Image(); |
|
310 | + $image->loadFromData($tmpAvatar); |
|
311 | + $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); |
|
312 | + try { |
|
313 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
314 | + $avatar->set($image); |
|
315 | + // Clean up |
|
316 | + $this->cache->remove('tmpAvatar'); |
|
317 | + return new JSONResponse(['status' => 'success']); |
|
318 | + } catch (\OC\NotSquareException $e) { |
|
319 | + return new JSONResponse(['data' => ['message' => $this->l->t('Crop is not square')]], |
|
320 | + Http::STATUS_BAD_REQUEST); |
|
321 | + } catch (\Exception $e) { |
|
322 | + $this->logger->logException($e, ['app' => 'core']); |
|
323 | + return new JSONResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
324 | + } |
|
325 | + } |
|
326 | 326 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $response = new FileDisplayResponse( |
128 | 128 | $avatarFile, |
129 | 129 | Http::STATUS_OK, |
130 | - ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
130 | + ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int) $avatar->isCustomAvatar()] |
|
131 | 131 | ); |
132 | 132 | } catch (\Exception $e) { |
133 | 133 | return new JSONResponse([], Http::STATUS_NOT_FOUND); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | Http::STATUS_OK, |
276 | 276 | ['Content-Type' => $image->mimeType()]); |
277 | 277 | |
278 | - $resp->setETag((string)crc32($image->data())); |
|
278 | + $resp->setETag((string) crc32($image->data())); |
|
279 | 279 | $resp->cacheFor(0); |
280 | 280 | $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT'))); |
281 | 281 | return $resp; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | $image = new \OC_Image(); |
310 | 310 | $image->loadFromData($tmpAvatar); |
311 | - $image->crop($crop['x'], $crop['y'], (int)round($crop['w']), (int)round($crop['h'])); |
|
311 | + $image->crop($crop['x'], $crop['y'], (int) round($crop['w']), (int) round($crop['h'])); |
|
312 | 312 | try { |
313 | 313 | $avatar = $this->avatarManager->getAvatar($this->userId); |
314 | 314 | $avatar->set($image); |
@@ -36,135 +36,135 @@ |
||
36 | 36 | use UnexpectedValueException; |
37 | 37 | |
38 | 38 | class CreateJs extends Command implements CompletionAwareInterface { |
39 | - protected function configure() { |
|
40 | - $this |
|
41 | - ->setName('l10n:createjs') |
|
42 | - ->setDescription('Create javascript translation files for a given app') |
|
43 | - ->addArgument( |
|
44 | - 'app', |
|
45 | - InputOption::VALUE_REQUIRED, |
|
46 | - 'name of the app' |
|
47 | - ) |
|
48 | - ->addArgument( |
|
49 | - 'lang', |
|
50 | - InputOption::VALUE_OPTIONAL, |
|
51 | - 'name of the language' |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
56 | - $app = $input->getArgument('app'); |
|
57 | - $lang = $input->getArgument('lang'); |
|
58 | - |
|
59 | - $path = \OC_App::getAppPath($app); |
|
60 | - if ($path === false) { |
|
61 | - $output->writeln("The app <$app> is unknown."); |
|
62 | - return 1; |
|
63 | - } |
|
64 | - $languages = $lang; |
|
65 | - if (empty($lang)) { |
|
66 | - $languages = $this->getAllLanguages($path); |
|
67 | - } |
|
68 | - |
|
69 | - foreach ($languages as $lang) { |
|
70 | - $this->writeFiles($app, $path, $lang, $output); |
|
71 | - } |
|
72 | - return 0; |
|
73 | - } |
|
74 | - |
|
75 | - private function getAllLanguages($path) { |
|
76 | - $result = []; |
|
77 | - foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
78 | - if ($fileInfo->isDot()) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - if ($fileInfo->isDir()) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - if ($fileInfo->getExtension() !== 'php') { |
|
85 | - continue; |
|
86 | - } |
|
87 | - $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
88 | - } |
|
89 | - |
|
90 | - return $result; |
|
91 | - } |
|
92 | - |
|
93 | - private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
94 | - list($translations, $plurals) = $this->loadTranslations($path, $lang); |
|
95 | - $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
96 | - $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
97 | - } |
|
98 | - |
|
99 | - private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
100 | - $jsFile = "$path/l10n/$lang.js"; |
|
101 | - if (file_exists($jsFile)) { |
|
102 | - $output->writeln("File already exists: $jsFile"); |
|
103 | - return; |
|
104 | - } |
|
105 | - $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
106 | - $jsTrans = []; |
|
107 | - foreach ($translations as $id => $val) { |
|
108 | - if (is_array($val)) { |
|
109 | - $val = '[ ' . implode(',', $val) . ']'; |
|
110 | - } |
|
111 | - $jsTrans[] = "\"$id\" : \"$val\""; |
|
112 | - } |
|
113 | - $content .= implode(",\n ", $jsTrans); |
|
114 | - $content .= "\n},\n\"$plurals\");\n"; |
|
115 | - |
|
116 | - file_put_contents($jsFile, $content); |
|
117 | - $output->writeln("Javascript translation file generated: $jsFile"); |
|
118 | - } |
|
119 | - |
|
120 | - private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
121 | - $jsFile = "$path/l10n/$lang.json"; |
|
122 | - if (file_exists($jsFile)) { |
|
123 | - $output->writeln("File already exists: $jsFile"); |
|
124 | - return; |
|
125 | - } |
|
126 | - $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
127 | - file_put_contents($jsFile, json_encode($content)); |
|
128 | - $output->writeln("Json translation file generated: $jsFile"); |
|
129 | - } |
|
130 | - |
|
131 | - private function loadTranslations($path, $lang) { |
|
132 | - $phpFile = "$path/l10n/$lang.php"; |
|
133 | - $TRANSLATIONS = []; |
|
134 | - $PLURAL_FORMS = ''; |
|
135 | - if (!file_exists($phpFile)) { |
|
136 | - throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
137 | - } |
|
138 | - require $phpFile; |
|
139 | - |
|
140 | - return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Return possible values for the named option |
|
145 | - * |
|
146 | - * @param string $optionName |
|
147 | - * @param CompletionContext $context |
|
148 | - * @return string[] |
|
149 | - */ |
|
150 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
151 | - return []; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Return possible values for the named argument |
|
156 | - * |
|
157 | - * @param string $argumentName |
|
158 | - * @param CompletionContext $context |
|
159 | - * @return string[] |
|
160 | - */ |
|
161 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
162 | - if ($argumentName === 'app') { |
|
163 | - return \OC_App::getAllApps(); |
|
164 | - } elseif ($argumentName === 'lang') { |
|
165 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
166 | - return $this->getAllLanguages(\OC_App::getAppPath($appName)); |
|
167 | - } |
|
168 | - return []; |
|
169 | - } |
|
39 | + protected function configure() { |
|
40 | + $this |
|
41 | + ->setName('l10n:createjs') |
|
42 | + ->setDescription('Create javascript translation files for a given app') |
|
43 | + ->addArgument( |
|
44 | + 'app', |
|
45 | + InputOption::VALUE_REQUIRED, |
|
46 | + 'name of the app' |
|
47 | + ) |
|
48 | + ->addArgument( |
|
49 | + 'lang', |
|
50 | + InputOption::VALUE_OPTIONAL, |
|
51 | + 'name of the language' |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
56 | + $app = $input->getArgument('app'); |
|
57 | + $lang = $input->getArgument('lang'); |
|
58 | + |
|
59 | + $path = \OC_App::getAppPath($app); |
|
60 | + if ($path === false) { |
|
61 | + $output->writeln("The app <$app> is unknown."); |
|
62 | + return 1; |
|
63 | + } |
|
64 | + $languages = $lang; |
|
65 | + if (empty($lang)) { |
|
66 | + $languages = $this->getAllLanguages($path); |
|
67 | + } |
|
68 | + |
|
69 | + foreach ($languages as $lang) { |
|
70 | + $this->writeFiles($app, $path, $lang, $output); |
|
71 | + } |
|
72 | + return 0; |
|
73 | + } |
|
74 | + |
|
75 | + private function getAllLanguages($path) { |
|
76 | + $result = []; |
|
77 | + foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
78 | + if ($fileInfo->isDot()) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + if ($fileInfo->isDir()) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + if ($fileInfo->getExtension() !== 'php') { |
|
85 | + continue; |
|
86 | + } |
|
87 | + $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
88 | + } |
|
89 | + |
|
90 | + return $result; |
|
91 | + } |
|
92 | + |
|
93 | + private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
94 | + list($translations, $plurals) = $this->loadTranslations($path, $lang); |
|
95 | + $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
96 | + $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
97 | + } |
|
98 | + |
|
99 | + private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
100 | + $jsFile = "$path/l10n/$lang.js"; |
|
101 | + if (file_exists($jsFile)) { |
|
102 | + $output->writeln("File already exists: $jsFile"); |
|
103 | + return; |
|
104 | + } |
|
105 | + $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
106 | + $jsTrans = []; |
|
107 | + foreach ($translations as $id => $val) { |
|
108 | + if (is_array($val)) { |
|
109 | + $val = '[ ' . implode(',', $val) . ']'; |
|
110 | + } |
|
111 | + $jsTrans[] = "\"$id\" : \"$val\""; |
|
112 | + } |
|
113 | + $content .= implode(",\n ", $jsTrans); |
|
114 | + $content .= "\n},\n\"$plurals\");\n"; |
|
115 | + |
|
116 | + file_put_contents($jsFile, $content); |
|
117 | + $output->writeln("Javascript translation file generated: $jsFile"); |
|
118 | + } |
|
119 | + |
|
120 | + private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
121 | + $jsFile = "$path/l10n/$lang.json"; |
|
122 | + if (file_exists($jsFile)) { |
|
123 | + $output->writeln("File already exists: $jsFile"); |
|
124 | + return; |
|
125 | + } |
|
126 | + $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
127 | + file_put_contents($jsFile, json_encode($content)); |
|
128 | + $output->writeln("Json translation file generated: $jsFile"); |
|
129 | + } |
|
130 | + |
|
131 | + private function loadTranslations($path, $lang) { |
|
132 | + $phpFile = "$path/l10n/$lang.php"; |
|
133 | + $TRANSLATIONS = []; |
|
134 | + $PLURAL_FORMS = ''; |
|
135 | + if (!file_exists($phpFile)) { |
|
136 | + throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
137 | + } |
|
138 | + require $phpFile; |
|
139 | + |
|
140 | + return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Return possible values for the named option |
|
145 | + * |
|
146 | + * @param string $optionName |
|
147 | + * @param CompletionContext $context |
|
148 | + * @return string[] |
|
149 | + */ |
|
150 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
151 | + return []; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Return possible values for the named argument |
|
156 | + * |
|
157 | + * @param string $argumentName |
|
158 | + * @param CompletionContext $context |
|
159 | + * @return string[] |
|
160 | + */ |
|
161 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
162 | + if ($argumentName === 'app') { |
|
163 | + return \OC_App::getAllApps(); |
|
164 | + } elseif ($argumentName === 'lang') { |
|
165 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
166 | + return $this->getAllLanguages(\OC_App::getAppPath($appName)); |
|
167 | + } |
|
168 | + return []; |
|
169 | + } |
|
170 | 170 | } |
@@ -106,7 +106,7 @@ |
||
106 | 106 | $jsTrans = []; |
107 | 107 | foreach ($translations as $id => $val) { |
108 | 108 | if (is_array($val)) { |
109 | - $val = '[ ' . implode(',', $val) . ']'; |
|
109 | + $val = '[ '.implode(',', $val).']'; |
|
110 | 110 | } |
111 | 111 | $jsTrans[] = "\"$id\" : \"$val\""; |
112 | 112 | } |
@@ -44,167 +44,167 @@ |
||
44 | 44 | use Symfony\Component\Console\Output\OutputInterface; |
45 | 45 | |
46 | 46 | class CheckCode extends Command implements CompletionAwareInterface { |
47 | - protected $checkers = [ |
|
48 | - 'private' => PrivateCheck::class, |
|
49 | - 'deprecation' => DeprecationCheck::class, |
|
50 | - 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | - ]; |
|
52 | - |
|
53 | - protected function configure() { |
|
54 | - $this |
|
55 | - ->setName('app:check-code') |
|
56 | - ->setDescription('check code to be compliant') |
|
57 | - ->addArgument( |
|
58 | - 'app-id', |
|
59 | - InputArgument::REQUIRED, |
|
60 | - 'check the specified app' |
|
61 | - ) |
|
62 | - ->addOption( |
|
63 | - 'checker', |
|
64 | - 'c', |
|
65 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | - 'enable the specified checker(s)', |
|
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | - ) |
|
69 | - ->addOption( |
|
70 | - '--skip-checkers', |
|
71 | - null, |
|
72 | - InputOption::VALUE_NONE, |
|
73 | - 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | - ) |
|
75 | - ->addOption( |
|
76 | - '--skip-validate-info', |
|
77 | - null, |
|
78 | - InputOption::VALUE_NONE, |
|
79 | - 'skips the info.xml/version check' |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | - $appId = $input->getArgument('app-id'); |
|
85 | - |
|
86 | - $checkList = new EmptyCheck(); |
|
87 | - foreach ($input->getOption('checker') as $checker) { |
|
88 | - if (!isset($this->checkers[$checker])) { |
|
89 | - throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | - } |
|
91 | - $checkerClass = $this->checkers[$checker]; |
|
92 | - $checkList = new $checkerClass($checkList); |
|
93 | - } |
|
94 | - |
|
95 | - $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | - |
|
97 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | - if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | - $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | - } |
|
101 | - }); |
|
102 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | - $count = count($errors); |
|
104 | - |
|
105 | - // show filename if the verbosity is low, but there are errors in a file |
|
106 | - if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | - $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | - } |
|
109 | - |
|
110 | - // show error count if there are errors present or the verbosity is high |
|
111 | - if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | - $output->writeln(" {$count} errors"); |
|
113 | - } |
|
114 | - usort($errors, function ($a, $b) { |
|
115 | - return $a['line'] > $b['line']; |
|
116 | - }); |
|
117 | - |
|
118 | - foreach ($errors as $p) { |
|
119 | - $line = sprintf("%' 4d", $p['line']); |
|
120 | - $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | - } |
|
122 | - }); |
|
123 | - $errors = []; |
|
124 | - if (!$input->getOption('skip-checkers')) { |
|
125 | - $errors = $codeChecker->analyse($appId); |
|
126 | - } |
|
127 | - |
|
128 | - if (!$input->getOption('skip-validate-info')) { |
|
129 | - $infoChecker = new InfoChecker(); |
|
130 | - $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | - $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | - }); |
|
133 | - |
|
134 | - $infoErrors = $infoChecker->analyse($appId); |
|
135 | - |
|
136 | - $errors = array_merge($errors, $infoErrors); |
|
137 | - |
|
138 | - $languageParser = new LanguageParseChecker(); |
|
139 | - $languageErrors = $languageParser->analyse($appId); |
|
140 | - |
|
141 | - foreach ($languageErrors as $languageError) { |
|
142 | - $output->writeln("<error>$languageError</error>"); |
|
143 | - } |
|
144 | - |
|
145 | - $errors = array_merge($errors, $languageErrors); |
|
146 | - |
|
147 | - $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | - $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | - |
|
150 | - foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | - $output->writeln("<error>$schemaError</error>"); |
|
152 | - } |
|
153 | - foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | - $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | - } |
|
156 | - |
|
157 | - $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | - } |
|
159 | - |
|
160 | - $this->analyseUpdateFile($appId, $output); |
|
161 | - |
|
162 | - if (empty($errors)) { |
|
163 | - $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | - return 0; |
|
165 | - } else { |
|
166 | - $output->writeln('<error>App is not compliant</error>'); |
|
167 | - return 101; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $appId |
|
173 | - * @param $output |
|
174 | - */ |
|
175 | - private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | - $appPath = \OC_App::getAppPath($appId); |
|
177 | - if ($appPath === false) { |
|
178 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | - } |
|
180 | - |
|
181 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | - if (file_exists($updatePhp)) { |
|
183 | - $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $optionName |
|
189 | - * @param CompletionContext $context |
|
190 | - * @return string[] |
|
191 | - */ |
|
192 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | - if ($optionName === 'checker') { |
|
194 | - return ['private', 'deprecation', 'strong-comparison']; |
|
195 | - } |
|
196 | - return []; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $argumentName |
|
201 | - * @param CompletionContext $context |
|
202 | - * @return string[] |
|
203 | - */ |
|
204 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | - if ($argumentName === 'app-id') { |
|
206 | - return \OC_App::getAllApps(); |
|
207 | - } |
|
208 | - return []; |
|
209 | - } |
|
47 | + protected $checkers = [ |
|
48 | + 'private' => PrivateCheck::class, |
|
49 | + 'deprecation' => DeprecationCheck::class, |
|
50 | + 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | + ]; |
|
52 | + |
|
53 | + protected function configure() { |
|
54 | + $this |
|
55 | + ->setName('app:check-code') |
|
56 | + ->setDescription('check code to be compliant') |
|
57 | + ->addArgument( |
|
58 | + 'app-id', |
|
59 | + InputArgument::REQUIRED, |
|
60 | + 'check the specified app' |
|
61 | + ) |
|
62 | + ->addOption( |
|
63 | + 'checker', |
|
64 | + 'c', |
|
65 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | + 'enable the specified checker(s)', |
|
67 | + [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | + ) |
|
69 | + ->addOption( |
|
70 | + '--skip-checkers', |
|
71 | + null, |
|
72 | + InputOption::VALUE_NONE, |
|
73 | + 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | + ) |
|
75 | + ->addOption( |
|
76 | + '--skip-validate-info', |
|
77 | + null, |
|
78 | + InputOption::VALUE_NONE, |
|
79 | + 'skips the info.xml/version check' |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
84 | + $appId = $input->getArgument('app-id'); |
|
85 | + |
|
86 | + $checkList = new EmptyCheck(); |
|
87 | + foreach ($input->getOption('checker') as $checker) { |
|
88 | + if (!isset($this->checkers[$checker])) { |
|
89 | + throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | + } |
|
91 | + $checkerClass = $this->checkers[$checker]; |
|
92 | + $checkList = new $checkerClass($checkList); |
|
93 | + } |
|
94 | + |
|
95 | + $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | + |
|
97 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | + if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | + $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | + } |
|
101 | + }); |
|
102 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | + $count = count($errors); |
|
104 | + |
|
105 | + // show filename if the verbosity is low, but there are errors in a file |
|
106 | + if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | + $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | + } |
|
109 | + |
|
110 | + // show error count if there are errors present or the verbosity is high |
|
111 | + if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | + $output->writeln(" {$count} errors"); |
|
113 | + } |
|
114 | + usort($errors, function ($a, $b) { |
|
115 | + return $a['line'] > $b['line']; |
|
116 | + }); |
|
117 | + |
|
118 | + foreach ($errors as $p) { |
|
119 | + $line = sprintf("%' 4d", $p['line']); |
|
120 | + $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | + } |
|
122 | + }); |
|
123 | + $errors = []; |
|
124 | + if (!$input->getOption('skip-checkers')) { |
|
125 | + $errors = $codeChecker->analyse($appId); |
|
126 | + } |
|
127 | + |
|
128 | + if (!$input->getOption('skip-validate-info')) { |
|
129 | + $infoChecker = new InfoChecker(); |
|
130 | + $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | + $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | + }); |
|
133 | + |
|
134 | + $infoErrors = $infoChecker->analyse($appId); |
|
135 | + |
|
136 | + $errors = array_merge($errors, $infoErrors); |
|
137 | + |
|
138 | + $languageParser = new LanguageParseChecker(); |
|
139 | + $languageErrors = $languageParser->analyse($appId); |
|
140 | + |
|
141 | + foreach ($languageErrors as $languageError) { |
|
142 | + $output->writeln("<error>$languageError</error>"); |
|
143 | + } |
|
144 | + |
|
145 | + $errors = array_merge($errors, $languageErrors); |
|
146 | + |
|
147 | + $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | + $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | + |
|
150 | + foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | + $output->writeln("<error>$schemaError</error>"); |
|
152 | + } |
|
153 | + foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | + $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | + } |
|
156 | + |
|
157 | + $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | + } |
|
159 | + |
|
160 | + $this->analyseUpdateFile($appId, $output); |
|
161 | + |
|
162 | + if (empty($errors)) { |
|
163 | + $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | + return 0; |
|
165 | + } else { |
|
166 | + $output->writeln('<error>App is not compliant</error>'); |
|
167 | + return 101; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $appId |
|
173 | + * @param $output |
|
174 | + */ |
|
175 | + private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | + $appPath = \OC_App::getAppPath($appId); |
|
177 | + if ($appPath === false) { |
|
178 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | + } |
|
180 | + |
|
181 | + $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | + if (file_exists($updatePhp)) { |
|
183 | + $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $optionName |
|
189 | + * @param CompletionContext $context |
|
190 | + * @return string[] |
|
191 | + */ |
|
192 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | + if ($optionName === 'checker') { |
|
194 | + return ['private', 'deprecation', 'strong-comparison']; |
|
195 | + } |
|
196 | + return []; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $argumentName |
|
201 | + * @param CompletionContext $context |
|
202 | + * @return string[] |
|
203 | + */ |
|
204 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | + if ($argumentName === 'app-id') { |
|
206 | + return \OC_App::getAllApps(); |
|
207 | + } |
|
208 | + return []; |
|
209 | + } |
|
210 | 210 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | 'c', |
65 | 65 | InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
66 | 66 | 'enable the specified checker(s)', |
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
67 | + ['private', 'deprecation', 'strong-comparison'] |
|
68 | 68 | ) |
69 | 69 | ->addOption( |
70 | 70 | '--skip-checkers', |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | |
95 | 95 | $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
96 | 96 | |
97 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
97 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
|
98 | 98 | if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
99 | 99 | $output->writeln("<info>Analysing {$params}</info>"); |
100 | 100 | } |
101 | 101 | }); |
102 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
102 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { |
|
103 | 103 | $count = count($errors); |
104 | 104 | |
105 | 105 | // show filename if the verbosity is low, but there are errors in a file |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
112 | 112 | $output->writeln(" {$count} errors"); |
113 | 113 | } |
114 | - usort($errors, function ($a, $b) { |
|
114 | + usort($errors, function($a, $b) { |
|
115 | 115 | return $a['line'] > $b['line']; |
116 | 116 | }); |
117 | 117 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | if (!$input->getOption('skip-validate-info')) { |
129 | 129 | $infoChecker = new InfoChecker(); |
130 | - $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
130 | + $infoChecker->listen('InfoChecker', 'parseError', function($error) use ($output) { |
|
131 | 131 | $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
132 | 132 | }); |
133 | 133 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | throw new \RuntimeException("No app with given id <$appId> known."); |
179 | 179 | } |
180 | 180 | |
181 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
181 | + $updatePhp = $appPath.'/appinfo/update.php'; |
|
182 | 182 | if (file_exists($updatePhp)) { |
183 | 183 | $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
184 | 184 | } |
@@ -37,35 +37,35 @@ |
||
37 | 37 | * @package OC\Core\Command\Integrity |
38 | 38 | */ |
39 | 39 | class CheckCore extends Base { |
40 | - /** |
|
41 | - * @var Checker |
|
42 | - */ |
|
43 | - private $checker; |
|
40 | + /** |
|
41 | + * @var Checker |
|
42 | + */ |
|
43 | + private $checker; |
|
44 | 44 | |
45 | - public function __construct(Checker $checker) { |
|
46 | - parent::__construct(); |
|
47 | - $this->checker = $checker; |
|
48 | - } |
|
45 | + public function __construct(Checker $checker) { |
|
46 | + parent::__construct(); |
|
47 | + $this->checker = $checker; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritdoc } |
|
52 | - */ |
|
53 | - protected function configure() { |
|
54 | - parent::configure(); |
|
55 | - $this |
|
56 | - ->setName('integrity:check-core') |
|
57 | - ->setDescription('Check integrity of core code using a signature.'); |
|
58 | - } |
|
50 | + /** |
|
51 | + * {@inheritdoc } |
|
52 | + */ |
|
53 | + protected function configure() { |
|
54 | + parent::configure(); |
|
55 | + $this |
|
56 | + ->setName('integrity:check-core') |
|
57 | + ->setDescription('Check integrity of core code using a signature.'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc } |
|
62 | - */ |
|
63 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | - $result = $this->checker->verifyCoreSignature(); |
|
65 | - $this->writeArrayInOutputFormat($input, $output, $result); |
|
66 | - if (count($result) > 0) { |
|
67 | - return 1; |
|
68 | - } |
|
69 | - return 0; |
|
70 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc } |
|
62 | + */ |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | + $result = $this->checker->verifyCoreSignature(); |
|
65 | + $this->writeArrayInOutputFormat($input, $output, $result); |
|
66 | + if (count($result) > 0) { |
|
67 | + return 1; |
|
68 | + } |
|
69 | + return 0; |
|
70 | + } |
|
71 | 71 | } |