@@ -1047,6 +1047,11 @@ |
||
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | |
1050 | + /** |
|
1051 | + * @param string $lang |
|
1052 | + * |
|
1053 | + * @return string |
|
1054 | + */ |
|
1050 | 1055 | protected static function findBestL10NOption($options, $lang) { |
1051 | 1056 | $fallback = $similarLangFallback = $englishFallback = false; |
1052 | 1057 |
@@ -62,1078 +62,1078 @@ |
||
62 | 62 | * upgrading and removing apps. |
63 | 63 | */ |
64 | 64 | class OC_App { |
65 | - static private $adminForms = array(); |
|
66 | - static private $personalForms = array(); |
|
67 | - static private $appTypes = array(); |
|
68 | - static private $loadedApps = array(); |
|
69 | - static private $altLogin = array(); |
|
70 | - static private $alreadyRegistered = []; |
|
71 | - const officialApp = 200; |
|
72 | - |
|
73 | - /** |
|
74 | - * clean the appId |
|
75 | - * |
|
76 | - * @param string|boolean $app AppId that needs to be cleaned |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function cleanAppId($app) { |
|
80 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Check if an app is loaded |
|
85 | - * |
|
86 | - * @param string $app |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public static function isAppLoaded($app) { |
|
90 | - return in_array($app, self::$loadedApps, true); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * loads all apps |
|
95 | - * |
|
96 | - * @param string[] | string | null $types |
|
97 | - * @return bool |
|
98 | - * |
|
99 | - * This function walks through the ownCloud directory and loads all apps |
|
100 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
101 | - * exists. |
|
102 | - * |
|
103 | - * if $types is set, only apps of those types will be loaded |
|
104 | - */ |
|
105 | - public static function loadApps($types = null) { |
|
106 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
107 | - return false; |
|
108 | - } |
|
109 | - // Load the enabled apps here |
|
110 | - $apps = self::getEnabledApps(); |
|
111 | - |
|
112 | - // Add each apps' folder as allowed class path |
|
113 | - foreach($apps as $app) { |
|
114 | - $path = self::getAppPath($app); |
|
115 | - if($path !== false) { |
|
116 | - self::registerAutoloading($app, $path); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - // prevent app.php from printing output |
|
121 | - ob_start(); |
|
122 | - foreach ($apps as $app) { |
|
123 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
124 | - self::loadApp($app); |
|
125 | - } |
|
126 | - } |
|
127 | - ob_end_clean(); |
|
128 | - |
|
129 | - return true; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * load a single app |
|
134 | - * |
|
135 | - * @param string $app |
|
136 | - */ |
|
137 | - public static function loadApp($app) { |
|
138 | - self::$loadedApps[] = $app; |
|
139 | - $appPath = self::getAppPath($app); |
|
140 | - if($appPath === false) { |
|
141 | - return; |
|
142 | - } |
|
143 | - |
|
144 | - // in case someone calls loadApp() directly |
|
145 | - self::registerAutoloading($app, $appPath); |
|
146 | - |
|
147 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
148 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
149 | - self::requireAppFile($app); |
|
150 | - if (self::isType($app, array('authentication'))) { |
|
151 | - // since authentication apps affect the "is app enabled for group" check, |
|
152 | - // the enabled apps cache needs to be cleared to make sure that the |
|
153 | - // next time getEnableApps() is called it will also include apps that were |
|
154 | - // enabled for groups |
|
155 | - self::$enabledAppsCache = array(); |
|
156 | - } |
|
157 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
158 | - } |
|
159 | - |
|
160 | - $info = self::getAppInfo($app); |
|
161 | - if (!empty($info['activity']['filters'])) { |
|
162 | - foreach ($info['activity']['filters'] as $filter) { |
|
163 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
164 | - } |
|
165 | - } |
|
166 | - if (!empty($info['activity']['settings'])) { |
|
167 | - foreach ($info['activity']['settings'] as $setting) { |
|
168 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
169 | - } |
|
170 | - } |
|
171 | - if (!empty($info['activity']['providers'])) { |
|
172 | - foreach ($info['activity']['providers'] as $provider) { |
|
173 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
174 | - } |
|
175 | - } |
|
176 | - if (!empty($info['collaboration']['plugins'])) { |
|
177 | - // deal with one or many plugin entries |
|
178 | - $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
179 | - [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
180 | - foreach ($plugins as $plugin) { |
|
181 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
182 | - $pluginInfo = [ |
|
183 | - 'shareType' => $plugin['@attributes']['share-type'], |
|
184 | - 'class' => $plugin['@value'], |
|
185 | - ]; |
|
186 | - \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
187 | - } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
188 | - \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @internal |
|
196 | - * @param string $app |
|
197 | - * @param string $path |
|
198 | - */ |
|
199 | - public static function registerAutoloading($app, $path) { |
|
200 | - $key = $app . '-' . $path; |
|
201 | - if(isset(self::$alreadyRegistered[$key])) { |
|
202 | - return; |
|
203 | - } |
|
204 | - |
|
205 | - self::$alreadyRegistered[$key] = true; |
|
206 | - |
|
207 | - // Register on PSR-4 composer autoloader |
|
208 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
209 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
210 | - |
|
211 | - if (file_exists($path . '/composer/autoload.php')) { |
|
212 | - require_once $path . '/composer/autoload.php'; |
|
213 | - } else { |
|
214 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
215 | - // Register on legacy autoloader |
|
216 | - \OC::$loader->addValidRoot($path); |
|
217 | - } |
|
218 | - |
|
219 | - // Register Test namespace only when testing |
|
220 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
221 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Load app.php from the given app |
|
227 | - * |
|
228 | - * @param string $app app name |
|
229 | - */ |
|
230 | - private static function requireAppFile($app) { |
|
231 | - try { |
|
232 | - // encapsulated here to avoid variable scope conflicts |
|
233 | - require_once $app . '/appinfo/app.php'; |
|
234 | - } catch (Error $ex) { |
|
235 | - \OC::$server->getLogger()->logException($ex); |
|
236 | - if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
237 | - // Only disable apps which are not shipped |
|
238 | - self::disable($app); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * check if an app is of a specific type |
|
245 | - * |
|
246 | - * @param string $app |
|
247 | - * @param string|array $types |
|
248 | - * @return bool |
|
249 | - */ |
|
250 | - public static function isType($app, $types) { |
|
251 | - if (is_string($types)) { |
|
252 | - $types = array($types); |
|
253 | - } |
|
254 | - $appTypes = self::getAppTypes($app); |
|
255 | - foreach ($types as $type) { |
|
256 | - if (array_search($type, $appTypes) !== false) { |
|
257 | - return true; |
|
258 | - } |
|
259 | - } |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * get the types of an app |
|
265 | - * |
|
266 | - * @param string $app |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - private static function getAppTypes($app) { |
|
270 | - //load the cache |
|
271 | - if (count(self::$appTypes) == 0) { |
|
272 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
273 | - } |
|
274 | - |
|
275 | - if (isset(self::$appTypes[$app])) { |
|
276 | - return explode(',', self::$appTypes[$app]); |
|
277 | - } else { |
|
278 | - return array(); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * read app types from info.xml and cache them in the database |
|
284 | - */ |
|
285 | - public static function setAppTypes($app) { |
|
286 | - $appData = self::getAppInfo($app); |
|
287 | - if(!is_array($appData)) { |
|
288 | - return; |
|
289 | - } |
|
290 | - |
|
291 | - if (isset($appData['types'])) { |
|
292 | - $appTypes = implode(',', $appData['types']); |
|
293 | - } else { |
|
294 | - $appTypes = ''; |
|
295 | - $appData['types'] = []; |
|
296 | - } |
|
297 | - |
|
298 | - \OC::$server->getConfig()->setAppValue($app, 'types', $appTypes); |
|
299 | - |
|
300 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
301 | - $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes'); |
|
302 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
303 | - \OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes'); |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * get all enabled apps |
|
310 | - */ |
|
311 | - protected static $enabledAppsCache = array(); |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns apps enabled for the current user. |
|
315 | - * |
|
316 | - * @param bool $forceRefresh whether to refresh the cache |
|
317 | - * @param bool $all whether to return apps for all users, not only the |
|
318 | - * currently logged in one |
|
319 | - * @return string[] |
|
320 | - */ |
|
321 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
322 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
323 | - return array(); |
|
324 | - } |
|
325 | - // in incognito mode or when logged out, $user will be false, |
|
326 | - // which is also the case during an upgrade |
|
327 | - $appManager = \OC::$server->getAppManager(); |
|
328 | - if ($all) { |
|
329 | - $user = null; |
|
330 | - } else { |
|
331 | - $user = \OC::$server->getUserSession()->getUser(); |
|
332 | - } |
|
333 | - |
|
334 | - if (is_null($user)) { |
|
335 | - $apps = $appManager->getInstalledApps(); |
|
336 | - } else { |
|
337 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
338 | - } |
|
339 | - $apps = array_filter($apps, function ($app) { |
|
340 | - return $app !== 'files';//we add this manually |
|
341 | - }); |
|
342 | - sort($apps); |
|
343 | - array_unshift($apps, 'files'); |
|
344 | - return $apps; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * checks whether or not an app is enabled |
|
349 | - * |
|
350 | - * @param string $app app |
|
351 | - * @return bool |
|
352 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
353 | - * |
|
354 | - * This function checks whether or not an app is enabled. |
|
355 | - */ |
|
356 | - public static function isEnabled($app) { |
|
357 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * enables an app |
|
362 | - * |
|
363 | - * @param string $appId |
|
364 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
365 | - * @throws \Exception |
|
366 | - * @return void |
|
367 | - * |
|
368 | - * This function set an app as enabled in appconfig. |
|
369 | - */ |
|
370 | - public function enable($appId, |
|
371 | - $groups = null) { |
|
372 | - self::$enabledAppsCache = []; // flush |
|
373 | - |
|
374 | - // Check if app is already downloaded |
|
375 | - $installer = \OC::$server->query(Installer::class); |
|
376 | - $isDownloaded = $installer->isDownloaded($appId); |
|
377 | - |
|
378 | - if(!$isDownloaded) { |
|
379 | - $installer->downloadApp($appId); |
|
380 | - } |
|
381 | - |
|
382 | - $installer->installApp($appId); |
|
383 | - |
|
384 | - $appManager = \OC::$server->getAppManager(); |
|
385 | - if (!is_null($groups)) { |
|
386 | - $groupManager = \OC::$server->getGroupManager(); |
|
387 | - $groupsList = []; |
|
388 | - foreach ($groups as $group) { |
|
389 | - $groupItem = $groupManager->get($group); |
|
390 | - if ($groupItem instanceof \OCP\IGroup) { |
|
391 | - $groupsList[] = $groupManager->get($group); |
|
392 | - } |
|
393 | - } |
|
394 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
395 | - } else { |
|
396 | - $appManager->enableApp($appId); |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * This function set an app as disabled in appconfig. |
|
402 | - * |
|
403 | - * @param string $app app |
|
404 | - * @throws Exception |
|
405 | - */ |
|
406 | - public static function disable($app) { |
|
407 | - // flush |
|
408 | - self::$enabledAppsCache = array(); |
|
409 | - |
|
410 | - // run uninstall steps |
|
411 | - $appData = OC_App::getAppInfo($app); |
|
412 | - if (!is_null($appData)) { |
|
413 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
414 | - } |
|
415 | - |
|
416 | - // emit disable hook - needed anymore ? |
|
417 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
418 | - |
|
419 | - // finally disable it |
|
420 | - $appManager = \OC::$server->getAppManager(); |
|
421 | - $appManager->disableApp($app); |
|
422 | - } |
|
423 | - |
|
424 | - // This is private as well. It simply works, so don't ask for more details |
|
425 | - private static function proceedNavigation($list) { |
|
426 | - usort($list, function($a, $b) { |
|
427 | - if (isset($a['order']) && isset($b['order'])) { |
|
428 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
429 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
430 | - return isset($a['order']) ? -1 : 1; |
|
431 | - } else { |
|
432 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
433 | - } |
|
434 | - }); |
|
435 | - |
|
436 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
437 | - foreach ($list as $index => &$navEntry) { |
|
438 | - if ($navEntry['id'] == $activeApp) { |
|
439 | - $navEntry['active'] = true; |
|
440 | - } else { |
|
441 | - $navEntry['active'] = false; |
|
442 | - } |
|
443 | - } |
|
444 | - unset($navEntry); |
|
445 | - |
|
446 | - return $list; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Get the path where to install apps |
|
451 | - * |
|
452 | - * @return string|false |
|
453 | - */ |
|
454 | - public static function getInstallPath() { |
|
455 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
456 | - return false; |
|
457 | - } |
|
458 | - |
|
459 | - foreach (OC::$APPSROOTS as $dir) { |
|
460 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
461 | - return $dir['path']; |
|
462 | - } |
|
463 | - } |
|
464 | - |
|
465 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
466 | - return null; |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * search for an app in all app-directories |
|
472 | - * |
|
473 | - * @param string $appId |
|
474 | - * @return false|string |
|
475 | - */ |
|
476 | - public static function findAppInDirectories($appId) { |
|
477 | - $sanitizedAppId = self::cleanAppId($appId); |
|
478 | - if($sanitizedAppId !== $appId) { |
|
479 | - return false; |
|
480 | - } |
|
481 | - static $app_dir = array(); |
|
482 | - |
|
483 | - if (isset($app_dir[$appId])) { |
|
484 | - return $app_dir[$appId]; |
|
485 | - } |
|
486 | - |
|
487 | - $possibleApps = array(); |
|
488 | - foreach (OC::$APPSROOTS as $dir) { |
|
489 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
490 | - $possibleApps[] = $dir; |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - if (empty($possibleApps)) { |
|
495 | - return false; |
|
496 | - } elseif (count($possibleApps) === 1) { |
|
497 | - $dir = array_shift($possibleApps); |
|
498 | - $app_dir[$appId] = $dir; |
|
499 | - return $dir; |
|
500 | - } else { |
|
501 | - $versionToLoad = array(); |
|
502 | - foreach ($possibleApps as $possibleApp) { |
|
503 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
504 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
505 | - $versionToLoad = array( |
|
506 | - 'dir' => $possibleApp, |
|
507 | - 'version' => $version, |
|
508 | - ); |
|
509 | - } |
|
510 | - } |
|
511 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
512 | - return $versionToLoad['dir']; |
|
513 | - //TODO - write test |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Get the directory for the given app. |
|
519 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
520 | - * |
|
521 | - * @param string $appId |
|
522 | - * @return string|false |
|
523 | - */ |
|
524 | - public static function getAppPath($appId) { |
|
525 | - if ($appId === null || trim($appId) === '') { |
|
526 | - return false; |
|
527 | - } |
|
528 | - |
|
529 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
530 | - return $dir['path'] . '/' . $appId; |
|
531 | - } |
|
532 | - return false; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Get the path for the given app on the access |
|
537 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
538 | - * |
|
539 | - * @param string $appId |
|
540 | - * @return string|false |
|
541 | - */ |
|
542 | - public static function getAppWebPath($appId) { |
|
543 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
544 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
545 | - } |
|
546 | - return false; |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * get the last version of the app from appinfo/info.xml |
|
551 | - * |
|
552 | - * @param string $appId |
|
553 | - * @param bool $useCache |
|
554 | - * @return string |
|
555 | - * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion() |
|
556 | - */ |
|
557 | - public static function getAppVersion($appId, $useCache = true) { |
|
558 | - return \OC::$server->getAppManager()->getAppVersion($appId, $useCache); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * get app's version based on it's path |
|
563 | - * |
|
564 | - * @param string $path |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - public static function getAppVersionByPath($path) { |
|
568 | - $infoFile = $path . '/appinfo/info.xml'; |
|
569 | - $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
|
570 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
571 | - } |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * Read all app metadata from the info.xml file |
|
576 | - * |
|
577 | - * @param string $appId id of the app or the path of the info.xml file |
|
578 | - * @param bool $path |
|
579 | - * @param string $lang |
|
580 | - * @return array|null |
|
581 | - * @note all data is read from info.xml, not just pre-defined fields |
|
582 | - * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo() |
|
583 | - */ |
|
584 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
585 | - return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns the navigation |
|
590 | - * |
|
591 | - * @return array |
|
592 | - * |
|
593 | - * This function returns an array containing all entries added. The |
|
594 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
595 | - * given for each app the following keys exist: |
|
596 | - * - active: boolean, signals if the user is on this navigation entry |
|
597 | - */ |
|
598 | - public static function getNavigation() { |
|
599 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
600 | - return self::proceedNavigation($entries); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Returns the Settings Navigation |
|
605 | - * |
|
606 | - * @return string[] |
|
607 | - * |
|
608 | - * This function returns an array containing all settings pages added. The |
|
609 | - * entries are sorted by the key 'order' ascending. |
|
610 | - */ |
|
611 | - public static function getSettingsNavigation() { |
|
612 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
613 | - return self::proceedNavigation($entries); |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * get the id of loaded app |
|
618 | - * |
|
619 | - * @return string |
|
620 | - */ |
|
621 | - public static function getCurrentApp() { |
|
622 | - $request = \OC::$server->getRequest(); |
|
623 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
624 | - $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
625 | - if (empty($topFolder)) { |
|
626 | - $path_info = $request->getPathInfo(); |
|
627 | - if ($path_info) { |
|
628 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
629 | - } |
|
630 | - } |
|
631 | - if ($topFolder == 'apps') { |
|
632 | - $length = strlen($topFolder); |
|
633 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
634 | - } else { |
|
635 | - return $topFolder; |
|
636 | - } |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * @param string $type |
|
641 | - * @return array |
|
642 | - */ |
|
643 | - public static function getForms($type) { |
|
644 | - $forms = array(); |
|
645 | - switch ($type) { |
|
646 | - case 'admin': |
|
647 | - $source = self::$adminForms; |
|
648 | - break; |
|
649 | - case 'personal': |
|
650 | - $source = self::$personalForms; |
|
651 | - break; |
|
652 | - default: |
|
653 | - return array(); |
|
654 | - } |
|
655 | - foreach ($source as $form) { |
|
656 | - $forms[] = include $form; |
|
657 | - } |
|
658 | - return $forms; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * register an admin form to be shown |
|
663 | - * |
|
664 | - * @param string $app |
|
665 | - * @param string $page |
|
666 | - */ |
|
667 | - public static function registerAdmin($app, $page) { |
|
668 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * register a personal form to be shown |
|
673 | - * @param string $app |
|
674 | - * @param string $page |
|
675 | - */ |
|
676 | - public static function registerPersonal($app, $page) { |
|
677 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * @param array $entry |
|
682 | - */ |
|
683 | - public static function registerLogIn(array $entry) { |
|
684 | - self::$altLogin[] = $entry; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * @return array |
|
689 | - */ |
|
690 | - public static function getAlternativeLogIns() { |
|
691 | - return self::$altLogin; |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * get a list of all apps in the apps folder |
|
696 | - * |
|
697 | - * @return array an array of app names (string IDs) |
|
698 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
699 | - */ |
|
700 | - public static function getAllApps() { |
|
701 | - |
|
702 | - $apps = array(); |
|
703 | - |
|
704 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
705 | - if (!is_readable($apps_dir['path'])) { |
|
706 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
707 | - continue; |
|
708 | - } |
|
709 | - $dh = opendir($apps_dir['path']); |
|
710 | - |
|
711 | - if (is_resource($dh)) { |
|
712 | - while (($file = readdir($dh)) !== false) { |
|
713 | - |
|
714 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
715 | - |
|
716 | - $apps[] = $file; |
|
717 | - } |
|
718 | - } |
|
719 | - } |
|
720 | - } |
|
721 | - |
|
722 | - $apps = array_unique($apps); |
|
723 | - |
|
724 | - return $apps; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * List all apps, this is used in apps.php |
|
729 | - * |
|
730 | - * @return array |
|
731 | - */ |
|
732 | - public function listAllApps() { |
|
733 | - $installedApps = OC_App::getAllApps(); |
|
734 | - |
|
735 | - $appManager = \OC::$server->getAppManager(); |
|
736 | - //we don't want to show configuration for these |
|
737 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
738 | - $appList = array(); |
|
739 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
740 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
741 | - |
|
742 | - foreach ($installedApps as $app) { |
|
743 | - if (array_search($app, $blacklist) === false) { |
|
744 | - |
|
745 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
746 | - if (!is_array($info)) { |
|
747 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
748 | - continue; |
|
749 | - } |
|
750 | - |
|
751 | - if (!isset($info['name'])) { |
|
752 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
753 | - continue; |
|
754 | - } |
|
755 | - |
|
756 | - $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
757 | - $info['groups'] = null; |
|
758 | - if ($enabled === 'yes') { |
|
759 | - $active = true; |
|
760 | - } else if ($enabled === 'no') { |
|
761 | - $active = false; |
|
762 | - } else { |
|
763 | - $active = true; |
|
764 | - $info['groups'] = $enabled; |
|
765 | - } |
|
766 | - |
|
767 | - $info['active'] = $active; |
|
768 | - |
|
769 | - if ($appManager->isShipped($app)) { |
|
770 | - $info['internal'] = true; |
|
771 | - $info['level'] = self::officialApp; |
|
772 | - $info['removable'] = false; |
|
773 | - } else { |
|
774 | - $info['internal'] = false; |
|
775 | - $info['removable'] = true; |
|
776 | - } |
|
777 | - |
|
778 | - $appPath = self::getAppPath($app); |
|
779 | - if($appPath !== false) { |
|
780 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
781 | - if (file_exists($appIcon)) { |
|
782 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
783 | - $info['previewAsIcon'] = true; |
|
784 | - } else { |
|
785 | - $appIcon = $appPath . '/img/app.svg'; |
|
786 | - if (file_exists($appIcon)) { |
|
787 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
788 | - $info['previewAsIcon'] = true; |
|
789 | - } |
|
790 | - } |
|
791 | - } |
|
792 | - // fix documentation |
|
793 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
794 | - foreach ($info['documentation'] as $key => $url) { |
|
795 | - // If it is not an absolute URL we assume it is a key |
|
796 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
797 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
798 | - $url = $urlGenerator->linkToDocs($url); |
|
799 | - } |
|
800 | - |
|
801 | - $info['documentation'][$key] = $url; |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - $info['version'] = OC_App::getAppVersion($app); |
|
806 | - $appList[] = $info; |
|
807 | - } |
|
808 | - } |
|
809 | - |
|
810 | - return $appList; |
|
811 | - } |
|
812 | - |
|
813 | - public static function shouldUpgrade($app) { |
|
814 | - $versions = self::getAppVersions(); |
|
815 | - $currentVersion = OC_App::getAppVersion($app); |
|
816 | - if ($currentVersion && isset($versions[$app])) { |
|
817 | - $installedVersion = $versions[$app]; |
|
818 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
819 | - return true; |
|
820 | - } |
|
821 | - } |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * Adjust the number of version parts of $version1 to match |
|
827 | - * the number of version parts of $version2. |
|
828 | - * |
|
829 | - * @param string $version1 version to adjust |
|
830 | - * @param string $version2 version to take the number of parts from |
|
831 | - * @return string shortened $version1 |
|
832 | - */ |
|
833 | - private static function adjustVersionParts($version1, $version2) { |
|
834 | - $version1 = explode('.', $version1); |
|
835 | - $version2 = explode('.', $version2); |
|
836 | - // reduce $version1 to match the number of parts in $version2 |
|
837 | - while (count($version1) > count($version2)) { |
|
838 | - array_pop($version1); |
|
839 | - } |
|
840 | - // if $version1 does not have enough parts, add some |
|
841 | - while (count($version1) < count($version2)) { |
|
842 | - $version1[] = '0'; |
|
843 | - } |
|
844 | - return implode('.', $version1); |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Check whether the current ownCloud version matches the given |
|
849 | - * application's version requirements. |
|
850 | - * |
|
851 | - * The comparison is made based on the number of parts that the |
|
852 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
853 | - * app info version is expecting version 6.0, the comparison is |
|
854 | - * made on the first two parts of the ownCloud version. |
|
855 | - * This means that it's possible to specify "requiremin" => 6 |
|
856 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
857 | - * |
|
858 | - * @param string $ocVersion ownCloud version to check against |
|
859 | - * @param array $appInfo app info (from xml) |
|
860 | - * |
|
861 | - * @return boolean true if compatible, otherwise false |
|
862 | - */ |
|
863 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
864 | - $requireMin = ''; |
|
865 | - $requireMax = ''; |
|
866 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
867 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
868 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
869 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
870 | - } else if (isset($appInfo['requiremin'])) { |
|
871 | - $requireMin = $appInfo['requiremin']; |
|
872 | - } else if (isset($appInfo['require'])) { |
|
873 | - $requireMin = $appInfo['require']; |
|
874 | - } |
|
875 | - |
|
876 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
877 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
878 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
879 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
880 | - } else if (isset($appInfo['requiremax'])) { |
|
881 | - $requireMax = $appInfo['requiremax']; |
|
882 | - } |
|
883 | - |
|
884 | - if (is_array($ocVersion)) { |
|
885 | - $ocVersion = implode('.', $ocVersion); |
|
886 | - } |
|
887 | - |
|
888 | - if (!empty($requireMin) |
|
889 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
890 | - ) { |
|
891 | - |
|
892 | - return false; |
|
893 | - } |
|
894 | - |
|
895 | - if (!empty($requireMax) |
|
896 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
897 | - ) { |
|
898 | - return false; |
|
899 | - } |
|
900 | - |
|
901 | - return true; |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * get the installed version of all apps |
|
906 | - */ |
|
907 | - public static function getAppVersions() { |
|
908 | - static $versions; |
|
909 | - |
|
910 | - if(!$versions) { |
|
911 | - $appConfig = \OC::$server->getAppConfig(); |
|
912 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
913 | - } |
|
914 | - return $versions; |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * update the database for the app and call the update script |
|
919 | - * |
|
920 | - * @param string $appId |
|
921 | - * @return bool |
|
922 | - */ |
|
923 | - public static function updateApp($appId) { |
|
924 | - $appPath = self::getAppPath($appId); |
|
925 | - if($appPath === false) { |
|
926 | - return false; |
|
927 | - } |
|
928 | - self::registerAutoloading($appId, $appPath); |
|
929 | - |
|
930 | - $appData = self::getAppInfo($appId); |
|
931 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
932 | - |
|
933 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
934 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
935 | - } else { |
|
936 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
937 | - $ms->migrate(); |
|
938 | - } |
|
939 | - |
|
940 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
941 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
942 | - // update appversion in app manager |
|
943 | - \OC::$server->getAppManager()->getAppVersion($appId, false); |
|
944 | - |
|
945 | - // run upgrade code |
|
946 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
947 | - self::loadApp($appId); |
|
948 | - include $appPath . '/appinfo/update.php'; |
|
949 | - } |
|
950 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
951 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
952 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
953 | - } |
|
954 | - |
|
955 | - //set remote/public handlers |
|
956 | - if (array_key_exists('ocsid', $appData)) { |
|
957 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
958 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
959 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
960 | - } |
|
961 | - foreach ($appData['remote'] as $name => $path) { |
|
962 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
963 | - } |
|
964 | - foreach ($appData['public'] as $name => $path) { |
|
965 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
966 | - } |
|
967 | - |
|
968 | - self::setAppTypes($appId); |
|
969 | - |
|
970 | - $version = \OC_App::getAppVersion($appId); |
|
971 | - \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
972 | - |
|
973 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
974 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
975 | - )); |
|
976 | - |
|
977 | - return true; |
|
978 | - } |
|
979 | - |
|
980 | - /** |
|
981 | - * @param string $appId |
|
982 | - * @param string[] $steps |
|
983 | - * @throws \OC\NeedsUpdateException |
|
984 | - */ |
|
985 | - public static function executeRepairSteps($appId, array $steps) { |
|
986 | - if (empty($steps)) { |
|
987 | - return; |
|
988 | - } |
|
989 | - // load the app |
|
990 | - self::loadApp($appId); |
|
991 | - |
|
992 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
993 | - |
|
994 | - // load the steps |
|
995 | - $r = new Repair([], $dispatcher); |
|
996 | - foreach ($steps as $step) { |
|
997 | - try { |
|
998 | - $r->addStep($step); |
|
999 | - } catch (Exception $ex) { |
|
1000 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1001 | - \OC::$server->getLogger()->logException($ex); |
|
1002 | - } |
|
1003 | - } |
|
1004 | - // run the steps |
|
1005 | - $r->run(); |
|
1006 | - } |
|
1007 | - |
|
1008 | - public static function setupBackgroundJobs(array $jobs) { |
|
1009 | - $queue = \OC::$server->getJobList(); |
|
1010 | - foreach ($jobs as $job) { |
|
1011 | - $queue->add($job); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * @param string $appId |
|
1017 | - * @param string[] $steps |
|
1018 | - */ |
|
1019 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1020 | - $queue = \OC::$server->getJobList(); |
|
1021 | - foreach ($steps as $step) { |
|
1022 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1023 | - 'app' => $appId, |
|
1024 | - 'step' => $step]); |
|
1025 | - } |
|
1026 | - } |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * @param string $appId |
|
1030 | - * @return \OC\Files\View|false |
|
1031 | - */ |
|
1032 | - public static function getStorage($appId) { |
|
1033 | - if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1034 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1035 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1036 | - if (!$view->file_exists($appId)) { |
|
1037 | - $view->mkdir($appId); |
|
1038 | - } |
|
1039 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1040 | - } else { |
|
1041 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1042 | - return false; |
|
1043 | - } |
|
1044 | - } else { |
|
1045 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1046 | - return false; |
|
1047 | - } |
|
1048 | - } |
|
1049 | - |
|
1050 | - protected static function findBestL10NOption($options, $lang) { |
|
1051 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1052 | - |
|
1053 | - $lang = strtolower($lang); |
|
1054 | - $similarLang = $lang; |
|
1055 | - if (strpos($similarLang, '_')) { |
|
1056 | - // For "de_DE" we want to find "de" and the other way around |
|
1057 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1058 | - } |
|
1059 | - |
|
1060 | - foreach ($options as $option) { |
|
1061 | - if (is_array($option)) { |
|
1062 | - if ($fallback === false) { |
|
1063 | - $fallback = $option['@value']; |
|
1064 | - } |
|
1065 | - |
|
1066 | - if (!isset($option['@attributes']['lang'])) { |
|
1067 | - continue; |
|
1068 | - } |
|
1069 | - |
|
1070 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1071 | - if ($attributeLang === $lang) { |
|
1072 | - return $option['@value']; |
|
1073 | - } |
|
1074 | - |
|
1075 | - if ($attributeLang === $similarLang) { |
|
1076 | - $similarLangFallback = $option['@value']; |
|
1077 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1078 | - if ($similarLangFallback === false) { |
|
1079 | - $similarLangFallback = $option['@value']; |
|
1080 | - } |
|
1081 | - } |
|
1082 | - } else { |
|
1083 | - $englishFallback = $option; |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - if ($similarLangFallback !== false) { |
|
1088 | - return $similarLangFallback; |
|
1089 | - } else if ($englishFallback !== false) { |
|
1090 | - return $englishFallback; |
|
1091 | - } |
|
1092 | - return (string) $fallback; |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * parses the app data array and enhanced the 'description' value |
|
1097 | - * |
|
1098 | - * @param array $data the app data |
|
1099 | - * @param string $lang |
|
1100 | - * @return array improved app data |
|
1101 | - */ |
|
1102 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1103 | - |
|
1104 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1105 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1106 | - } |
|
1107 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1108 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1109 | - } |
|
1110 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1111 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1112 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1113 | - $data['description'] = trim($data['description']); |
|
1114 | - } else { |
|
1115 | - $data['description'] = ''; |
|
1116 | - } |
|
1117 | - |
|
1118 | - return $data; |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * @param \OCP\IConfig $config |
|
1123 | - * @param \OCP\IL10N $l |
|
1124 | - * @param array $info |
|
1125 | - * @throws \Exception |
|
1126 | - */ |
|
1127 | - public static function checkAppDependencies($config, $l, $info) { |
|
1128 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1129 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1130 | - if (!empty($missing)) { |
|
1131 | - $missingMsg = implode(PHP_EOL, $missing); |
|
1132 | - throw new \Exception( |
|
1133 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1134 | - [$info['name'], $missingMsg] |
|
1135 | - ) |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } |
|
65 | + static private $adminForms = array(); |
|
66 | + static private $personalForms = array(); |
|
67 | + static private $appTypes = array(); |
|
68 | + static private $loadedApps = array(); |
|
69 | + static private $altLogin = array(); |
|
70 | + static private $alreadyRegistered = []; |
|
71 | + const officialApp = 200; |
|
72 | + |
|
73 | + /** |
|
74 | + * clean the appId |
|
75 | + * |
|
76 | + * @param string|boolean $app AppId that needs to be cleaned |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function cleanAppId($app) { |
|
80 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Check if an app is loaded |
|
85 | + * |
|
86 | + * @param string $app |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public static function isAppLoaded($app) { |
|
90 | + return in_array($app, self::$loadedApps, true); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * loads all apps |
|
95 | + * |
|
96 | + * @param string[] | string | null $types |
|
97 | + * @return bool |
|
98 | + * |
|
99 | + * This function walks through the ownCloud directory and loads all apps |
|
100 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
101 | + * exists. |
|
102 | + * |
|
103 | + * if $types is set, only apps of those types will be loaded |
|
104 | + */ |
|
105 | + public static function loadApps($types = null) { |
|
106 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
107 | + return false; |
|
108 | + } |
|
109 | + // Load the enabled apps here |
|
110 | + $apps = self::getEnabledApps(); |
|
111 | + |
|
112 | + // Add each apps' folder as allowed class path |
|
113 | + foreach($apps as $app) { |
|
114 | + $path = self::getAppPath($app); |
|
115 | + if($path !== false) { |
|
116 | + self::registerAutoloading($app, $path); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + // prevent app.php from printing output |
|
121 | + ob_start(); |
|
122 | + foreach ($apps as $app) { |
|
123 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
124 | + self::loadApp($app); |
|
125 | + } |
|
126 | + } |
|
127 | + ob_end_clean(); |
|
128 | + |
|
129 | + return true; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * load a single app |
|
134 | + * |
|
135 | + * @param string $app |
|
136 | + */ |
|
137 | + public static function loadApp($app) { |
|
138 | + self::$loadedApps[] = $app; |
|
139 | + $appPath = self::getAppPath($app); |
|
140 | + if($appPath === false) { |
|
141 | + return; |
|
142 | + } |
|
143 | + |
|
144 | + // in case someone calls loadApp() directly |
|
145 | + self::registerAutoloading($app, $appPath); |
|
146 | + |
|
147 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
148 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
149 | + self::requireAppFile($app); |
|
150 | + if (self::isType($app, array('authentication'))) { |
|
151 | + // since authentication apps affect the "is app enabled for group" check, |
|
152 | + // the enabled apps cache needs to be cleared to make sure that the |
|
153 | + // next time getEnableApps() is called it will also include apps that were |
|
154 | + // enabled for groups |
|
155 | + self::$enabledAppsCache = array(); |
|
156 | + } |
|
157 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
158 | + } |
|
159 | + |
|
160 | + $info = self::getAppInfo($app); |
|
161 | + if (!empty($info['activity']['filters'])) { |
|
162 | + foreach ($info['activity']['filters'] as $filter) { |
|
163 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
164 | + } |
|
165 | + } |
|
166 | + if (!empty($info['activity']['settings'])) { |
|
167 | + foreach ($info['activity']['settings'] as $setting) { |
|
168 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
169 | + } |
|
170 | + } |
|
171 | + if (!empty($info['activity']['providers'])) { |
|
172 | + foreach ($info['activity']['providers'] as $provider) { |
|
173 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
174 | + } |
|
175 | + } |
|
176 | + if (!empty($info['collaboration']['plugins'])) { |
|
177 | + // deal with one or many plugin entries |
|
178 | + $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
179 | + [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
180 | + foreach ($plugins as $plugin) { |
|
181 | + if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
182 | + $pluginInfo = [ |
|
183 | + 'shareType' => $plugin['@attributes']['share-type'], |
|
184 | + 'class' => $plugin['@value'], |
|
185 | + ]; |
|
186 | + \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
187 | + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
188 | + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @internal |
|
196 | + * @param string $app |
|
197 | + * @param string $path |
|
198 | + */ |
|
199 | + public static function registerAutoloading($app, $path) { |
|
200 | + $key = $app . '-' . $path; |
|
201 | + if(isset(self::$alreadyRegistered[$key])) { |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + self::$alreadyRegistered[$key] = true; |
|
206 | + |
|
207 | + // Register on PSR-4 composer autoloader |
|
208 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
209 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
210 | + |
|
211 | + if (file_exists($path . '/composer/autoload.php')) { |
|
212 | + require_once $path . '/composer/autoload.php'; |
|
213 | + } else { |
|
214 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
215 | + // Register on legacy autoloader |
|
216 | + \OC::$loader->addValidRoot($path); |
|
217 | + } |
|
218 | + |
|
219 | + // Register Test namespace only when testing |
|
220 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
221 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Load app.php from the given app |
|
227 | + * |
|
228 | + * @param string $app app name |
|
229 | + */ |
|
230 | + private static function requireAppFile($app) { |
|
231 | + try { |
|
232 | + // encapsulated here to avoid variable scope conflicts |
|
233 | + require_once $app . '/appinfo/app.php'; |
|
234 | + } catch (Error $ex) { |
|
235 | + \OC::$server->getLogger()->logException($ex); |
|
236 | + if (!\OC::$server->getAppManager()->isShipped($app)) { |
|
237 | + // Only disable apps which are not shipped |
|
238 | + self::disable($app); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * check if an app is of a specific type |
|
245 | + * |
|
246 | + * @param string $app |
|
247 | + * @param string|array $types |
|
248 | + * @return bool |
|
249 | + */ |
|
250 | + public static function isType($app, $types) { |
|
251 | + if (is_string($types)) { |
|
252 | + $types = array($types); |
|
253 | + } |
|
254 | + $appTypes = self::getAppTypes($app); |
|
255 | + foreach ($types as $type) { |
|
256 | + if (array_search($type, $appTypes) !== false) { |
|
257 | + return true; |
|
258 | + } |
|
259 | + } |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * get the types of an app |
|
265 | + * |
|
266 | + * @param string $app |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + private static function getAppTypes($app) { |
|
270 | + //load the cache |
|
271 | + if (count(self::$appTypes) == 0) { |
|
272 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
273 | + } |
|
274 | + |
|
275 | + if (isset(self::$appTypes[$app])) { |
|
276 | + return explode(',', self::$appTypes[$app]); |
|
277 | + } else { |
|
278 | + return array(); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * read app types from info.xml and cache them in the database |
|
284 | + */ |
|
285 | + public static function setAppTypes($app) { |
|
286 | + $appData = self::getAppInfo($app); |
|
287 | + if(!is_array($appData)) { |
|
288 | + return; |
|
289 | + } |
|
290 | + |
|
291 | + if (isset($appData['types'])) { |
|
292 | + $appTypes = implode(',', $appData['types']); |
|
293 | + } else { |
|
294 | + $appTypes = ''; |
|
295 | + $appData['types'] = []; |
|
296 | + } |
|
297 | + |
|
298 | + \OC::$server->getConfig()->setAppValue($app, 'types', $appTypes); |
|
299 | + |
|
300 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
301 | + $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'yes'); |
|
302 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
303 | + \OC::$server->getConfig()->setAppValue($app, 'enabled', 'yes'); |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * get all enabled apps |
|
310 | + */ |
|
311 | + protected static $enabledAppsCache = array(); |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns apps enabled for the current user. |
|
315 | + * |
|
316 | + * @param bool $forceRefresh whether to refresh the cache |
|
317 | + * @param bool $all whether to return apps for all users, not only the |
|
318 | + * currently logged in one |
|
319 | + * @return string[] |
|
320 | + */ |
|
321 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
322 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
323 | + return array(); |
|
324 | + } |
|
325 | + // in incognito mode or when logged out, $user will be false, |
|
326 | + // which is also the case during an upgrade |
|
327 | + $appManager = \OC::$server->getAppManager(); |
|
328 | + if ($all) { |
|
329 | + $user = null; |
|
330 | + } else { |
|
331 | + $user = \OC::$server->getUserSession()->getUser(); |
|
332 | + } |
|
333 | + |
|
334 | + if (is_null($user)) { |
|
335 | + $apps = $appManager->getInstalledApps(); |
|
336 | + } else { |
|
337 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
338 | + } |
|
339 | + $apps = array_filter($apps, function ($app) { |
|
340 | + return $app !== 'files';//we add this manually |
|
341 | + }); |
|
342 | + sort($apps); |
|
343 | + array_unshift($apps, 'files'); |
|
344 | + return $apps; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * checks whether or not an app is enabled |
|
349 | + * |
|
350 | + * @param string $app app |
|
351 | + * @return bool |
|
352 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
353 | + * |
|
354 | + * This function checks whether or not an app is enabled. |
|
355 | + */ |
|
356 | + public static function isEnabled($app) { |
|
357 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * enables an app |
|
362 | + * |
|
363 | + * @param string $appId |
|
364 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
365 | + * @throws \Exception |
|
366 | + * @return void |
|
367 | + * |
|
368 | + * This function set an app as enabled in appconfig. |
|
369 | + */ |
|
370 | + public function enable($appId, |
|
371 | + $groups = null) { |
|
372 | + self::$enabledAppsCache = []; // flush |
|
373 | + |
|
374 | + // Check if app is already downloaded |
|
375 | + $installer = \OC::$server->query(Installer::class); |
|
376 | + $isDownloaded = $installer->isDownloaded($appId); |
|
377 | + |
|
378 | + if(!$isDownloaded) { |
|
379 | + $installer->downloadApp($appId); |
|
380 | + } |
|
381 | + |
|
382 | + $installer->installApp($appId); |
|
383 | + |
|
384 | + $appManager = \OC::$server->getAppManager(); |
|
385 | + if (!is_null($groups)) { |
|
386 | + $groupManager = \OC::$server->getGroupManager(); |
|
387 | + $groupsList = []; |
|
388 | + foreach ($groups as $group) { |
|
389 | + $groupItem = $groupManager->get($group); |
|
390 | + if ($groupItem instanceof \OCP\IGroup) { |
|
391 | + $groupsList[] = $groupManager->get($group); |
|
392 | + } |
|
393 | + } |
|
394 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
395 | + } else { |
|
396 | + $appManager->enableApp($appId); |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * This function set an app as disabled in appconfig. |
|
402 | + * |
|
403 | + * @param string $app app |
|
404 | + * @throws Exception |
|
405 | + */ |
|
406 | + public static function disable($app) { |
|
407 | + // flush |
|
408 | + self::$enabledAppsCache = array(); |
|
409 | + |
|
410 | + // run uninstall steps |
|
411 | + $appData = OC_App::getAppInfo($app); |
|
412 | + if (!is_null($appData)) { |
|
413 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
414 | + } |
|
415 | + |
|
416 | + // emit disable hook - needed anymore ? |
|
417 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
418 | + |
|
419 | + // finally disable it |
|
420 | + $appManager = \OC::$server->getAppManager(); |
|
421 | + $appManager->disableApp($app); |
|
422 | + } |
|
423 | + |
|
424 | + // This is private as well. It simply works, so don't ask for more details |
|
425 | + private static function proceedNavigation($list) { |
|
426 | + usort($list, function($a, $b) { |
|
427 | + if (isset($a['order']) && isset($b['order'])) { |
|
428 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
429 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
430 | + return isset($a['order']) ? -1 : 1; |
|
431 | + } else { |
|
432 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
433 | + } |
|
434 | + }); |
|
435 | + |
|
436 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
437 | + foreach ($list as $index => &$navEntry) { |
|
438 | + if ($navEntry['id'] == $activeApp) { |
|
439 | + $navEntry['active'] = true; |
|
440 | + } else { |
|
441 | + $navEntry['active'] = false; |
|
442 | + } |
|
443 | + } |
|
444 | + unset($navEntry); |
|
445 | + |
|
446 | + return $list; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * Get the path where to install apps |
|
451 | + * |
|
452 | + * @return string|false |
|
453 | + */ |
|
454 | + public static function getInstallPath() { |
|
455 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
456 | + return false; |
|
457 | + } |
|
458 | + |
|
459 | + foreach (OC::$APPSROOTS as $dir) { |
|
460 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
461 | + return $dir['path']; |
|
462 | + } |
|
463 | + } |
|
464 | + |
|
465 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
466 | + return null; |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * search for an app in all app-directories |
|
472 | + * |
|
473 | + * @param string $appId |
|
474 | + * @return false|string |
|
475 | + */ |
|
476 | + public static function findAppInDirectories($appId) { |
|
477 | + $sanitizedAppId = self::cleanAppId($appId); |
|
478 | + if($sanitizedAppId !== $appId) { |
|
479 | + return false; |
|
480 | + } |
|
481 | + static $app_dir = array(); |
|
482 | + |
|
483 | + if (isset($app_dir[$appId])) { |
|
484 | + return $app_dir[$appId]; |
|
485 | + } |
|
486 | + |
|
487 | + $possibleApps = array(); |
|
488 | + foreach (OC::$APPSROOTS as $dir) { |
|
489 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
490 | + $possibleApps[] = $dir; |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + if (empty($possibleApps)) { |
|
495 | + return false; |
|
496 | + } elseif (count($possibleApps) === 1) { |
|
497 | + $dir = array_shift($possibleApps); |
|
498 | + $app_dir[$appId] = $dir; |
|
499 | + return $dir; |
|
500 | + } else { |
|
501 | + $versionToLoad = array(); |
|
502 | + foreach ($possibleApps as $possibleApp) { |
|
503 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
504 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
505 | + $versionToLoad = array( |
|
506 | + 'dir' => $possibleApp, |
|
507 | + 'version' => $version, |
|
508 | + ); |
|
509 | + } |
|
510 | + } |
|
511 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
512 | + return $versionToLoad['dir']; |
|
513 | + //TODO - write test |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Get the directory for the given app. |
|
519 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
520 | + * |
|
521 | + * @param string $appId |
|
522 | + * @return string|false |
|
523 | + */ |
|
524 | + public static function getAppPath($appId) { |
|
525 | + if ($appId === null || trim($appId) === '') { |
|
526 | + return false; |
|
527 | + } |
|
528 | + |
|
529 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
530 | + return $dir['path'] . '/' . $appId; |
|
531 | + } |
|
532 | + return false; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Get the path for the given app on the access |
|
537 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
538 | + * |
|
539 | + * @param string $appId |
|
540 | + * @return string|false |
|
541 | + */ |
|
542 | + public static function getAppWebPath($appId) { |
|
543 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
544 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
545 | + } |
|
546 | + return false; |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * get the last version of the app from appinfo/info.xml |
|
551 | + * |
|
552 | + * @param string $appId |
|
553 | + * @param bool $useCache |
|
554 | + * @return string |
|
555 | + * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion() |
|
556 | + */ |
|
557 | + public static function getAppVersion($appId, $useCache = true) { |
|
558 | + return \OC::$server->getAppManager()->getAppVersion($appId, $useCache); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * get app's version based on it's path |
|
563 | + * |
|
564 | + * @param string $path |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + public static function getAppVersionByPath($path) { |
|
568 | + $infoFile = $path . '/appinfo/info.xml'; |
|
569 | + $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
|
570 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
571 | + } |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * Read all app metadata from the info.xml file |
|
576 | + * |
|
577 | + * @param string $appId id of the app or the path of the info.xml file |
|
578 | + * @param bool $path |
|
579 | + * @param string $lang |
|
580 | + * @return array|null |
|
581 | + * @note all data is read from info.xml, not just pre-defined fields |
|
582 | + * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo() |
|
583 | + */ |
|
584 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
585 | + return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns the navigation |
|
590 | + * |
|
591 | + * @return array |
|
592 | + * |
|
593 | + * This function returns an array containing all entries added. The |
|
594 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
595 | + * given for each app the following keys exist: |
|
596 | + * - active: boolean, signals if the user is on this navigation entry |
|
597 | + */ |
|
598 | + public static function getNavigation() { |
|
599 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
600 | + return self::proceedNavigation($entries); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Returns the Settings Navigation |
|
605 | + * |
|
606 | + * @return string[] |
|
607 | + * |
|
608 | + * This function returns an array containing all settings pages added. The |
|
609 | + * entries are sorted by the key 'order' ascending. |
|
610 | + */ |
|
611 | + public static function getSettingsNavigation() { |
|
612 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
613 | + return self::proceedNavigation($entries); |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * get the id of loaded app |
|
618 | + * |
|
619 | + * @return string |
|
620 | + */ |
|
621 | + public static function getCurrentApp() { |
|
622 | + $request = \OC::$server->getRequest(); |
|
623 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
624 | + $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
625 | + if (empty($topFolder)) { |
|
626 | + $path_info = $request->getPathInfo(); |
|
627 | + if ($path_info) { |
|
628 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
629 | + } |
|
630 | + } |
|
631 | + if ($topFolder == 'apps') { |
|
632 | + $length = strlen($topFolder); |
|
633 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
634 | + } else { |
|
635 | + return $topFolder; |
|
636 | + } |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * @param string $type |
|
641 | + * @return array |
|
642 | + */ |
|
643 | + public static function getForms($type) { |
|
644 | + $forms = array(); |
|
645 | + switch ($type) { |
|
646 | + case 'admin': |
|
647 | + $source = self::$adminForms; |
|
648 | + break; |
|
649 | + case 'personal': |
|
650 | + $source = self::$personalForms; |
|
651 | + break; |
|
652 | + default: |
|
653 | + return array(); |
|
654 | + } |
|
655 | + foreach ($source as $form) { |
|
656 | + $forms[] = include $form; |
|
657 | + } |
|
658 | + return $forms; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * register an admin form to be shown |
|
663 | + * |
|
664 | + * @param string $app |
|
665 | + * @param string $page |
|
666 | + */ |
|
667 | + public static function registerAdmin($app, $page) { |
|
668 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * register a personal form to be shown |
|
673 | + * @param string $app |
|
674 | + * @param string $page |
|
675 | + */ |
|
676 | + public static function registerPersonal($app, $page) { |
|
677 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * @param array $entry |
|
682 | + */ |
|
683 | + public static function registerLogIn(array $entry) { |
|
684 | + self::$altLogin[] = $entry; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * @return array |
|
689 | + */ |
|
690 | + public static function getAlternativeLogIns() { |
|
691 | + return self::$altLogin; |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * get a list of all apps in the apps folder |
|
696 | + * |
|
697 | + * @return array an array of app names (string IDs) |
|
698 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
699 | + */ |
|
700 | + public static function getAllApps() { |
|
701 | + |
|
702 | + $apps = array(); |
|
703 | + |
|
704 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
705 | + if (!is_readable($apps_dir['path'])) { |
|
706 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
707 | + continue; |
|
708 | + } |
|
709 | + $dh = opendir($apps_dir['path']); |
|
710 | + |
|
711 | + if (is_resource($dh)) { |
|
712 | + while (($file = readdir($dh)) !== false) { |
|
713 | + |
|
714 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
715 | + |
|
716 | + $apps[] = $file; |
|
717 | + } |
|
718 | + } |
|
719 | + } |
|
720 | + } |
|
721 | + |
|
722 | + $apps = array_unique($apps); |
|
723 | + |
|
724 | + return $apps; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * List all apps, this is used in apps.php |
|
729 | + * |
|
730 | + * @return array |
|
731 | + */ |
|
732 | + public function listAllApps() { |
|
733 | + $installedApps = OC_App::getAllApps(); |
|
734 | + |
|
735 | + $appManager = \OC::$server->getAppManager(); |
|
736 | + //we don't want to show configuration for these |
|
737 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
738 | + $appList = array(); |
|
739 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
740 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
741 | + |
|
742 | + foreach ($installedApps as $app) { |
|
743 | + if (array_search($app, $blacklist) === false) { |
|
744 | + |
|
745 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
746 | + if (!is_array($info)) { |
|
747 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
748 | + continue; |
|
749 | + } |
|
750 | + |
|
751 | + if (!isset($info['name'])) { |
|
752 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
753 | + continue; |
|
754 | + } |
|
755 | + |
|
756 | + $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
757 | + $info['groups'] = null; |
|
758 | + if ($enabled === 'yes') { |
|
759 | + $active = true; |
|
760 | + } else if ($enabled === 'no') { |
|
761 | + $active = false; |
|
762 | + } else { |
|
763 | + $active = true; |
|
764 | + $info['groups'] = $enabled; |
|
765 | + } |
|
766 | + |
|
767 | + $info['active'] = $active; |
|
768 | + |
|
769 | + if ($appManager->isShipped($app)) { |
|
770 | + $info['internal'] = true; |
|
771 | + $info['level'] = self::officialApp; |
|
772 | + $info['removable'] = false; |
|
773 | + } else { |
|
774 | + $info['internal'] = false; |
|
775 | + $info['removable'] = true; |
|
776 | + } |
|
777 | + |
|
778 | + $appPath = self::getAppPath($app); |
|
779 | + if($appPath !== false) { |
|
780 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
781 | + if (file_exists($appIcon)) { |
|
782 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
783 | + $info['previewAsIcon'] = true; |
|
784 | + } else { |
|
785 | + $appIcon = $appPath . '/img/app.svg'; |
|
786 | + if (file_exists($appIcon)) { |
|
787 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
788 | + $info['previewAsIcon'] = true; |
|
789 | + } |
|
790 | + } |
|
791 | + } |
|
792 | + // fix documentation |
|
793 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
794 | + foreach ($info['documentation'] as $key => $url) { |
|
795 | + // If it is not an absolute URL we assume it is a key |
|
796 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
797 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
798 | + $url = $urlGenerator->linkToDocs($url); |
|
799 | + } |
|
800 | + |
|
801 | + $info['documentation'][$key] = $url; |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + $info['version'] = OC_App::getAppVersion($app); |
|
806 | + $appList[] = $info; |
|
807 | + } |
|
808 | + } |
|
809 | + |
|
810 | + return $appList; |
|
811 | + } |
|
812 | + |
|
813 | + public static function shouldUpgrade($app) { |
|
814 | + $versions = self::getAppVersions(); |
|
815 | + $currentVersion = OC_App::getAppVersion($app); |
|
816 | + if ($currentVersion && isset($versions[$app])) { |
|
817 | + $installedVersion = $versions[$app]; |
|
818 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
819 | + return true; |
|
820 | + } |
|
821 | + } |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * Adjust the number of version parts of $version1 to match |
|
827 | + * the number of version parts of $version2. |
|
828 | + * |
|
829 | + * @param string $version1 version to adjust |
|
830 | + * @param string $version2 version to take the number of parts from |
|
831 | + * @return string shortened $version1 |
|
832 | + */ |
|
833 | + private static function adjustVersionParts($version1, $version2) { |
|
834 | + $version1 = explode('.', $version1); |
|
835 | + $version2 = explode('.', $version2); |
|
836 | + // reduce $version1 to match the number of parts in $version2 |
|
837 | + while (count($version1) > count($version2)) { |
|
838 | + array_pop($version1); |
|
839 | + } |
|
840 | + // if $version1 does not have enough parts, add some |
|
841 | + while (count($version1) < count($version2)) { |
|
842 | + $version1[] = '0'; |
|
843 | + } |
|
844 | + return implode('.', $version1); |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Check whether the current ownCloud version matches the given |
|
849 | + * application's version requirements. |
|
850 | + * |
|
851 | + * The comparison is made based on the number of parts that the |
|
852 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
853 | + * app info version is expecting version 6.0, the comparison is |
|
854 | + * made on the first two parts of the ownCloud version. |
|
855 | + * This means that it's possible to specify "requiremin" => 6 |
|
856 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
857 | + * |
|
858 | + * @param string $ocVersion ownCloud version to check against |
|
859 | + * @param array $appInfo app info (from xml) |
|
860 | + * |
|
861 | + * @return boolean true if compatible, otherwise false |
|
862 | + */ |
|
863 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
864 | + $requireMin = ''; |
|
865 | + $requireMax = ''; |
|
866 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
867 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
868 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
869 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
870 | + } else if (isset($appInfo['requiremin'])) { |
|
871 | + $requireMin = $appInfo['requiremin']; |
|
872 | + } else if (isset($appInfo['require'])) { |
|
873 | + $requireMin = $appInfo['require']; |
|
874 | + } |
|
875 | + |
|
876 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
877 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
878 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
879 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
880 | + } else if (isset($appInfo['requiremax'])) { |
|
881 | + $requireMax = $appInfo['requiremax']; |
|
882 | + } |
|
883 | + |
|
884 | + if (is_array($ocVersion)) { |
|
885 | + $ocVersion = implode('.', $ocVersion); |
|
886 | + } |
|
887 | + |
|
888 | + if (!empty($requireMin) |
|
889 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
890 | + ) { |
|
891 | + |
|
892 | + return false; |
|
893 | + } |
|
894 | + |
|
895 | + if (!empty($requireMax) |
|
896 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
897 | + ) { |
|
898 | + return false; |
|
899 | + } |
|
900 | + |
|
901 | + return true; |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * get the installed version of all apps |
|
906 | + */ |
|
907 | + public static function getAppVersions() { |
|
908 | + static $versions; |
|
909 | + |
|
910 | + if(!$versions) { |
|
911 | + $appConfig = \OC::$server->getAppConfig(); |
|
912 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
913 | + } |
|
914 | + return $versions; |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * update the database for the app and call the update script |
|
919 | + * |
|
920 | + * @param string $appId |
|
921 | + * @return bool |
|
922 | + */ |
|
923 | + public static function updateApp($appId) { |
|
924 | + $appPath = self::getAppPath($appId); |
|
925 | + if($appPath === false) { |
|
926 | + return false; |
|
927 | + } |
|
928 | + self::registerAutoloading($appId, $appPath); |
|
929 | + |
|
930 | + $appData = self::getAppInfo($appId); |
|
931 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
932 | + |
|
933 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
934 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
935 | + } else { |
|
936 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
937 | + $ms->migrate(); |
|
938 | + } |
|
939 | + |
|
940 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
941 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
942 | + // update appversion in app manager |
|
943 | + \OC::$server->getAppManager()->getAppVersion($appId, false); |
|
944 | + |
|
945 | + // run upgrade code |
|
946 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
947 | + self::loadApp($appId); |
|
948 | + include $appPath . '/appinfo/update.php'; |
|
949 | + } |
|
950 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
951 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
952 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
953 | + } |
|
954 | + |
|
955 | + //set remote/public handlers |
|
956 | + if (array_key_exists('ocsid', $appData)) { |
|
957 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
958 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
959 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
960 | + } |
|
961 | + foreach ($appData['remote'] as $name => $path) { |
|
962 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
963 | + } |
|
964 | + foreach ($appData['public'] as $name => $path) { |
|
965 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
966 | + } |
|
967 | + |
|
968 | + self::setAppTypes($appId); |
|
969 | + |
|
970 | + $version = \OC_App::getAppVersion($appId); |
|
971 | + \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
972 | + |
|
973 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
974 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
975 | + )); |
|
976 | + |
|
977 | + return true; |
|
978 | + } |
|
979 | + |
|
980 | + /** |
|
981 | + * @param string $appId |
|
982 | + * @param string[] $steps |
|
983 | + * @throws \OC\NeedsUpdateException |
|
984 | + */ |
|
985 | + public static function executeRepairSteps($appId, array $steps) { |
|
986 | + if (empty($steps)) { |
|
987 | + return; |
|
988 | + } |
|
989 | + // load the app |
|
990 | + self::loadApp($appId); |
|
991 | + |
|
992 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
993 | + |
|
994 | + // load the steps |
|
995 | + $r = new Repair([], $dispatcher); |
|
996 | + foreach ($steps as $step) { |
|
997 | + try { |
|
998 | + $r->addStep($step); |
|
999 | + } catch (Exception $ex) { |
|
1000 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1001 | + \OC::$server->getLogger()->logException($ex); |
|
1002 | + } |
|
1003 | + } |
|
1004 | + // run the steps |
|
1005 | + $r->run(); |
|
1006 | + } |
|
1007 | + |
|
1008 | + public static function setupBackgroundJobs(array $jobs) { |
|
1009 | + $queue = \OC::$server->getJobList(); |
|
1010 | + foreach ($jobs as $job) { |
|
1011 | + $queue->add($job); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * @param string $appId |
|
1017 | + * @param string[] $steps |
|
1018 | + */ |
|
1019 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1020 | + $queue = \OC::$server->getJobList(); |
|
1021 | + foreach ($steps as $step) { |
|
1022 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1023 | + 'app' => $appId, |
|
1024 | + 'step' => $step]); |
|
1025 | + } |
|
1026 | + } |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * @param string $appId |
|
1030 | + * @return \OC\Files\View|false |
|
1031 | + */ |
|
1032 | + public static function getStorage($appId) { |
|
1033 | + if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1034 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1035 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1036 | + if (!$view->file_exists($appId)) { |
|
1037 | + $view->mkdir($appId); |
|
1038 | + } |
|
1039 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1040 | + } else { |
|
1041 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1042 | + return false; |
|
1043 | + } |
|
1044 | + } else { |
|
1045 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1046 | + return false; |
|
1047 | + } |
|
1048 | + } |
|
1049 | + |
|
1050 | + protected static function findBestL10NOption($options, $lang) { |
|
1051 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1052 | + |
|
1053 | + $lang = strtolower($lang); |
|
1054 | + $similarLang = $lang; |
|
1055 | + if (strpos($similarLang, '_')) { |
|
1056 | + // For "de_DE" we want to find "de" and the other way around |
|
1057 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1058 | + } |
|
1059 | + |
|
1060 | + foreach ($options as $option) { |
|
1061 | + if (is_array($option)) { |
|
1062 | + if ($fallback === false) { |
|
1063 | + $fallback = $option['@value']; |
|
1064 | + } |
|
1065 | + |
|
1066 | + if (!isset($option['@attributes']['lang'])) { |
|
1067 | + continue; |
|
1068 | + } |
|
1069 | + |
|
1070 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1071 | + if ($attributeLang === $lang) { |
|
1072 | + return $option['@value']; |
|
1073 | + } |
|
1074 | + |
|
1075 | + if ($attributeLang === $similarLang) { |
|
1076 | + $similarLangFallback = $option['@value']; |
|
1077 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1078 | + if ($similarLangFallback === false) { |
|
1079 | + $similarLangFallback = $option['@value']; |
|
1080 | + } |
|
1081 | + } |
|
1082 | + } else { |
|
1083 | + $englishFallback = $option; |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + if ($similarLangFallback !== false) { |
|
1088 | + return $similarLangFallback; |
|
1089 | + } else if ($englishFallback !== false) { |
|
1090 | + return $englishFallback; |
|
1091 | + } |
|
1092 | + return (string) $fallback; |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * parses the app data array and enhanced the 'description' value |
|
1097 | + * |
|
1098 | + * @param array $data the app data |
|
1099 | + * @param string $lang |
|
1100 | + * @return array improved app data |
|
1101 | + */ |
|
1102 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1103 | + |
|
1104 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1105 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1106 | + } |
|
1107 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1108 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1109 | + } |
|
1110 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1111 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1112 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1113 | + $data['description'] = trim($data['description']); |
|
1114 | + } else { |
|
1115 | + $data['description'] = ''; |
|
1116 | + } |
|
1117 | + |
|
1118 | + return $data; |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * @param \OCP\IConfig $config |
|
1123 | + * @param \OCP\IL10N $l |
|
1124 | + * @param array $info |
|
1125 | + * @throws \Exception |
|
1126 | + */ |
|
1127 | + public static function checkAppDependencies($config, $l, $info) { |
|
1128 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1129 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1130 | + if (!empty($missing)) { |
|
1131 | + $missingMsg = implode(PHP_EOL, $missing); |
|
1132 | + throw new \Exception( |
|
1133 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1134 | + [$info['name'], $missingMsg] |
|
1135 | + ) |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } |
|
1139 | 1139 | } |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | $apps = self::getEnabledApps(); |
111 | 111 | |
112 | 112 | // Add each apps' folder as allowed class path |
113 | - foreach($apps as $app) { |
|
113 | + foreach ($apps as $app) { |
|
114 | 114 | $path = self::getAppPath($app); |
115 | - if($path !== false) { |
|
115 | + if ($path !== false) { |
|
116 | 116 | self::registerAutoloading($app, $path); |
117 | 117 | } |
118 | 118 | } |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | public static function loadApp($app) { |
138 | 138 | self::$loadedApps[] = $app; |
139 | 139 | $appPath = self::getAppPath($app); |
140 | - if($appPath === false) { |
|
140 | + if ($appPath === false) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // in case someone calls loadApp() directly |
145 | 145 | self::registerAutoloading($app, $appPath); |
146 | 146 | |
147 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
148 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
147 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
148 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
149 | 149 | self::requireAppFile($app); |
150 | 150 | if (self::isType($app, array('authentication'))) { |
151 | 151 | // since authentication apps affect the "is app enabled for group" check, |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | // enabled for groups |
155 | 155 | self::$enabledAppsCache = array(); |
156 | 156 | } |
157 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
157 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $info = self::getAppInfo($app); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
179 | 179 | [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
180 | 180 | foreach ($plugins as $plugin) { |
181 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
181 | + if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
182 | 182 | $pluginInfo = [ |
183 | 183 | 'shareType' => $plugin['@attributes']['share-type'], |
184 | 184 | 'class' => $plugin['@value'], |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string $path |
198 | 198 | */ |
199 | 199 | public static function registerAutoloading($app, $path) { |
200 | - $key = $app . '-' . $path; |
|
201 | - if(isset(self::$alreadyRegistered[$key])) { |
|
200 | + $key = $app.'-'.$path; |
|
201 | + if (isset(self::$alreadyRegistered[$key])) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
@@ -208,17 +208,17 @@ discard block |
||
208 | 208 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
209 | 209 | \OC::$server->registerNamespace($app, $appNamespace); |
210 | 210 | |
211 | - if (file_exists($path . '/composer/autoload.php')) { |
|
212 | - require_once $path . '/composer/autoload.php'; |
|
211 | + if (file_exists($path.'/composer/autoload.php')) { |
|
212 | + require_once $path.'/composer/autoload.php'; |
|
213 | 213 | } else { |
214 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
214 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
215 | 215 | // Register on legacy autoloader |
216 | 216 | \OC::$loader->addValidRoot($path); |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Register Test namespace only when testing |
220 | 220 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
221 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
221 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | private static function requireAppFile($app) { |
231 | 231 | try { |
232 | 232 | // encapsulated here to avoid variable scope conflicts |
233 | - require_once $app . '/appinfo/app.php'; |
|
233 | + require_once $app.'/appinfo/app.php'; |
|
234 | 234 | } catch (Error $ex) { |
235 | 235 | \OC::$server->getLogger()->logException($ex); |
236 | 236 | if (!\OC::$server->getAppManager()->isShipped($app)) { |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public static function setAppTypes($app) { |
286 | 286 | $appData = self::getAppInfo($app); |
287 | - if(!is_array($appData)) { |
|
287 | + if (!is_array($appData)) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | } else { |
337 | 337 | $apps = $appManager->getEnabledAppsForUser($user); |
338 | 338 | } |
339 | - $apps = array_filter($apps, function ($app) { |
|
340 | - return $app !== 'files';//we add this manually |
|
339 | + $apps = array_filter($apps, function($app) { |
|
340 | + return $app !== 'files'; //we add this manually |
|
341 | 341 | }); |
342 | 342 | sort($apps); |
343 | 343 | array_unshift($apps, 'files'); |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $installer = \OC::$server->query(Installer::class); |
376 | 376 | $isDownloaded = $installer->isDownloaded($appId); |
377 | 377 | |
378 | - if(!$isDownloaded) { |
|
378 | + if (!$isDownloaded) { |
|
379 | 379 | $installer->downloadApp($appId); |
380 | 380 | } |
381 | 381 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | */ |
476 | 476 | public static function findAppInDirectories($appId) { |
477 | 477 | $sanitizedAppId = self::cleanAppId($appId); |
478 | - if($sanitizedAppId !== $appId) { |
|
478 | + if ($sanitizedAppId !== $appId) { |
|
479 | 479 | return false; |
480 | 480 | } |
481 | 481 | static $app_dir = array(); |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | $possibleApps = array(); |
488 | 488 | foreach (OC::$APPSROOTS as $dir) { |
489 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
489 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
490 | 490 | $possibleApps[] = $dir; |
491 | 491 | } |
492 | 492 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | if (($dir = self::findAppInDirectories($appId)) != false) { |
530 | - return $dir['path'] . '/' . $appId; |
|
530 | + return $dir['path'].'/'.$appId; |
|
531 | 531 | } |
532 | 532 | return false; |
533 | 533 | } |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public static function getAppWebPath($appId) { |
543 | 543 | if (($dir = self::findAppInDirectories($appId)) != false) { |
544 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
544 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
545 | 545 | } |
546 | 546 | return false; |
547 | 547 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @return string |
566 | 566 | */ |
567 | 567 | public static function getAppVersionByPath($path) { |
568 | - $infoFile = $path . '/appinfo/info.xml'; |
|
568 | + $infoFile = $path.'/appinfo/info.xml'; |
|
569 | 569 | $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
570 | 570 | return isset($appData['version']) ? $appData['version'] : ''; |
571 | 571 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * @param string $page |
666 | 666 | */ |
667 | 667 | public static function registerAdmin($app, $page) { |
668 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
668 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | * @param string $page |
675 | 675 | */ |
676 | 676 | public static function registerPersonal($app, $page) { |
677 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
677 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | |
704 | 704 | foreach (OC::$APPSROOTS as $apps_dir) { |
705 | 705 | if (!is_readable($apps_dir['path'])) { |
706 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
706 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
707 | 707 | continue; |
708 | 708 | } |
709 | 709 | $dh = opendir($apps_dir['path']); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | if (is_resource($dh)) { |
712 | 712 | while (($file = readdir($dh)) !== false) { |
713 | 713 | |
714 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
714 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
715 | 715 | |
716 | 716 | $apps[] = $file; |
717 | 717 | } |
@@ -744,12 +744,12 @@ discard block |
||
744 | 744 | |
745 | 745 | $info = OC_App::getAppInfo($app, false, $langCode); |
746 | 746 | if (!is_array($info)) { |
747 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
747 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
748 | 748 | continue; |
749 | 749 | } |
750 | 750 | |
751 | 751 | if (!isset($info['name'])) { |
752 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
752 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
753 | 753 | continue; |
754 | 754 | } |
755 | 755 | |
@@ -776,13 +776,13 @@ discard block |
||
776 | 776 | } |
777 | 777 | |
778 | 778 | $appPath = self::getAppPath($app); |
779 | - if($appPath !== false) { |
|
780 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
779 | + if ($appPath !== false) { |
|
780 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
781 | 781 | if (file_exists($appIcon)) { |
782 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
782 | + $info['preview'] = $urlGenerator->imagePath($app, $app.'.svg'); |
|
783 | 783 | $info['previewAsIcon'] = true; |
784 | 784 | } else { |
785 | - $appIcon = $appPath . '/img/app.svg'; |
|
785 | + $appIcon = $appPath.'/img/app.svg'; |
|
786 | 786 | if (file_exists($appIcon)) { |
787 | 787 | $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
788 | 788 | $info['previewAsIcon'] = true; |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | public static function getAppVersions() { |
908 | 908 | static $versions; |
909 | 909 | |
910 | - if(!$versions) { |
|
910 | + if (!$versions) { |
|
911 | 911 | $appConfig = \OC::$server->getAppConfig(); |
912 | 912 | $versions = $appConfig->getValues(false, 'installed_version'); |
913 | 913 | } |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | */ |
923 | 923 | public static function updateApp($appId) { |
924 | 924 | $appPath = self::getAppPath($appId); |
925 | - if($appPath === false) { |
|
925 | + if ($appPath === false) { |
|
926 | 926 | return false; |
927 | 927 | } |
928 | 928 | self::registerAutoloading($appId, $appPath); |
@@ -930,8 +930,8 @@ discard block |
||
930 | 930 | $appData = self::getAppInfo($appId); |
931 | 931 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
932 | 932 | |
933 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
934 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
933 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
934 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
935 | 935 | } else { |
936 | 936 | $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
937 | 937 | $ms->migrate(); |
@@ -943,26 +943,26 @@ discard block |
||
943 | 943 | \OC::$server->getAppManager()->getAppVersion($appId, false); |
944 | 944 | |
945 | 945 | // run upgrade code |
946 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
946 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
947 | 947 | self::loadApp($appId); |
948 | - include $appPath . '/appinfo/update.php'; |
|
948 | + include $appPath.'/appinfo/update.php'; |
|
949 | 949 | } |
950 | 950 | self::setupBackgroundJobs($appData['background-jobs']); |
951 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
951 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
952 | 952 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
953 | 953 | } |
954 | 954 | |
955 | 955 | //set remote/public handlers |
956 | 956 | if (array_key_exists('ocsid', $appData)) { |
957 | 957 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
958 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
958 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
959 | 959 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
960 | 960 | } |
961 | 961 | foreach ($appData['remote'] as $name => $path) { |
962 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
962 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
963 | 963 | } |
964 | 964 | foreach ($appData['public'] as $name => $path) { |
965 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
965 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
966 | 966 | } |
967 | 967 | |
968 | 968 | self::setAppTypes($appId); |
@@ -1032,17 +1032,17 @@ discard block |
||
1032 | 1032 | public static function getStorage($appId) { |
1033 | 1033 | if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
1034 | 1034 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
1035 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1035 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1036 | 1036 | if (!$view->file_exists($appId)) { |
1037 | 1037 | $view->mkdir($appId); |
1038 | 1038 | } |
1039 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1039 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1040 | 1040 | } else { |
1041 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1041 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
1042 | 1042 | return false; |
1043 | 1043 | } |
1044 | 1044 | } else { |
1045 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1045 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
1046 | 1046 | return false; |
1047 | 1047 | } |
1048 | 1048 | } |
@@ -1074,9 +1074,9 @@ discard block |
||
1074 | 1074 | |
1075 | 1075 | if ($attributeLang === $similarLang) { |
1076 | 1076 | $similarLangFallback = $option['@value']; |
1077 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1077 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1078 | 1078 | if ($similarLangFallback === false) { |
1079 | - $similarLangFallback = $option['@value']; |
|
1079 | + $similarLangFallback = $option['@value']; |
|
1080 | 1080 | } |
1081 | 1081 | } |
1082 | 1082 | } else { |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
1112 | 1112 | } else if (isset($data['description']) && is_string($data['description'])) { |
1113 | 1113 | $data['description'] = trim($data['description']); |
1114 | - } else { |
|
1114 | + } else { |
|
1115 | 1115 | $data['description'] = ''; |
1116 | 1116 | } |
1117 | 1117 |
@@ -40,284 +40,284 @@ |
||
40 | 40 | |
41 | 41 | class Storage extends Wrapper { |
42 | 42 | |
43 | - private $mountPoint; |
|
44 | - // remember already deleted files to avoid infinite loops if the trash bin |
|
45 | - // move files across storages |
|
46 | - private $deletedFiles = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * Disable trash logic |
|
50 | - * |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - private static $disableTrash = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * remember which file/folder was moved out of s shared folder |
|
57 | - * in this case we want to add a copy to the owners trash bin |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - private static $moveOutOfSharedFolder = []; |
|
62 | - |
|
63 | - /** @var IUserManager */ |
|
64 | - private $userManager; |
|
65 | - |
|
66 | - /** @var ILogger */ |
|
67 | - private $logger; |
|
68 | - |
|
69 | - /** @var EventDispatcher */ |
|
70 | - private $eventDispatcher; |
|
71 | - |
|
72 | - /** @var IRootFolder */ |
|
73 | - private $rootFolder; |
|
74 | - |
|
75 | - /** |
|
76 | - * Storage constructor. |
|
77 | - * |
|
78 | - * @param array $parameters |
|
79 | - * @param IUserManager|null $userManager |
|
80 | - * @param ILogger|null $logger |
|
81 | - * @param EventDispatcher|null $eventDispatcher |
|
82 | - * @param IRootFolder|null $rootFolder |
|
83 | - */ |
|
84 | - public function __construct($parameters, |
|
85 | - IUserManager $userManager = null, |
|
86 | - ILogger $logger = null, |
|
87 | - EventDispatcher $eventDispatcher = null, |
|
88 | - IRootFolder $rootFolder = null) { |
|
89 | - $this->mountPoint = $parameters['mountPoint']; |
|
90 | - $this->userManager = $userManager; |
|
91 | - $this->logger = $logger; |
|
92 | - $this->eventDispatcher = $eventDispatcher; |
|
93 | - $this->rootFolder = $rootFolder; |
|
94 | - parent::__construct($parameters); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @internal |
|
99 | - */ |
|
100 | - public static function preRenameHook($params) { |
|
101 | - // in cross-storage cases, a rename is a copy + unlink, |
|
102 | - // that last unlink must not go to trash, only exception: |
|
103 | - // if the file was moved from a shared storage to a local folder, |
|
104 | - // in this case the owner should get a copy in his trash bin so that |
|
105 | - // they can restore the files again |
|
106 | - |
|
107 | - $oldPath = $params['oldpath']; |
|
108 | - $newPath = dirname($params['newpath']); |
|
109 | - $currentUser = \OC::$server->getUserSession()->getUser(); |
|
110 | - |
|
111 | - $fileMovedOutOfSharedFolder = false; |
|
112 | - |
|
113 | - try { |
|
114 | - if ($currentUser) { |
|
115 | - $currentUserId = $currentUser->getUID(); |
|
116 | - |
|
117 | - $view = new View($currentUserId . '/files'); |
|
118 | - $fileInfo = $view->getFileInfo($oldPath); |
|
119 | - if ($fileInfo) { |
|
120 | - $sourceStorage = $fileInfo->getStorage(); |
|
121 | - $sourceOwner = $view->getOwner($oldPath); |
|
122 | - $targetOwner = $view->getOwner($newPath); |
|
123 | - |
|
124 | - if ($sourceOwner !== $targetOwner |
|
125 | - && $sourceStorage->instanceOfStorage('OCA\Files_Sharing\SharedStorage') |
|
126 | - ) { |
|
127 | - $fileMovedOutOfSharedFolder = true; |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } catch (\Exception $e) { |
|
132 | - // do nothing, in this case we just disable the trashbin and continue |
|
133 | - \OC::$server->getLogger()->logException($e, [ |
|
134 | - 'message' => 'Trashbin storage could not check if a file was moved out of a shared folder.', |
|
135 | - 'level' => \OCP\Util::DEBUG, |
|
136 | - 'app' => 'files_trashbin', |
|
137 | - ]); |
|
138 | - } |
|
139 | - |
|
140 | - if($fileMovedOutOfSharedFolder) { |
|
141 | - self::$moveOutOfSharedFolder['/' . $currentUserId . '/files' . $oldPath] = true; |
|
142 | - } else { |
|
143 | - self::$disableTrash = true; |
|
144 | - } |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @internal |
|
150 | - */ |
|
151 | - public static function postRenameHook($params) { |
|
152 | - self::$disableTrash = false; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Rename path1 to path2 by calling the wrapped storage. |
|
157 | - * |
|
158 | - * @param string $path1 first path |
|
159 | - * @param string $path2 second path |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - public function rename($path1, $path2) { |
|
163 | - $result = $this->storage->rename($path1, $path2); |
|
164 | - if ($result === false) { |
|
165 | - // when rename failed, the post_rename hook isn't triggered, |
|
166 | - // but we still want to reenable the trash logic |
|
167 | - self::$disableTrash = false; |
|
168 | - } |
|
169 | - return $result; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Deletes the given file by moving it into the trashbin. |
|
174 | - * |
|
175 | - * @param string $path path of file or folder to delete |
|
176 | - * |
|
177 | - * @return bool true if the operation succeeded, false otherwise |
|
178 | - */ |
|
179 | - public function unlink($path) { |
|
180 | - try { |
|
181 | - if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { |
|
182 | - $result = $this->doDelete($path, 'unlink', true); |
|
183 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); |
|
184 | - } else { |
|
185 | - $result = $this->doDelete($path, 'unlink'); |
|
186 | - } |
|
187 | - } catch (GenericEncryptionException $e) { |
|
188 | - // in case of a encryption exception we delete the file right away |
|
189 | - $this->logger->info( |
|
190 | - "Can't move file" . $path . |
|
191 | - "to the trash bin, therefore it was deleted right away"); |
|
192 | - |
|
193 | - $result = $this->storage->unlink($path); |
|
194 | - } |
|
195 | - |
|
196 | - return $result; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Deletes the given folder by moving it into the trashbin. |
|
201 | - * |
|
202 | - * @param string $path path of folder to delete |
|
203 | - * |
|
204 | - * @return bool true if the operation succeeded, false otherwise |
|
205 | - */ |
|
206 | - public function rmdir($path) { |
|
207 | - if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { |
|
208 | - $result = $this->doDelete($path, 'rmdir', true); |
|
209 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); |
|
210 | - } else { |
|
211 | - $result = $this->doDelete($path, 'rmdir'); |
|
212 | - } |
|
213 | - |
|
214 | - return $result; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * check if it is a file located in data/user/files only files in the |
|
219 | - * 'files' directory should be moved to the trash |
|
220 | - * |
|
221 | - * @param $path |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - protected function shouldMoveToTrash($path){ |
|
225 | - |
|
226 | - // check if there is a app which want to disable the trash bin for this file |
|
227 | - $fileId = $this->storage->getCache()->getId($path); |
|
228 | - $nodes = $this->rootFolder->getById($fileId); |
|
229 | - foreach ($nodes as $node) { |
|
230 | - $event = $this->createMoveToTrashEvent($node); |
|
231 | - $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); |
|
232 | - if ($event->shouldMoveToTrashBin() === false) { |
|
233 | - return false; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); |
|
238 | - $parts = explode('/', $normalized); |
|
239 | - if (count($parts) < 4) { |
|
240 | - return false; |
|
241 | - } |
|
242 | - |
|
243 | - if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) { |
|
244 | - return true; |
|
245 | - } |
|
246 | - |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * get move to trash event |
|
252 | - * |
|
253 | - * @param Node $node |
|
254 | - * @return MoveToTrashEvent |
|
255 | - */ |
|
256 | - protected function createMoveToTrashEvent(Node $node) { |
|
257 | - return new MoveToTrashEvent($node); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Run the delete operation with the given method |
|
262 | - * |
|
263 | - * @param string $path path of file or folder to delete |
|
264 | - * @param string $method either "unlink" or "rmdir" |
|
265 | - * @param bool $ownerOnly delete for owner only (if file gets moved out of a shared folder) |
|
266 | - * |
|
267 | - * @return bool true if the operation succeeded, false otherwise |
|
268 | - */ |
|
269 | - private function doDelete($path, $method, $ownerOnly = false) { |
|
270 | - if (self::$disableTrash |
|
271 | - || !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') |
|
272 | - || (pathinfo($path, PATHINFO_EXTENSION) === 'part') |
|
273 | - || $this->shouldMoveToTrash($path) === false |
|
274 | - ) { |
|
275 | - return call_user_func_array([$this->storage, $method], [$path]); |
|
276 | - } |
|
277 | - |
|
278 | - // check permissions before we continue, this is especially important for |
|
279 | - // shared files |
|
280 | - if (!$this->isDeletable($path)) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - |
|
284 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path, true, false, true); |
|
285 | - $result = true; |
|
286 | - $view = Filesystem::getView(); |
|
287 | - if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { |
|
288 | - $this->deletedFiles[$normalized] = $normalized; |
|
289 | - if ($filesPath = $view->getRelativePath($normalized)) { |
|
290 | - $filesPath = trim($filesPath, '/'); |
|
291 | - $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath, $ownerOnly); |
|
292 | - // in cross-storage cases the file will be copied |
|
293 | - // but not deleted, so we delete it here |
|
294 | - if ($result) { |
|
295 | - call_user_func_array([$this->storage, $method], [$path]); |
|
296 | - } |
|
297 | - } else { |
|
298 | - $result = call_user_func_array([$this->storage, $method], [$path]); |
|
299 | - } |
|
300 | - unset($this->deletedFiles[$normalized]); |
|
301 | - } else if ($this->storage->file_exists($path)) { |
|
302 | - $result = call_user_func_array([$this->storage, $method], [$path]); |
|
303 | - } |
|
304 | - |
|
305 | - return $result; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Setup the storate wrapper callback |
|
310 | - */ |
|
311 | - public static function setupStorage() { |
|
312 | - \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { |
|
313 | - return new \OCA\Files_Trashbin\Storage( |
|
314 | - array('storage' => $storage, 'mountPoint' => $mountPoint), |
|
315 | - \OC::$server->getUserManager(), |
|
316 | - \OC::$server->getLogger(), |
|
317 | - \OC::$server->getEventDispatcher(), |
|
318 | - \OC::$server->getLazyRootFolder() |
|
319 | - ); |
|
320 | - }, 1); |
|
321 | - } |
|
43 | + private $mountPoint; |
|
44 | + // remember already deleted files to avoid infinite loops if the trash bin |
|
45 | + // move files across storages |
|
46 | + private $deletedFiles = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * Disable trash logic |
|
50 | + * |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + private static $disableTrash = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * remember which file/folder was moved out of s shared folder |
|
57 | + * in this case we want to add a copy to the owners trash bin |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + private static $moveOutOfSharedFolder = []; |
|
62 | + |
|
63 | + /** @var IUserManager */ |
|
64 | + private $userManager; |
|
65 | + |
|
66 | + /** @var ILogger */ |
|
67 | + private $logger; |
|
68 | + |
|
69 | + /** @var EventDispatcher */ |
|
70 | + private $eventDispatcher; |
|
71 | + |
|
72 | + /** @var IRootFolder */ |
|
73 | + private $rootFolder; |
|
74 | + |
|
75 | + /** |
|
76 | + * Storage constructor. |
|
77 | + * |
|
78 | + * @param array $parameters |
|
79 | + * @param IUserManager|null $userManager |
|
80 | + * @param ILogger|null $logger |
|
81 | + * @param EventDispatcher|null $eventDispatcher |
|
82 | + * @param IRootFolder|null $rootFolder |
|
83 | + */ |
|
84 | + public function __construct($parameters, |
|
85 | + IUserManager $userManager = null, |
|
86 | + ILogger $logger = null, |
|
87 | + EventDispatcher $eventDispatcher = null, |
|
88 | + IRootFolder $rootFolder = null) { |
|
89 | + $this->mountPoint = $parameters['mountPoint']; |
|
90 | + $this->userManager = $userManager; |
|
91 | + $this->logger = $logger; |
|
92 | + $this->eventDispatcher = $eventDispatcher; |
|
93 | + $this->rootFolder = $rootFolder; |
|
94 | + parent::__construct($parameters); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @internal |
|
99 | + */ |
|
100 | + public static function preRenameHook($params) { |
|
101 | + // in cross-storage cases, a rename is a copy + unlink, |
|
102 | + // that last unlink must not go to trash, only exception: |
|
103 | + // if the file was moved from a shared storage to a local folder, |
|
104 | + // in this case the owner should get a copy in his trash bin so that |
|
105 | + // they can restore the files again |
|
106 | + |
|
107 | + $oldPath = $params['oldpath']; |
|
108 | + $newPath = dirname($params['newpath']); |
|
109 | + $currentUser = \OC::$server->getUserSession()->getUser(); |
|
110 | + |
|
111 | + $fileMovedOutOfSharedFolder = false; |
|
112 | + |
|
113 | + try { |
|
114 | + if ($currentUser) { |
|
115 | + $currentUserId = $currentUser->getUID(); |
|
116 | + |
|
117 | + $view = new View($currentUserId . '/files'); |
|
118 | + $fileInfo = $view->getFileInfo($oldPath); |
|
119 | + if ($fileInfo) { |
|
120 | + $sourceStorage = $fileInfo->getStorage(); |
|
121 | + $sourceOwner = $view->getOwner($oldPath); |
|
122 | + $targetOwner = $view->getOwner($newPath); |
|
123 | + |
|
124 | + if ($sourceOwner !== $targetOwner |
|
125 | + && $sourceStorage->instanceOfStorage('OCA\Files_Sharing\SharedStorage') |
|
126 | + ) { |
|
127 | + $fileMovedOutOfSharedFolder = true; |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } catch (\Exception $e) { |
|
132 | + // do nothing, in this case we just disable the trashbin and continue |
|
133 | + \OC::$server->getLogger()->logException($e, [ |
|
134 | + 'message' => 'Trashbin storage could not check if a file was moved out of a shared folder.', |
|
135 | + 'level' => \OCP\Util::DEBUG, |
|
136 | + 'app' => 'files_trashbin', |
|
137 | + ]); |
|
138 | + } |
|
139 | + |
|
140 | + if($fileMovedOutOfSharedFolder) { |
|
141 | + self::$moveOutOfSharedFolder['/' . $currentUserId . '/files' . $oldPath] = true; |
|
142 | + } else { |
|
143 | + self::$disableTrash = true; |
|
144 | + } |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @internal |
|
150 | + */ |
|
151 | + public static function postRenameHook($params) { |
|
152 | + self::$disableTrash = false; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Rename path1 to path2 by calling the wrapped storage. |
|
157 | + * |
|
158 | + * @param string $path1 first path |
|
159 | + * @param string $path2 second path |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + public function rename($path1, $path2) { |
|
163 | + $result = $this->storage->rename($path1, $path2); |
|
164 | + if ($result === false) { |
|
165 | + // when rename failed, the post_rename hook isn't triggered, |
|
166 | + // but we still want to reenable the trash logic |
|
167 | + self::$disableTrash = false; |
|
168 | + } |
|
169 | + return $result; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Deletes the given file by moving it into the trashbin. |
|
174 | + * |
|
175 | + * @param string $path path of file or folder to delete |
|
176 | + * |
|
177 | + * @return bool true if the operation succeeded, false otherwise |
|
178 | + */ |
|
179 | + public function unlink($path) { |
|
180 | + try { |
|
181 | + if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { |
|
182 | + $result = $this->doDelete($path, 'unlink', true); |
|
183 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); |
|
184 | + } else { |
|
185 | + $result = $this->doDelete($path, 'unlink'); |
|
186 | + } |
|
187 | + } catch (GenericEncryptionException $e) { |
|
188 | + // in case of a encryption exception we delete the file right away |
|
189 | + $this->logger->info( |
|
190 | + "Can't move file" . $path . |
|
191 | + "to the trash bin, therefore it was deleted right away"); |
|
192 | + |
|
193 | + $result = $this->storage->unlink($path); |
|
194 | + } |
|
195 | + |
|
196 | + return $result; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Deletes the given folder by moving it into the trashbin. |
|
201 | + * |
|
202 | + * @param string $path path of folder to delete |
|
203 | + * |
|
204 | + * @return bool true if the operation succeeded, false otherwise |
|
205 | + */ |
|
206 | + public function rmdir($path) { |
|
207 | + if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { |
|
208 | + $result = $this->doDelete($path, 'rmdir', true); |
|
209 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); |
|
210 | + } else { |
|
211 | + $result = $this->doDelete($path, 'rmdir'); |
|
212 | + } |
|
213 | + |
|
214 | + return $result; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * check if it is a file located in data/user/files only files in the |
|
219 | + * 'files' directory should be moved to the trash |
|
220 | + * |
|
221 | + * @param $path |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + protected function shouldMoveToTrash($path){ |
|
225 | + |
|
226 | + // check if there is a app which want to disable the trash bin for this file |
|
227 | + $fileId = $this->storage->getCache()->getId($path); |
|
228 | + $nodes = $this->rootFolder->getById($fileId); |
|
229 | + foreach ($nodes as $node) { |
|
230 | + $event = $this->createMoveToTrashEvent($node); |
|
231 | + $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); |
|
232 | + if ($event->shouldMoveToTrashBin() === false) { |
|
233 | + return false; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); |
|
238 | + $parts = explode('/', $normalized); |
|
239 | + if (count($parts) < 4) { |
|
240 | + return false; |
|
241 | + } |
|
242 | + |
|
243 | + if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) { |
|
244 | + return true; |
|
245 | + } |
|
246 | + |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * get move to trash event |
|
252 | + * |
|
253 | + * @param Node $node |
|
254 | + * @return MoveToTrashEvent |
|
255 | + */ |
|
256 | + protected function createMoveToTrashEvent(Node $node) { |
|
257 | + return new MoveToTrashEvent($node); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Run the delete operation with the given method |
|
262 | + * |
|
263 | + * @param string $path path of file or folder to delete |
|
264 | + * @param string $method either "unlink" or "rmdir" |
|
265 | + * @param bool $ownerOnly delete for owner only (if file gets moved out of a shared folder) |
|
266 | + * |
|
267 | + * @return bool true if the operation succeeded, false otherwise |
|
268 | + */ |
|
269 | + private function doDelete($path, $method, $ownerOnly = false) { |
|
270 | + if (self::$disableTrash |
|
271 | + || !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') |
|
272 | + || (pathinfo($path, PATHINFO_EXTENSION) === 'part') |
|
273 | + || $this->shouldMoveToTrash($path) === false |
|
274 | + ) { |
|
275 | + return call_user_func_array([$this->storage, $method], [$path]); |
|
276 | + } |
|
277 | + |
|
278 | + // check permissions before we continue, this is especially important for |
|
279 | + // shared files |
|
280 | + if (!$this->isDeletable($path)) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + |
|
284 | + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path, true, false, true); |
|
285 | + $result = true; |
|
286 | + $view = Filesystem::getView(); |
|
287 | + if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { |
|
288 | + $this->deletedFiles[$normalized] = $normalized; |
|
289 | + if ($filesPath = $view->getRelativePath($normalized)) { |
|
290 | + $filesPath = trim($filesPath, '/'); |
|
291 | + $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath, $ownerOnly); |
|
292 | + // in cross-storage cases the file will be copied |
|
293 | + // but not deleted, so we delete it here |
|
294 | + if ($result) { |
|
295 | + call_user_func_array([$this->storage, $method], [$path]); |
|
296 | + } |
|
297 | + } else { |
|
298 | + $result = call_user_func_array([$this->storage, $method], [$path]); |
|
299 | + } |
|
300 | + unset($this->deletedFiles[$normalized]); |
|
301 | + } else if ($this->storage->file_exists($path)) { |
|
302 | + $result = call_user_func_array([$this->storage, $method], [$path]); |
|
303 | + } |
|
304 | + |
|
305 | + return $result; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Setup the storate wrapper callback |
|
310 | + */ |
|
311 | + public static function setupStorage() { |
|
312 | + \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { |
|
313 | + return new \OCA\Files_Trashbin\Storage( |
|
314 | + array('storage' => $storage, 'mountPoint' => $mountPoint), |
|
315 | + \OC::$server->getUserManager(), |
|
316 | + \OC::$server->getLogger(), |
|
317 | + \OC::$server->getEventDispatcher(), |
|
318 | + \OC::$server->getLazyRootFolder() |
|
319 | + ); |
|
320 | + }, 1); |
|
321 | + } |
|
322 | 322 | |
323 | 323 | } |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | |
28 | 28 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
29 | 29 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
30 | - $l = \OC::$server->getL10N('core'); |
|
31 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
32 | - exit(); |
|
30 | + $l = \OC::$server->getL10N('core'); |
|
31 | + OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
32 | + exit(); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if (!array_key_exists('appid', $_POST)) { |
36 | - OC_JSON::error(); |
|
37 | - exit; |
|
36 | + OC_JSON::error(); |
|
37 | + exit; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $appId = (string)$_POST['appid']; |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | $installer = \OC::$server->query(\OC\Installer::class); |
46 | 46 | $result = $installer->removeApp($app); |
47 | 47 | if($result !== false) { |
48 | - // FIXME: Clear the cache - move that into some sane helper method |
|
49 | - \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-0'); |
|
50 | - \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-1'); |
|
51 | - OC_JSON::success(array('data' => array('appid' => $appId))); |
|
48 | + // FIXME: Clear the cache - move that into some sane helper method |
|
49 | + \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-0'); |
|
50 | + \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-1'); |
|
51 | + OC_JSON::success(array('data' => array('appid' => $appId))); |
|
52 | 52 | } else { |
53 | - $l = \OC::$server->getL10N('settings'); |
|
54 | - OC_JSON::error(array('data' => array( 'message' => $l->t("Couldn't remove app.") ))); |
|
53 | + $l = \OC::$server->getL10N('settings'); |
|
54 | + OC_JSON::error(array('data' => array( 'message' => $l->t("Couldn't remove app.") ))); |
|
55 | 55 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
29 | 29 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
30 | 30 | $l = \OC::$server->getL10N('core'); |
31 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
31 | + OC_JSON::error(array('data' => array('message' => $l->t('Password confirmation is required')))); |
|
32 | 32 | exit(); |
33 | 33 | } |
34 | 34 | |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | exit; |
38 | 38 | } |
39 | 39 | |
40 | -$appId = (string)$_POST['appid']; |
|
40 | +$appId = (string) $_POST['appid']; |
|
41 | 41 | $appId = OC_App::cleanAppId($appId); |
42 | 42 | |
43 | 43 | // FIXME: move to controller |
44 | 44 | /** @var \OC\Installer $installer */ |
45 | 45 | $installer = \OC::$server->query(\OC\Installer::class); |
46 | 46 | $result = $installer->removeApp($app); |
47 | -if($result !== false) { |
|
47 | +if ($result !== false) { |
|
48 | 48 | // FIXME: Clear the cache - move that into some sane helper method |
49 | 49 | \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-0'); |
50 | 50 | \OC::$server->getMemCacheFactory()->createDistributed('settings')->remove('listApps-1'); |
51 | 51 | OC_JSON::success(array('data' => array('appid' => $appId))); |
52 | 52 | } else { |
53 | 53 | $l = \OC::$server->getL10N('settings'); |
54 | - OC_JSON::error(array('data' => array( 'message' => $l->t("Couldn't remove app.") ))); |
|
54 | + OC_JSON::error(array('data' => array('message' => $l->t("Couldn't remove app.")))); |
|
55 | 55 | } |
@@ -45,401 +45,401 @@ |
||
45 | 45 | |
46 | 46 | class AppManager implements IAppManager { |
47 | 47 | |
48 | - /** |
|
49 | - * Apps with these types can not be enabled for certain groups only |
|
50 | - * @var string[] |
|
51 | - */ |
|
52 | - protected $protectedAppTypes = [ |
|
53 | - 'filesystem', |
|
54 | - 'prelogin', |
|
55 | - 'authentication', |
|
56 | - 'logging', |
|
57 | - 'prevent_group_restriction', |
|
58 | - ]; |
|
59 | - |
|
60 | - /** @var IUserSession */ |
|
61 | - private $userSession; |
|
62 | - |
|
63 | - /** @var AppConfig */ |
|
64 | - private $appConfig; |
|
65 | - |
|
66 | - /** @var IGroupManager */ |
|
67 | - private $groupManager; |
|
68 | - |
|
69 | - /** @var ICacheFactory */ |
|
70 | - private $memCacheFactory; |
|
71 | - |
|
72 | - /** @var EventDispatcherInterface */ |
|
73 | - private $dispatcher; |
|
74 | - |
|
75 | - /** @var string[] $appId => $enabled */ |
|
76 | - private $installedAppsCache; |
|
77 | - |
|
78 | - /** @var string[] */ |
|
79 | - private $shippedApps; |
|
80 | - |
|
81 | - /** @var string[] */ |
|
82 | - private $alwaysEnabled; |
|
83 | - |
|
84 | - /** @var array */ |
|
85 | - private $appInfos = []; |
|
86 | - |
|
87 | - /** @var array */ |
|
88 | - private $appVersions = []; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param IUserSession $userSession |
|
92 | - * @param AppConfig $appConfig |
|
93 | - * @param IGroupManager $groupManager |
|
94 | - * @param ICacheFactory $memCacheFactory |
|
95 | - * @param EventDispatcherInterface $dispatcher |
|
96 | - */ |
|
97 | - public function __construct(IUserSession $userSession, |
|
98 | - IAppConfig $appConfig = null, |
|
99 | - IGroupManager $groupManager, |
|
100 | - ICacheFactory $memCacheFactory, |
|
101 | - EventDispatcherInterface $dispatcher) { |
|
102 | - $this->userSession = $userSession; |
|
103 | - $this->appConfig = $appConfig; |
|
104 | - $this->groupManager = $groupManager; |
|
105 | - $this->memCacheFactory = $memCacheFactory; |
|
106 | - $this->dispatcher = $dispatcher; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string[] $appId => $enabled |
|
111 | - */ |
|
112 | - private function getInstalledAppsValues() { |
|
113 | - if (!$this->installedAppsCache) { |
|
114 | - $values = $this->appConfig->getValues(false, 'enabled'); |
|
115 | - |
|
116 | - $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
117 | - foreach($alwaysEnabledApps as $appId) { |
|
118 | - $values[$appId] = 'yes'; |
|
119 | - } |
|
120 | - |
|
121 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
122 | - return $value !== 'no'; |
|
123 | - }); |
|
124 | - ksort($this->installedAppsCache); |
|
125 | - } |
|
126 | - return $this->installedAppsCache; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * List all installed apps |
|
131 | - * |
|
132 | - * @return string[] |
|
133 | - */ |
|
134 | - public function getInstalledApps() { |
|
135 | - return array_keys($this->getInstalledAppsValues()); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * List all apps enabled for a user |
|
140 | - * |
|
141 | - * @param \OCP\IUser $user |
|
142 | - * @return string[] |
|
143 | - */ |
|
144 | - public function getEnabledAppsForUser(IUser $user) { |
|
145 | - $apps = $this->getInstalledAppsValues(); |
|
146 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
147 | - return $this->checkAppForUser($enabled, $user); |
|
148 | - }); |
|
149 | - return array_keys($appsForUser); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Check if an app is enabled for user |
|
154 | - * |
|
155 | - * @param string $appId |
|
156 | - * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
157 | - * @return bool |
|
158 | - */ |
|
159 | - public function isEnabledForUser($appId, $user = null) { |
|
160 | - if ($this->isAlwaysEnabled($appId)) { |
|
161 | - return true; |
|
162 | - } |
|
163 | - if ($user === null) { |
|
164 | - $user = $this->userSession->getUser(); |
|
165 | - } |
|
166 | - $installedApps = $this->getInstalledAppsValues(); |
|
167 | - if (isset($installedApps[$appId])) { |
|
168 | - return $this->checkAppForUser($installedApps[$appId], $user); |
|
169 | - } else { |
|
170 | - return false; |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $enabled |
|
176 | - * @param IUser $user |
|
177 | - * @return bool |
|
178 | - */ |
|
179 | - private function checkAppForUser($enabled, $user) { |
|
180 | - if ($enabled === 'yes') { |
|
181 | - return true; |
|
182 | - } elseif ($user === null) { |
|
183 | - return false; |
|
184 | - } else { |
|
185 | - if(empty($enabled)){ |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - $groupIds = json_decode($enabled); |
|
190 | - |
|
191 | - if (!is_array($groupIds)) { |
|
192 | - $jsonError = json_last_error(); |
|
193 | - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
194 | - return false; |
|
195 | - } |
|
196 | - |
|
197 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
198 | - foreach ($userGroups as $groupId) { |
|
199 | - if (in_array($groupId, $groupIds, true)) { |
|
200 | - return true; |
|
201 | - } |
|
202 | - } |
|
203 | - return false; |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Check if an app is installed in the instance |
|
209 | - * |
|
210 | - * @param string $appId |
|
211 | - * @return bool |
|
212 | - */ |
|
213 | - public function isInstalled($appId) { |
|
214 | - $installedApps = $this->getInstalledAppsValues(); |
|
215 | - return isset($installedApps[$appId]); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Enable an app for every user |
|
220 | - * |
|
221 | - * @param string $appId |
|
222 | - * @throws AppPathNotFoundException |
|
223 | - */ |
|
224 | - public function enableApp($appId) { |
|
225 | - // Check if app exists |
|
226 | - $this->getAppPath($appId); |
|
227 | - |
|
228 | - $this->installedAppsCache[$appId] = 'yes'; |
|
229 | - $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
230 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
231 | - ManagerEvent::EVENT_APP_ENABLE, $appId |
|
232 | - )); |
|
233 | - $this->clearAppsCache(); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Whether a list of types contains a protected app type |
|
238 | - * |
|
239 | - * @param string[] $types |
|
240 | - * @return bool |
|
241 | - */ |
|
242 | - public function hasProtectedAppType($types) { |
|
243 | - if (empty($types)) { |
|
244 | - return false; |
|
245 | - } |
|
246 | - |
|
247 | - $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
248 | - return !empty($protectedTypes); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Enable an app only for specific groups |
|
253 | - * |
|
254 | - * @param string $appId |
|
255 | - * @param \OCP\IGroup[] $groups |
|
256 | - * @throws \Exception if app can't be enabled for groups |
|
257 | - */ |
|
258 | - public function enableAppForGroups($appId, $groups) { |
|
259 | - $info = $this->getAppInfo($appId); |
|
260 | - if (!empty($info['types'])) { |
|
261 | - $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
262 | - if (!empty($protectedTypes)) { |
|
263 | - throw new \Exception("$appId can't be enabled for groups."); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - $groupIds = array_map(function ($group) { |
|
268 | - /** @var \OCP\IGroup $group */ |
|
269 | - return $group->getGID(); |
|
270 | - }, $groups); |
|
271 | - $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
272 | - $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
273 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
274 | - ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
275 | - )); |
|
276 | - $this->clearAppsCache(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Disable an app for every user |
|
281 | - * |
|
282 | - * @param string $appId |
|
283 | - * @throws \Exception if app can't be disabled |
|
284 | - */ |
|
285 | - public function disableApp($appId) { |
|
286 | - if ($this->isAlwaysEnabled($appId)) { |
|
287 | - throw new \Exception("$appId can't be disabled."); |
|
288 | - } |
|
289 | - unset($this->installedAppsCache[$appId]); |
|
290 | - $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
291 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
292 | - ManagerEvent::EVENT_APP_DISABLE, $appId |
|
293 | - )); |
|
294 | - $this->clearAppsCache(); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get the directory for the given app. |
|
299 | - * |
|
300 | - * @param string $appId |
|
301 | - * @return string |
|
302 | - * @throws AppPathNotFoundException if app folder can't be found |
|
303 | - */ |
|
304 | - public function getAppPath($appId) { |
|
305 | - $appPath = \OC_App::getAppPath($appId); |
|
306 | - if($appPath === false) { |
|
307 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
308 | - } |
|
309 | - return $appPath; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Clear the cached list of apps when enabling/disabling an app |
|
314 | - */ |
|
315 | - public function clearAppsCache() { |
|
316 | - $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
317 | - $settingsMemCache->clear('listApps'); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Returns a list of apps that need upgrade |
|
322 | - * |
|
323 | - * @param string $version Nextcloud version as array of version components |
|
324 | - * @return array list of app info from apps that need an upgrade |
|
325 | - * |
|
326 | - * @internal |
|
327 | - */ |
|
328 | - public function getAppsNeedingUpgrade($version) { |
|
329 | - $appsToUpgrade = []; |
|
330 | - $apps = $this->getInstalledApps(); |
|
331 | - foreach ($apps as $appId) { |
|
332 | - $appInfo = $this->getAppInfo($appId); |
|
333 | - $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
334 | - if ($appDbVersion |
|
335 | - && isset($appInfo['version']) |
|
336 | - && version_compare($appInfo['version'], $appDbVersion, '>') |
|
337 | - && \OC_App::isAppCompatible($version, $appInfo) |
|
338 | - ) { |
|
339 | - $appsToUpgrade[] = $appInfo; |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - return $appsToUpgrade; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Returns the app information from "appinfo/info.xml". |
|
348 | - * |
|
349 | - * @param string $appId app id |
|
350 | - * |
|
351 | - * @param bool $path |
|
352 | - * @param null $lang |
|
353 | - * @return array app info |
|
354 | - */ |
|
355 | - public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
356 | - if ($path) { |
|
357 | - $file = $appId; |
|
358 | - } else { |
|
359 | - if ($lang === null && isset($this->appInfos[$appId])) { |
|
360 | - return $this->appInfos[$appId]; |
|
361 | - } |
|
362 | - try { |
|
363 | - $appPath = $this->getAppPath($appId); |
|
364 | - } catch (AppPathNotFoundException $e) { |
|
365 | - return null; |
|
366 | - } |
|
367 | - $file = $appPath . '/appinfo/info.xml'; |
|
368 | - } |
|
369 | - |
|
370 | - $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
371 | - $data = $parser->parse($file); |
|
372 | - |
|
373 | - if (is_array($data)) { |
|
374 | - $data = \OC_App::parseAppInfo($data, $lang); |
|
375 | - } |
|
376 | - |
|
377 | - if ($lang === null) { |
|
378 | - $this->appInfos[$appId] = $data; |
|
379 | - } |
|
380 | - |
|
381 | - return $data; |
|
382 | - } |
|
383 | - |
|
384 | - public function getAppVersion(string $appId, bool $useCache = true) { |
|
385 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
386 | - $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
387 | - $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
|
388 | - } |
|
389 | - return $this->appVersions[$appId]; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns a list of apps incompatible with the given version |
|
394 | - * |
|
395 | - * @param string $version Nextcloud version as array of version components |
|
396 | - * |
|
397 | - * @return array list of app info from incompatible apps |
|
398 | - * |
|
399 | - * @internal |
|
400 | - */ |
|
401 | - public function getIncompatibleApps($version) { |
|
402 | - $apps = $this->getInstalledApps(); |
|
403 | - $incompatibleApps = array(); |
|
404 | - foreach ($apps as $appId) { |
|
405 | - $info = $this->getAppInfo($appId); |
|
406 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
407 | - $incompatibleApps[] = $info; |
|
408 | - } |
|
409 | - } |
|
410 | - return $incompatibleApps; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * @inheritdoc |
|
415 | - */ |
|
416 | - public function isShipped($appId) { |
|
417 | - $this->loadShippedJson(); |
|
418 | - return in_array($appId, $this->shippedApps, true); |
|
419 | - } |
|
420 | - |
|
421 | - private function isAlwaysEnabled($appId) { |
|
422 | - $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
423 | - return in_array($appId, $alwaysEnabled, true); |
|
424 | - } |
|
425 | - |
|
426 | - private function loadShippedJson() { |
|
427 | - if ($this->shippedApps === null) { |
|
428 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
429 | - if (!file_exists($shippedJson)) { |
|
430 | - throw new \Exception("File not found: $shippedJson"); |
|
431 | - } |
|
432 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
433 | - $this->shippedApps = $content['shippedApps']; |
|
434 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * @inheritdoc |
|
440 | - */ |
|
441 | - public function getAlwaysEnabledApps() { |
|
442 | - $this->loadShippedJson(); |
|
443 | - return $this->alwaysEnabled; |
|
444 | - } |
|
48 | + /** |
|
49 | + * Apps with these types can not be enabled for certain groups only |
|
50 | + * @var string[] |
|
51 | + */ |
|
52 | + protected $protectedAppTypes = [ |
|
53 | + 'filesystem', |
|
54 | + 'prelogin', |
|
55 | + 'authentication', |
|
56 | + 'logging', |
|
57 | + 'prevent_group_restriction', |
|
58 | + ]; |
|
59 | + |
|
60 | + /** @var IUserSession */ |
|
61 | + private $userSession; |
|
62 | + |
|
63 | + /** @var AppConfig */ |
|
64 | + private $appConfig; |
|
65 | + |
|
66 | + /** @var IGroupManager */ |
|
67 | + private $groupManager; |
|
68 | + |
|
69 | + /** @var ICacheFactory */ |
|
70 | + private $memCacheFactory; |
|
71 | + |
|
72 | + /** @var EventDispatcherInterface */ |
|
73 | + private $dispatcher; |
|
74 | + |
|
75 | + /** @var string[] $appId => $enabled */ |
|
76 | + private $installedAppsCache; |
|
77 | + |
|
78 | + /** @var string[] */ |
|
79 | + private $shippedApps; |
|
80 | + |
|
81 | + /** @var string[] */ |
|
82 | + private $alwaysEnabled; |
|
83 | + |
|
84 | + /** @var array */ |
|
85 | + private $appInfos = []; |
|
86 | + |
|
87 | + /** @var array */ |
|
88 | + private $appVersions = []; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param IUserSession $userSession |
|
92 | + * @param AppConfig $appConfig |
|
93 | + * @param IGroupManager $groupManager |
|
94 | + * @param ICacheFactory $memCacheFactory |
|
95 | + * @param EventDispatcherInterface $dispatcher |
|
96 | + */ |
|
97 | + public function __construct(IUserSession $userSession, |
|
98 | + IAppConfig $appConfig = null, |
|
99 | + IGroupManager $groupManager, |
|
100 | + ICacheFactory $memCacheFactory, |
|
101 | + EventDispatcherInterface $dispatcher) { |
|
102 | + $this->userSession = $userSession; |
|
103 | + $this->appConfig = $appConfig; |
|
104 | + $this->groupManager = $groupManager; |
|
105 | + $this->memCacheFactory = $memCacheFactory; |
|
106 | + $this->dispatcher = $dispatcher; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string[] $appId => $enabled |
|
111 | + */ |
|
112 | + private function getInstalledAppsValues() { |
|
113 | + if (!$this->installedAppsCache) { |
|
114 | + $values = $this->appConfig->getValues(false, 'enabled'); |
|
115 | + |
|
116 | + $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
117 | + foreach($alwaysEnabledApps as $appId) { |
|
118 | + $values[$appId] = 'yes'; |
|
119 | + } |
|
120 | + |
|
121 | + $this->installedAppsCache = array_filter($values, function ($value) { |
|
122 | + return $value !== 'no'; |
|
123 | + }); |
|
124 | + ksort($this->installedAppsCache); |
|
125 | + } |
|
126 | + return $this->installedAppsCache; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * List all installed apps |
|
131 | + * |
|
132 | + * @return string[] |
|
133 | + */ |
|
134 | + public function getInstalledApps() { |
|
135 | + return array_keys($this->getInstalledAppsValues()); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * List all apps enabled for a user |
|
140 | + * |
|
141 | + * @param \OCP\IUser $user |
|
142 | + * @return string[] |
|
143 | + */ |
|
144 | + public function getEnabledAppsForUser(IUser $user) { |
|
145 | + $apps = $this->getInstalledAppsValues(); |
|
146 | + $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
147 | + return $this->checkAppForUser($enabled, $user); |
|
148 | + }); |
|
149 | + return array_keys($appsForUser); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Check if an app is enabled for user |
|
154 | + * |
|
155 | + * @param string $appId |
|
156 | + * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
157 | + * @return bool |
|
158 | + */ |
|
159 | + public function isEnabledForUser($appId, $user = null) { |
|
160 | + if ($this->isAlwaysEnabled($appId)) { |
|
161 | + return true; |
|
162 | + } |
|
163 | + if ($user === null) { |
|
164 | + $user = $this->userSession->getUser(); |
|
165 | + } |
|
166 | + $installedApps = $this->getInstalledAppsValues(); |
|
167 | + if (isset($installedApps[$appId])) { |
|
168 | + return $this->checkAppForUser($installedApps[$appId], $user); |
|
169 | + } else { |
|
170 | + return false; |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $enabled |
|
176 | + * @param IUser $user |
|
177 | + * @return bool |
|
178 | + */ |
|
179 | + private function checkAppForUser($enabled, $user) { |
|
180 | + if ($enabled === 'yes') { |
|
181 | + return true; |
|
182 | + } elseif ($user === null) { |
|
183 | + return false; |
|
184 | + } else { |
|
185 | + if(empty($enabled)){ |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + $groupIds = json_decode($enabled); |
|
190 | + |
|
191 | + if (!is_array($groupIds)) { |
|
192 | + $jsonError = json_last_error(); |
|
193 | + \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
194 | + return false; |
|
195 | + } |
|
196 | + |
|
197 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
198 | + foreach ($userGroups as $groupId) { |
|
199 | + if (in_array($groupId, $groupIds, true)) { |
|
200 | + return true; |
|
201 | + } |
|
202 | + } |
|
203 | + return false; |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Check if an app is installed in the instance |
|
209 | + * |
|
210 | + * @param string $appId |
|
211 | + * @return bool |
|
212 | + */ |
|
213 | + public function isInstalled($appId) { |
|
214 | + $installedApps = $this->getInstalledAppsValues(); |
|
215 | + return isset($installedApps[$appId]); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Enable an app for every user |
|
220 | + * |
|
221 | + * @param string $appId |
|
222 | + * @throws AppPathNotFoundException |
|
223 | + */ |
|
224 | + public function enableApp($appId) { |
|
225 | + // Check if app exists |
|
226 | + $this->getAppPath($appId); |
|
227 | + |
|
228 | + $this->installedAppsCache[$appId] = 'yes'; |
|
229 | + $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
230 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
231 | + ManagerEvent::EVENT_APP_ENABLE, $appId |
|
232 | + )); |
|
233 | + $this->clearAppsCache(); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Whether a list of types contains a protected app type |
|
238 | + * |
|
239 | + * @param string[] $types |
|
240 | + * @return bool |
|
241 | + */ |
|
242 | + public function hasProtectedAppType($types) { |
|
243 | + if (empty($types)) { |
|
244 | + return false; |
|
245 | + } |
|
246 | + |
|
247 | + $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
248 | + return !empty($protectedTypes); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Enable an app only for specific groups |
|
253 | + * |
|
254 | + * @param string $appId |
|
255 | + * @param \OCP\IGroup[] $groups |
|
256 | + * @throws \Exception if app can't be enabled for groups |
|
257 | + */ |
|
258 | + public function enableAppForGroups($appId, $groups) { |
|
259 | + $info = $this->getAppInfo($appId); |
|
260 | + if (!empty($info['types'])) { |
|
261 | + $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
262 | + if (!empty($protectedTypes)) { |
|
263 | + throw new \Exception("$appId can't be enabled for groups."); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + $groupIds = array_map(function ($group) { |
|
268 | + /** @var \OCP\IGroup $group */ |
|
269 | + return $group->getGID(); |
|
270 | + }, $groups); |
|
271 | + $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
272 | + $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
273 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
274 | + ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
275 | + )); |
|
276 | + $this->clearAppsCache(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Disable an app for every user |
|
281 | + * |
|
282 | + * @param string $appId |
|
283 | + * @throws \Exception if app can't be disabled |
|
284 | + */ |
|
285 | + public function disableApp($appId) { |
|
286 | + if ($this->isAlwaysEnabled($appId)) { |
|
287 | + throw new \Exception("$appId can't be disabled."); |
|
288 | + } |
|
289 | + unset($this->installedAppsCache[$appId]); |
|
290 | + $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
291 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
292 | + ManagerEvent::EVENT_APP_DISABLE, $appId |
|
293 | + )); |
|
294 | + $this->clearAppsCache(); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get the directory for the given app. |
|
299 | + * |
|
300 | + * @param string $appId |
|
301 | + * @return string |
|
302 | + * @throws AppPathNotFoundException if app folder can't be found |
|
303 | + */ |
|
304 | + public function getAppPath($appId) { |
|
305 | + $appPath = \OC_App::getAppPath($appId); |
|
306 | + if($appPath === false) { |
|
307 | + throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
308 | + } |
|
309 | + return $appPath; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Clear the cached list of apps when enabling/disabling an app |
|
314 | + */ |
|
315 | + public function clearAppsCache() { |
|
316 | + $settingsMemCache = $this->memCacheFactory->createDistributed('settings'); |
|
317 | + $settingsMemCache->clear('listApps'); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Returns a list of apps that need upgrade |
|
322 | + * |
|
323 | + * @param string $version Nextcloud version as array of version components |
|
324 | + * @return array list of app info from apps that need an upgrade |
|
325 | + * |
|
326 | + * @internal |
|
327 | + */ |
|
328 | + public function getAppsNeedingUpgrade($version) { |
|
329 | + $appsToUpgrade = []; |
|
330 | + $apps = $this->getInstalledApps(); |
|
331 | + foreach ($apps as $appId) { |
|
332 | + $appInfo = $this->getAppInfo($appId); |
|
333 | + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
334 | + if ($appDbVersion |
|
335 | + && isset($appInfo['version']) |
|
336 | + && version_compare($appInfo['version'], $appDbVersion, '>') |
|
337 | + && \OC_App::isAppCompatible($version, $appInfo) |
|
338 | + ) { |
|
339 | + $appsToUpgrade[] = $appInfo; |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + return $appsToUpgrade; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Returns the app information from "appinfo/info.xml". |
|
348 | + * |
|
349 | + * @param string $appId app id |
|
350 | + * |
|
351 | + * @param bool $path |
|
352 | + * @param null $lang |
|
353 | + * @return array app info |
|
354 | + */ |
|
355 | + public function getAppInfo(string $appId, bool $path = false, $lang = null) { |
|
356 | + if ($path) { |
|
357 | + $file = $appId; |
|
358 | + } else { |
|
359 | + if ($lang === null && isset($this->appInfos[$appId])) { |
|
360 | + return $this->appInfos[$appId]; |
|
361 | + } |
|
362 | + try { |
|
363 | + $appPath = $this->getAppPath($appId); |
|
364 | + } catch (AppPathNotFoundException $e) { |
|
365 | + return null; |
|
366 | + } |
|
367 | + $file = $appPath . '/appinfo/info.xml'; |
|
368 | + } |
|
369 | + |
|
370 | + $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
|
371 | + $data = $parser->parse($file); |
|
372 | + |
|
373 | + if (is_array($data)) { |
|
374 | + $data = \OC_App::parseAppInfo($data, $lang); |
|
375 | + } |
|
376 | + |
|
377 | + if ($lang === null) { |
|
378 | + $this->appInfos[$appId] = $data; |
|
379 | + } |
|
380 | + |
|
381 | + return $data; |
|
382 | + } |
|
383 | + |
|
384 | + public function getAppVersion(string $appId, bool $useCache = true) { |
|
385 | + if(!$useCache || !isset($this->appVersions[$appId])) { |
|
386 | + $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
|
387 | + $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
|
388 | + } |
|
389 | + return $this->appVersions[$appId]; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns a list of apps incompatible with the given version |
|
394 | + * |
|
395 | + * @param string $version Nextcloud version as array of version components |
|
396 | + * |
|
397 | + * @return array list of app info from incompatible apps |
|
398 | + * |
|
399 | + * @internal |
|
400 | + */ |
|
401 | + public function getIncompatibleApps($version) { |
|
402 | + $apps = $this->getInstalledApps(); |
|
403 | + $incompatibleApps = array(); |
|
404 | + foreach ($apps as $appId) { |
|
405 | + $info = $this->getAppInfo($appId); |
|
406 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
407 | + $incompatibleApps[] = $info; |
|
408 | + } |
|
409 | + } |
|
410 | + return $incompatibleApps; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * @inheritdoc |
|
415 | + */ |
|
416 | + public function isShipped($appId) { |
|
417 | + $this->loadShippedJson(); |
|
418 | + return in_array($appId, $this->shippedApps, true); |
|
419 | + } |
|
420 | + |
|
421 | + private function isAlwaysEnabled($appId) { |
|
422 | + $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
423 | + return in_array($appId, $alwaysEnabled, true); |
|
424 | + } |
|
425 | + |
|
426 | + private function loadShippedJson() { |
|
427 | + if ($this->shippedApps === null) { |
|
428 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
429 | + if (!file_exists($shippedJson)) { |
|
430 | + throw new \Exception("File not found: $shippedJson"); |
|
431 | + } |
|
432 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
433 | + $this->shippedApps = $content['shippedApps']; |
|
434 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * @inheritdoc |
|
440 | + */ |
|
441 | + public function getAlwaysEnabledApps() { |
|
442 | + $this->loadShippedJson(); |
|
443 | + return $this->alwaysEnabled; |
|
444 | + } |
|
445 | 445 | } |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $values = $this->appConfig->getValues(false, 'enabled'); |
115 | 115 | |
116 | 116 | $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
117 | - foreach($alwaysEnabledApps as $appId) { |
|
117 | + foreach ($alwaysEnabledApps as $appId) { |
|
118 | 118 | $values[$appId] = 'yes'; |
119 | 119 | } |
120 | 120 | |
121 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
121 | + $this->installedAppsCache = array_filter($values, function($value) { |
|
122 | 122 | return $value !== 'no'; |
123 | 123 | }); |
124 | 124 | ksort($this->installedAppsCache); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function getEnabledAppsForUser(IUser $user) { |
145 | 145 | $apps = $this->getInstalledAppsValues(); |
146 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
146 | + $appsForUser = array_filter($apps, function($enabled) use ($user) { |
|
147 | 147 | return $this->checkAppForUser($enabled, $user); |
148 | 148 | }); |
149 | 149 | return array_keys($appsForUser); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } elseif ($user === null) { |
183 | 183 | return false; |
184 | 184 | } else { |
185 | - if(empty($enabled)){ |
|
185 | + if (empty($enabled)) { |
|
186 | 186 | return false; |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | if (!is_array($groupIds)) { |
192 | 192 | $jsonError = json_last_error(); |
193 | - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
193 | + \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: '.print_r($enabled, true).' - json error code: '.$jsonError, ['app' => 'lib']); |
|
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | - $groupIds = array_map(function ($group) { |
|
267 | + $groupIds = array_map(function($group) { |
|
268 | 268 | /** @var \OCP\IGroup $group */ |
269 | 269 | return $group->getGID(); |
270 | 270 | }, $groups); |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function getAppPath($appId) { |
305 | 305 | $appPath = \OC_App::getAppPath($appId); |
306 | - if($appPath === false) { |
|
307 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
306 | + if ($appPath === false) { |
|
307 | + throw new AppPathNotFoundException('Could not find path for '.$appId); |
|
308 | 308 | } |
309 | 309 | return $appPath; |
310 | 310 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | } catch (AppPathNotFoundException $e) { |
365 | 365 | return null; |
366 | 366 | } |
367 | - $file = $appPath . '/appinfo/info.xml'; |
|
367 | + $file = $appPath.'/appinfo/info.xml'; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $parser = new InfoParser($this->memCacheFactory->createLocal('core.appinfo')); |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | } |
383 | 383 | |
384 | 384 | public function getAppVersion(string $appId, bool $useCache = true) { |
385 | - if(!$useCache || !isset($this->appVersions[$appId])) { |
|
385 | + if (!$useCache || !isset($this->appVersions[$appId])) { |
|
386 | 386 | $appInfo = \OC::$server->getAppManager()->getAppInfo($appId); |
387 | 387 | $this->appVersions[$appId] = ($appInfo !== null) ? $appInfo['version'] : '0'; |
388 | 388 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | private function loadShippedJson() { |
427 | 427 | if ($this->shippedApps === null) { |
428 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
428 | + $shippedJson = \OC::$SERVERROOT.'/core/shipped.json'; |
|
429 | 429 | if (!file_exists($shippedJson)) { |
430 | 430 | throw new \Exception("File not found: $shippedJson"); |
431 | 431 | } |
@@ -57,572 +57,572 @@ |
||
57 | 57 | * This class provides the functionality needed to install, update and remove apps |
58 | 58 | */ |
59 | 59 | class Installer { |
60 | - /** @var AppFetcher */ |
|
61 | - private $appFetcher; |
|
62 | - /** @var IClientService */ |
|
63 | - private $clientService; |
|
64 | - /** @var ITempManager */ |
|
65 | - private $tempManager; |
|
66 | - /** @var ILogger */ |
|
67 | - private $logger; |
|
68 | - /** @var IConfig */ |
|
69 | - private $config; |
|
70 | - /** @var array - for caching the result of app fetcher */ |
|
71 | - private $apps = null; |
|
72 | - /** @var bool|null - for caching the result of the ready status */ |
|
73 | - private $isInstanceReadyForUpdates = null; |
|
74 | - |
|
75 | - /** |
|
76 | - * @param AppFetcher $appFetcher |
|
77 | - * @param IClientService $clientService |
|
78 | - * @param ITempManager $tempManager |
|
79 | - * @param ILogger $logger |
|
80 | - * @param IConfig $config |
|
81 | - */ |
|
82 | - public function __construct(AppFetcher $appFetcher, |
|
83 | - IClientService $clientService, |
|
84 | - ITempManager $tempManager, |
|
85 | - ILogger $logger, |
|
86 | - IConfig $config) { |
|
87 | - $this->appFetcher = $appFetcher; |
|
88 | - $this->clientService = $clientService; |
|
89 | - $this->tempManager = $tempManager; |
|
90 | - $this->logger = $logger; |
|
91 | - $this->config = $config; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Installs an app that is located in one of the app folders already |
|
96 | - * |
|
97 | - * @param string $appId App to install |
|
98 | - * @throws \Exception |
|
99 | - * @return string app ID |
|
100 | - */ |
|
101 | - public function installApp($appId) { |
|
102 | - $app = \OC_App::findAppInDirectories($appId); |
|
103 | - if($app === false) { |
|
104 | - throw new \Exception('App not found in any app directory'); |
|
105 | - } |
|
106 | - |
|
107 | - $basedir = $app['path'].'/'.$appId; |
|
108 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
109 | - |
|
110 | - $l = \OC::$server->getL10N('core'); |
|
111 | - |
|
112 | - if(!is_array($info)) { |
|
113 | - throw new \Exception( |
|
114 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
115 | - [$info['name']] |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - $version = \OCP\Util::getVersion(); |
|
121 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
122 | - throw new \Exception( |
|
123 | - // TODO $l |
|
124 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
125 | - [$info['name']] |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - // check for required dependencies |
|
131 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
132 | - \OC_App::registerAutoloading($appId, $basedir); |
|
133 | - |
|
134 | - //install the database |
|
135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
136 | - if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
137 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
138 | - } else { |
|
139 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
140 | - } |
|
141 | - } else { |
|
142 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
143 | - $ms->migrate(); |
|
144 | - } |
|
145 | - |
|
146 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
148 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
149 | - } |
|
150 | - |
|
151 | - //run appinfo/install.php |
|
152 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
153 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
154 | - } |
|
155 | - |
|
156 | - $appData = OC_App::getAppInfo($appId); |
|
157 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
158 | - |
|
159 | - //set the installed version |
|
160 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
161 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
162 | - |
|
163 | - //set remote/public handlers |
|
164 | - foreach($info['remote'] as $name=>$path) { |
|
165 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
166 | - } |
|
167 | - foreach($info['public'] as $name=>$path) { |
|
168 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
169 | - } |
|
170 | - |
|
171 | - OC_App::setAppTypes($info['id']); |
|
172 | - |
|
173 | - return $info['id']; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @brief checks whether or not an app is installed |
|
178 | - * @param string $app app |
|
179 | - * @returns bool |
|
180 | - * |
|
181 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
182 | - */ |
|
183 | - public static function isInstalled( $app ) { |
|
184 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Updates the specified app from the appstore |
|
189 | - * |
|
190 | - * @param string $appId |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function updateAppstoreApp($appId) { |
|
194 | - if($this->isUpdateAvailable($appId)) { |
|
195 | - try { |
|
196 | - $this->downloadApp($appId); |
|
197 | - } catch (\Exception $e) { |
|
198 | - $this->logger->logException($e, [ |
|
199 | - 'level' => \OCP\Util::ERROR, |
|
200 | - 'app' => 'core', |
|
201 | - ]); |
|
202 | - return false; |
|
203 | - } |
|
204 | - return OC_App::updateApp($appId); |
|
205 | - } |
|
206 | - |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Downloads an app and puts it into the app directory |
|
212 | - * |
|
213 | - * @param string $appId |
|
214 | - * |
|
215 | - * @throws \Exception If the installation was not successful |
|
216 | - */ |
|
217 | - public function downloadApp($appId) { |
|
218 | - $appId = strtolower($appId); |
|
219 | - |
|
220 | - $apps = $this->appFetcher->get(); |
|
221 | - foreach($apps as $app) { |
|
222 | - if($app['id'] === $appId) { |
|
223 | - // Load the certificate |
|
224 | - $certificate = new X509(); |
|
225 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
226 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
227 | - |
|
228 | - // Verify if the certificate has been revoked |
|
229 | - $crl = new X509(); |
|
230 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
231 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
232 | - if($crl->validateSignature() !== true) { |
|
233 | - throw new \Exception('Could not validate CRL signature'); |
|
234 | - } |
|
235 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
236 | - $revoked = $crl->getRevoked($csn); |
|
237 | - if ($revoked !== false) { |
|
238 | - throw new \Exception( |
|
239 | - sprintf( |
|
240 | - 'Certificate "%s" has been revoked', |
|
241 | - $csn |
|
242 | - ) |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
247 | - if($certificate->validateSignature() !== true) { |
|
248 | - throw new \Exception( |
|
249 | - sprintf( |
|
250 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
251 | - $appId |
|
252 | - ) |
|
253 | - ); |
|
254 | - } |
|
255 | - |
|
256 | - // Verify if the certificate is issued for the requested app id |
|
257 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
258 | - if(!isset($certInfo['subject']['CN'])) { |
|
259 | - throw new \Exception( |
|
260 | - sprintf( |
|
261 | - 'App with id %s has a cert with no CN', |
|
262 | - $appId |
|
263 | - ) |
|
264 | - ); |
|
265 | - } |
|
266 | - if($certInfo['subject']['CN'] !== $appId) { |
|
267 | - throw new \Exception( |
|
268 | - sprintf( |
|
269 | - 'App with id %s has a cert issued to %s', |
|
270 | - $appId, |
|
271 | - $certInfo['subject']['CN'] |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - |
|
276 | - // Download the release |
|
277 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
278 | - $client = $this->clientService->newClient(); |
|
279 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
280 | - |
|
281 | - // Check if the signature actually matches the downloaded content |
|
282 | - $certificate = openssl_get_publickey($app['certificate']); |
|
283 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
284 | - openssl_free_key($certificate); |
|
285 | - |
|
286 | - if($verified === true) { |
|
287 | - // Seems to match, let's proceed |
|
288 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
289 | - $archive = new TAR($tempFile); |
|
290 | - |
|
291 | - if($archive) { |
|
292 | - if (!$archive->extract($extractDir)) { |
|
293 | - throw new \Exception( |
|
294 | - sprintf( |
|
295 | - 'Could not extract app %s', |
|
296 | - $appId |
|
297 | - ) |
|
298 | - ); |
|
299 | - } |
|
300 | - $allFiles = scandir($extractDir); |
|
301 | - $folders = array_diff($allFiles, ['.', '..']); |
|
302 | - $folders = array_values($folders); |
|
303 | - |
|
304 | - if(count($folders) > 1) { |
|
305 | - throw new \Exception( |
|
306 | - sprintf( |
|
307 | - 'Extracted app %s has more than 1 folder', |
|
308 | - $appId |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | - // Check if appinfo/info.xml has the same app ID as well |
|
314 | - $loadEntities = libxml_disable_entity_loader(false); |
|
315 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
316 | - libxml_disable_entity_loader($loadEntities); |
|
317 | - if((string)$xml->id !== $appId) { |
|
318 | - throw new \Exception( |
|
319 | - sprintf( |
|
320 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
321 | - $appId, |
|
322 | - (string)$xml->id |
|
323 | - ) |
|
324 | - ); |
|
325 | - } |
|
326 | - |
|
327 | - // Check if the version is lower than before |
|
328 | - $currentVersion = OC_App::getAppVersion($appId); |
|
329 | - $newVersion = (string)$xml->version; |
|
330 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
331 | - throw new \Exception( |
|
332 | - sprintf( |
|
333 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
334 | - $appId, |
|
335 | - $currentVersion, |
|
336 | - $newVersion |
|
337 | - ) |
|
338 | - ); |
|
339 | - } |
|
340 | - |
|
341 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
342 | - // Remove old app with the ID if existent |
|
343 | - OC_Helper::rmdirr($baseDir); |
|
344 | - // Move to app folder |
|
345 | - if(@mkdir($baseDir)) { |
|
346 | - $extractDir .= '/' . $folders[0]; |
|
347 | - OC_Helper::copyr($extractDir, $baseDir); |
|
348 | - } |
|
349 | - OC_Helper::copyr($extractDir, $baseDir); |
|
350 | - OC_Helper::rmdirr($extractDir); |
|
351 | - return; |
|
352 | - } else { |
|
353 | - throw new \Exception( |
|
354 | - sprintf( |
|
355 | - 'Could not extract app with ID %s to %s', |
|
356 | - $appId, |
|
357 | - $extractDir |
|
358 | - ) |
|
359 | - ); |
|
360 | - } |
|
361 | - } else { |
|
362 | - // Signature does not match |
|
363 | - throw new \Exception( |
|
364 | - sprintf( |
|
365 | - 'App with id %s has invalid signature', |
|
366 | - $appId |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - throw new \Exception( |
|
374 | - sprintf( |
|
375 | - 'Could not download app %s', |
|
376 | - $appId |
|
377 | - ) |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Check if an update for the app is available |
|
383 | - * |
|
384 | - * @param string $appId |
|
385 | - * @return string|false false or the version number of the update |
|
386 | - */ |
|
387 | - public function isUpdateAvailable($appId) { |
|
388 | - if ($this->isInstanceReadyForUpdates === null) { |
|
389 | - $installPath = OC_App::getInstallPath(); |
|
390 | - if ($installPath === false || $installPath === null) { |
|
391 | - $this->isInstanceReadyForUpdates = false; |
|
392 | - } else { |
|
393 | - $this->isInstanceReadyForUpdates = true; |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - if ($this->isInstanceReadyForUpdates === false) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - if ($this->isInstalledFromGit($appId) === true) { |
|
402 | - return false; |
|
403 | - } |
|
404 | - |
|
405 | - if ($this->apps === null) { |
|
406 | - $this->apps = $this->appFetcher->get(); |
|
407 | - } |
|
408 | - |
|
409 | - foreach($this->apps as $app) { |
|
410 | - if($app['id'] === $appId) { |
|
411 | - $currentVersion = OC_App::getAppVersion($appId); |
|
412 | - $newestVersion = $app['releases'][0]['version']; |
|
413 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
414 | - return $newestVersion; |
|
415 | - } else { |
|
416 | - return false; |
|
417 | - } |
|
418 | - } |
|
419 | - } |
|
420 | - |
|
421 | - return false; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Check if app has been installed from git |
|
426 | - * @param string $name name of the application to remove |
|
427 | - * @return boolean |
|
428 | - * |
|
429 | - * The function will check if the path contains a .git folder |
|
430 | - */ |
|
431 | - private function isInstalledFromGit($appId) { |
|
432 | - $app = \OC_App::findAppInDirectories($appId); |
|
433 | - if($app === false) { |
|
434 | - return false; |
|
435 | - } |
|
436 | - $basedir = $app['path'].'/'.$appId; |
|
437 | - return file_exists($basedir.'/.git/'); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Check if app is already downloaded |
|
442 | - * @param string $name name of the application to remove |
|
443 | - * @return boolean |
|
444 | - * |
|
445 | - * The function will check if the app is already downloaded in the apps repository |
|
446 | - */ |
|
447 | - public function isDownloaded($name) { |
|
448 | - foreach(\OC::$APPSROOTS as $dir) { |
|
449 | - $dirToTest = $dir['path']; |
|
450 | - $dirToTest .= '/'; |
|
451 | - $dirToTest .= $name; |
|
452 | - $dirToTest .= '/'; |
|
453 | - |
|
454 | - if (is_dir($dirToTest)) { |
|
455 | - return true; |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - return false; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Removes an app |
|
464 | - * @param string $appId ID of the application to remove |
|
465 | - * @return boolean |
|
466 | - * |
|
467 | - * |
|
468 | - * This function works as follows |
|
469 | - * -# call uninstall repair steps |
|
470 | - * -# removing the files |
|
471 | - * |
|
472 | - * The function will not delete preferences, tables and the configuration, |
|
473 | - * this has to be done by the function oc_app_uninstall(). |
|
474 | - */ |
|
475 | - public function removeApp($appId) { |
|
476 | - if($this->isDownloaded( $appId )) { |
|
477 | - if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
478 | - return false; |
|
479 | - } |
|
480 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
481 | - OC_Helper::rmdirr($appDir); |
|
482 | - return true; |
|
483 | - }else{ |
|
484 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
485 | - |
|
486 | - return false; |
|
487 | - } |
|
488 | - |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Installs the app within the bundle and marks the bundle as installed |
|
493 | - * |
|
494 | - * @param Bundle $bundle |
|
495 | - * @throws \Exception If app could not get installed |
|
496 | - */ |
|
497 | - public function installAppBundle(Bundle $bundle) { |
|
498 | - $appIds = $bundle->getAppIdentifiers(); |
|
499 | - foreach($appIds as $appId) { |
|
500 | - if(!$this->isDownloaded($appId)) { |
|
501 | - $this->downloadApp($appId); |
|
502 | - } |
|
503 | - $this->installApp($appId); |
|
504 | - $app = new OC_App(); |
|
505 | - $app->enable($appId); |
|
506 | - } |
|
507 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
508 | - $bundles[] = $bundle->getIdentifier(); |
|
509 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * Installs shipped apps |
|
514 | - * |
|
515 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
516 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
517 | - * working ownCloud at the end instead of an aborted update. |
|
518 | - * @return array Array of error messages (appid => Exception) |
|
519 | - */ |
|
520 | - public static function installShippedApps($softErrors = false) { |
|
521 | - $errors = []; |
|
522 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
523 | - if($dir = opendir( $app_dir['path'] )) { |
|
524 | - while( false !== ( $filename = readdir( $dir ))) { |
|
525 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
526 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
527 | - if(!Installer::isInstalled($filename)) { |
|
528 | - $info=OC_App::getAppInfo($filename); |
|
529 | - $enabled = isset($info['default_enable']); |
|
530 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
531 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
532 | - if ($softErrors) { |
|
533 | - try { |
|
534 | - Installer::installShippedApp($filename); |
|
535 | - } catch (HintException $e) { |
|
536 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
537 | - $errors[$filename] = $e; |
|
538 | - continue; |
|
539 | - } |
|
540 | - throw $e; |
|
541 | - } |
|
542 | - } else { |
|
543 | - Installer::installShippedApp($filename); |
|
544 | - } |
|
545 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
546 | - } |
|
547 | - } |
|
548 | - } |
|
549 | - } |
|
550 | - } |
|
551 | - closedir( $dir ); |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - return $errors; |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * install an app already placed in the app folder |
|
560 | - * @param string $app id of the app to install |
|
561 | - * @return integer |
|
562 | - */ |
|
563 | - public static function installShippedApp($app) { |
|
564 | - //install the database |
|
565 | - $appPath = OC_App::getAppPath($app); |
|
566 | - \OC_App::registerAutoloading($app, $appPath); |
|
567 | - |
|
568 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
569 | - try { |
|
570 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
571 | - } catch (TableExistsException $e) { |
|
572 | - throw new HintException( |
|
573 | - 'Failed to enable app ' . $app, |
|
574 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
575 | - 0, $e |
|
576 | - ); |
|
577 | - } |
|
578 | - } else { |
|
579 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
580 | - $ms->migrate(); |
|
581 | - } |
|
582 | - |
|
583 | - //run appinfo/install.php |
|
584 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
585 | - |
|
586 | - $info = OC_App::getAppInfo($app); |
|
587 | - if (is_null($info)) { |
|
588 | - return false; |
|
589 | - } |
|
590 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
591 | - |
|
592 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
593 | - |
|
594 | - $config = \OC::$server->getConfig(); |
|
595 | - |
|
596 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
597 | - if (array_key_exists('ocsid', $info)) { |
|
598 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
599 | - } |
|
600 | - |
|
601 | - //set remote/public handlers |
|
602 | - foreach($info['remote'] as $name=>$path) { |
|
603 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
604 | - } |
|
605 | - foreach($info['public'] as $name=>$path) { |
|
606 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
607 | - } |
|
608 | - |
|
609 | - OC_App::setAppTypes($info['id']); |
|
610 | - |
|
611 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
612 | - // requires that autoloading was registered for the app, |
|
613 | - // as happens before running the install.php some lines above |
|
614 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
615 | - } |
|
616 | - |
|
617 | - return $info['id']; |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * @param string $script |
|
622 | - */ |
|
623 | - private static function includeAppScript($script) { |
|
624 | - if ( file_exists($script) ){ |
|
625 | - include $script; |
|
626 | - } |
|
627 | - } |
|
60 | + /** @var AppFetcher */ |
|
61 | + private $appFetcher; |
|
62 | + /** @var IClientService */ |
|
63 | + private $clientService; |
|
64 | + /** @var ITempManager */ |
|
65 | + private $tempManager; |
|
66 | + /** @var ILogger */ |
|
67 | + private $logger; |
|
68 | + /** @var IConfig */ |
|
69 | + private $config; |
|
70 | + /** @var array - for caching the result of app fetcher */ |
|
71 | + private $apps = null; |
|
72 | + /** @var bool|null - for caching the result of the ready status */ |
|
73 | + private $isInstanceReadyForUpdates = null; |
|
74 | + |
|
75 | + /** |
|
76 | + * @param AppFetcher $appFetcher |
|
77 | + * @param IClientService $clientService |
|
78 | + * @param ITempManager $tempManager |
|
79 | + * @param ILogger $logger |
|
80 | + * @param IConfig $config |
|
81 | + */ |
|
82 | + public function __construct(AppFetcher $appFetcher, |
|
83 | + IClientService $clientService, |
|
84 | + ITempManager $tempManager, |
|
85 | + ILogger $logger, |
|
86 | + IConfig $config) { |
|
87 | + $this->appFetcher = $appFetcher; |
|
88 | + $this->clientService = $clientService; |
|
89 | + $this->tempManager = $tempManager; |
|
90 | + $this->logger = $logger; |
|
91 | + $this->config = $config; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Installs an app that is located in one of the app folders already |
|
96 | + * |
|
97 | + * @param string $appId App to install |
|
98 | + * @throws \Exception |
|
99 | + * @return string app ID |
|
100 | + */ |
|
101 | + public function installApp($appId) { |
|
102 | + $app = \OC_App::findAppInDirectories($appId); |
|
103 | + if($app === false) { |
|
104 | + throw new \Exception('App not found in any app directory'); |
|
105 | + } |
|
106 | + |
|
107 | + $basedir = $app['path'].'/'.$appId; |
|
108 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
109 | + |
|
110 | + $l = \OC::$server->getL10N('core'); |
|
111 | + |
|
112 | + if(!is_array($info)) { |
|
113 | + throw new \Exception( |
|
114 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
115 | + [$info['name']] |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + $version = \OCP\Util::getVersion(); |
|
121 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
122 | + throw new \Exception( |
|
123 | + // TODO $l |
|
124 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
125 | + [$info['name']] |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + // check for required dependencies |
|
131 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
132 | + \OC_App::registerAutoloading($appId, $basedir); |
|
133 | + |
|
134 | + //install the database |
|
135 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
136 | + if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
137 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
138 | + } else { |
|
139 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
140 | + } |
|
141 | + } else { |
|
142 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
143 | + $ms->migrate(); |
|
144 | + } |
|
145 | + |
|
146 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
147 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
148 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
149 | + } |
|
150 | + |
|
151 | + //run appinfo/install.php |
|
152 | + if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
153 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
154 | + } |
|
155 | + |
|
156 | + $appData = OC_App::getAppInfo($appId); |
|
157 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
158 | + |
|
159 | + //set the installed version |
|
160 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
161 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
162 | + |
|
163 | + //set remote/public handlers |
|
164 | + foreach($info['remote'] as $name=>$path) { |
|
165 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
166 | + } |
|
167 | + foreach($info['public'] as $name=>$path) { |
|
168 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
169 | + } |
|
170 | + |
|
171 | + OC_App::setAppTypes($info['id']); |
|
172 | + |
|
173 | + return $info['id']; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @brief checks whether or not an app is installed |
|
178 | + * @param string $app app |
|
179 | + * @returns bool |
|
180 | + * |
|
181 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
182 | + */ |
|
183 | + public static function isInstalled( $app ) { |
|
184 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Updates the specified app from the appstore |
|
189 | + * |
|
190 | + * @param string $appId |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function updateAppstoreApp($appId) { |
|
194 | + if($this->isUpdateAvailable($appId)) { |
|
195 | + try { |
|
196 | + $this->downloadApp($appId); |
|
197 | + } catch (\Exception $e) { |
|
198 | + $this->logger->logException($e, [ |
|
199 | + 'level' => \OCP\Util::ERROR, |
|
200 | + 'app' => 'core', |
|
201 | + ]); |
|
202 | + return false; |
|
203 | + } |
|
204 | + return OC_App::updateApp($appId); |
|
205 | + } |
|
206 | + |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Downloads an app and puts it into the app directory |
|
212 | + * |
|
213 | + * @param string $appId |
|
214 | + * |
|
215 | + * @throws \Exception If the installation was not successful |
|
216 | + */ |
|
217 | + public function downloadApp($appId) { |
|
218 | + $appId = strtolower($appId); |
|
219 | + |
|
220 | + $apps = $this->appFetcher->get(); |
|
221 | + foreach($apps as $app) { |
|
222 | + if($app['id'] === $appId) { |
|
223 | + // Load the certificate |
|
224 | + $certificate = new X509(); |
|
225 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
226 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
227 | + |
|
228 | + // Verify if the certificate has been revoked |
|
229 | + $crl = new X509(); |
|
230 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
231 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
232 | + if($crl->validateSignature() !== true) { |
|
233 | + throw new \Exception('Could not validate CRL signature'); |
|
234 | + } |
|
235 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
236 | + $revoked = $crl->getRevoked($csn); |
|
237 | + if ($revoked !== false) { |
|
238 | + throw new \Exception( |
|
239 | + sprintf( |
|
240 | + 'Certificate "%s" has been revoked', |
|
241 | + $csn |
|
242 | + ) |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
247 | + if($certificate->validateSignature() !== true) { |
|
248 | + throw new \Exception( |
|
249 | + sprintf( |
|
250 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
251 | + $appId |
|
252 | + ) |
|
253 | + ); |
|
254 | + } |
|
255 | + |
|
256 | + // Verify if the certificate is issued for the requested app id |
|
257 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
258 | + if(!isset($certInfo['subject']['CN'])) { |
|
259 | + throw new \Exception( |
|
260 | + sprintf( |
|
261 | + 'App with id %s has a cert with no CN', |
|
262 | + $appId |
|
263 | + ) |
|
264 | + ); |
|
265 | + } |
|
266 | + if($certInfo['subject']['CN'] !== $appId) { |
|
267 | + throw new \Exception( |
|
268 | + sprintf( |
|
269 | + 'App with id %s has a cert issued to %s', |
|
270 | + $appId, |
|
271 | + $certInfo['subject']['CN'] |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + |
|
276 | + // Download the release |
|
277 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
278 | + $client = $this->clientService->newClient(); |
|
279 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
280 | + |
|
281 | + // Check if the signature actually matches the downloaded content |
|
282 | + $certificate = openssl_get_publickey($app['certificate']); |
|
283 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
284 | + openssl_free_key($certificate); |
|
285 | + |
|
286 | + if($verified === true) { |
|
287 | + // Seems to match, let's proceed |
|
288 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
289 | + $archive = new TAR($tempFile); |
|
290 | + |
|
291 | + if($archive) { |
|
292 | + if (!$archive->extract($extractDir)) { |
|
293 | + throw new \Exception( |
|
294 | + sprintf( |
|
295 | + 'Could not extract app %s', |
|
296 | + $appId |
|
297 | + ) |
|
298 | + ); |
|
299 | + } |
|
300 | + $allFiles = scandir($extractDir); |
|
301 | + $folders = array_diff($allFiles, ['.', '..']); |
|
302 | + $folders = array_values($folders); |
|
303 | + |
|
304 | + if(count($folders) > 1) { |
|
305 | + throw new \Exception( |
|
306 | + sprintf( |
|
307 | + 'Extracted app %s has more than 1 folder', |
|
308 | + $appId |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | + |
|
313 | + // Check if appinfo/info.xml has the same app ID as well |
|
314 | + $loadEntities = libxml_disable_entity_loader(false); |
|
315 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
316 | + libxml_disable_entity_loader($loadEntities); |
|
317 | + if((string)$xml->id !== $appId) { |
|
318 | + throw new \Exception( |
|
319 | + sprintf( |
|
320 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
321 | + $appId, |
|
322 | + (string)$xml->id |
|
323 | + ) |
|
324 | + ); |
|
325 | + } |
|
326 | + |
|
327 | + // Check if the version is lower than before |
|
328 | + $currentVersion = OC_App::getAppVersion($appId); |
|
329 | + $newVersion = (string)$xml->version; |
|
330 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
331 | + throw new \Exception( |
|
332 | + sprintf( |
|
333 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
334 | + $appId, |
|
335 | + $currentVersion, |
|
336 | + $newVersion |
|
337 | + ) |
|
338 | + ); |
|
339 | + } |
|
340 | + |
|
341 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
342 | + // Remove old app with the ID if existent |
|
343 | + OC_Helper::rmdirr($baseDir); |
|
344 | + // Move to app folder |
|
345 | + if(@mkdir($baseDir)) { |
|
346 | + $extractDir .= '/' . $folders[0]; |
|
347 | + OC_Helper::copyr($extractDir, $baseDir); |
|
348 | + } |
|
349 | + OC_Helper::copyr($extractDir, $baseDir); |
|
350 | + OC_Helper::rmdirr($extractDir); |
|
351 | + return; |
|
352 | + } else { |
|
353 | + throw new \Exception( |
|
354 | + sprintf( |
|
355 | + 'Could not extract app with ID %s to %s', |
|
356 | + $appId, |
|
357 | + $extractDir |
|
358 | + ) |
|
359 | + ); |
|
360 | + } |
|
361 | + } else { |
|
362 | + // Signature does not match |
|
363 | + throw new \Exception( |
|
364 | + sprintf( |
|
365 | + 'App with id %s has invalid signature', |
|
366 | + $appId |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + throw new \Exception( |
|
374 | + sprintf( |
|
375 | + 'Could not download app %s', |
|
376 | + $appId |
|
377 | + ) |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Check if an update for the app is available |
|
383 | + * |
|
384 | + * @param string $appId |
|
385 | + * @return string|false false or the version number of the update |
|
386 | + */ |
|
387 | + public function isUpdateAvailable($appId) { |
|
388 | + if ($this->isInstanceReadyForUpdates === null) { |
|
389 | + $installPath = OC_App::getInstallPath(); |
|
390 | + if ($installPath === false || $installPath === null) { |
|
391 | + $this->isInstanceReadyForUpdates = false; |
|
392 | + } else { |
|
393 | + $this->isInstanceReadyForUpdates = true; |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + if ($this->isInstanceReadyForUpdates === false) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + if ($this->isInstalledFromGit($appId) === true) { |
|
402 | + return false; |
|
403 | + } |
|
404 | + |
|
405 | + if ($this->apps === null) { |
|
406 | + $this->apps = $this->appFetcher->get(); |
|
407 | + } |
|
408 | + |
|
409 | + foreach($this->apps as $app) { |
|
410 | + if($app['id'] === $appId) { |
|
411 | + $currentVersion = OC_App::getAppVersion($appId); |
|
412 | + $newestVersion = $app['releases'][0]['version']; |
|
413 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
414 | + return $newestVersion; |
|
415 | + } else { |
|
416 | + return false; |
|
417 | + } |
|
418 | + } |
|
419 | + } |
|
420 | + |
|
421 | + return false; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Check if app has been installed from git |
|
426 | + * @param string $name name of the application to remove |
|
427 | + * @return boolean |
|
428 | + * |
|
429 | + * The function will check if the path contains a .git folder |
|
430 | + */ |
|
431 | + private function isInstalledFromGit($appId) { |
|
432 | + $app = \OC_App::findAppInDirectories($appId); |
|
433 | + if($app === false) { |
|
434 | + return false; |
|
435 | + } |
|
436 | + $basedir = $app['path'].'/'.$appId; |
|
437 | + return file_exists($basedir.'/.git/'); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Check if app is already downloaded |
|
442 | + * @param string $name name of the application to remove |
|
443 | + * @return boolean |
|
444 | + * |
|
445 | + * The function will check if the app is already downloaded in the apps repository |
|
446 | + */ |
|
447 | + public function isDownloaded($name) { |
|
448 | + foreach(\OC::$APPSROOTS as $dir) { |
|
449 | + $dirToTest = $dir['path']; |
|
450 | + $dirToTest .= '/'; |
|
451 | + $dirToTest .= $name; |
|
452 | + $dirToTest .= '/'; |
|
453 | + |
|
454 | + if (is_dir($dirToTest)) { |
|
455 | + return true; |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + return false; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Removes an app |
|
464 | + * @param string $appId ID of the application to remove |
|
465 | + * @return boolean |
|
466 | + * |
|
467 | + * |
|
468 | + * This function works as follows |
|
469 | + * -# call uninstall repair steps |
|
470 | + * -# removing the files |
|
471 | + * |
|
472 | + * The function will not delete preferences, tables and the configuration, |
|
473 | + * this has to be done by the function oc_app_uninstall(). |
|
474 | + */ |
|
475 | + public function removeApp($appId) { |
|
476 | + if($this->isDownloaded( $appId )) { |
|
477 | + if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
478 | + return false; |
|
479 | + } |
|
480 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
481 | + OC_Helper::rmdirr($appDir); |
|
482 | + return true; |
|
483 | + }else{ |
|
484 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
485 | + |
|
486 | + return false; |
|
487 | + } |
|
488 | + |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Installs the app within the bundle and marks the bundle as installed |
|
493 | + * |
|
494 | + * @param Bundle $bundle |
|
495 | + * @throws \Exception If app could not get installed |
|
496 | + */ |
|
497 | + public function installAppBundle(Bundle $bundle) { |
|
498 | + $appIds = $bundle->getAppIdentifiers(); |
|
499 | + foreach($appIds as $appId) { |
|
500 | + if(!$this->isDownloaded($appId)) { |
|
501 | + $this->downloadApp($appId); |
|
502 | + } |
|
503 | + $this->installApp($appId); |
|
504 | + $app = new OC_App(); |
|
505 | + $app->enable($appId); |
|
506 | + } |
|
507 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
508 | + $bundles[] = $bundle->getIdentifier(); |
|
509 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Installs shipped apps |
|
514 | + * |
|
515 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
516 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
517 | + * working ownCloud at the end instead of an aborted update. |
|
518 | + * @return array Array of error messages (appid => Exception) |
|
519 | + */ |
|
520 | + public static function installShippedApps($softErrors = false) { |
|
521 | + $errors = []; |
|
522 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
523 | + if($dir = opendir( $app_dir['path'] )) { |
|
524 | + while( false !== ( $filename = readdir( $dir ))) { |
|
525 | + if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
526 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
527 | + if(!Installer::isInstalled($filename)) { |
|
528 | + $info=OC_App::getAppInfo($filename); |
|
529 | + $enabled = isset($info['default_enable']); |
|
530 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
531 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
532 | + if ($softErrors) { |
|
533 | + try { |
|
534 | + Installer::installShippedApp($filename); |
|
535 | + } catch (HintException $e) { |
|
536 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
537 | + $errors[$filename] = $e; |
|
538 | + continue; |
|
539 | + } |
|
540 | + throw $e; |
|
541 | + } |
|
542 | + } else { |
|
543 | + Installer::installShippedApp($filename); |
|
544 | + } |
|
545 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
546 | + } |
|
547 | + } |
|
548 | + } |
|
549 | + } |
|
550 | + } |
|
551 | + closedir( $dir ); |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + return $errors; |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * install an app already placed in the app folder |
|
560 | + * @param string $app id of the app to install |
|
561 | + * @return integer |
|
562 | + */ |
|
563 | + public static function installShippedApp($app) { |
|
564 | + //install the database |
|
565 | + $appPath = OC_App::getAppPath($app); |
|
566 | + \OC_App::registerAutoloading($app, $appPath); |
|
567 | + |
|
568 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
569 | + try { |
|
570 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
571 | + } catch (TableExistsException $e) { |
|
572 | + throw new HintException( |
|
573 | + 'Failed to enable app ' . $app, |
|
574 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
575 | + 0, $e |
|
576 | + ); |
|
577 | + } |
|
578 | + } else { |
|
579 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
580 | + $ms->migrate(); |
|
581 | + } |
|
582 | + |
|
583 | + //run appinfo/install.php |
|
584 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
585 | + |
|
586 | + $info = OC_App::getAppInfo($app); |
|
587 | + if (is_null($info)) { |
|
588 | + return false; |
|
589 | + } |
|
590 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
591 | + |
|
592 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
593 | + |
|
594 | + $config = \OC::$server->getConfig(); |
|
595 | + |
|
596 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
597 | + if (array_key_exists('ocsid', $info)) { |
|
598 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
599 | + } |
|
600 | + |
|
601 | + //set remote/public handlers |
|
602 | + foreach($info['remote'] as $name=>$path) { |
|
603 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
604 | + } |
|
605 | + foreach($info['public'] as $name=>$path) { |
|
606 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
607 | + } |
|
608 | + |
|
609 | + OC_App::setAppTypes($info['id']); |
|
610 | + |
|
611 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
612 | + // requires that autoloading was registered for the app, |
|
613 | + // as happens before running the install.php some lines above |
|
614 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
615 | + } |
|
616 | + |
|
617 | + return $info['id']; |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * @param string $script |
|
622 | + */ |
|
623 | + private static function includeAppScript($script) { |
|
624 | + if ( file_exists($script) ){ |
|
625 | + include $script; |
|
626 | + } |
|
627 | + } |
|
628 | 628 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function installApp($appId) { |
102 | 102 | $app = \OC_App::findAppInDirectories($appId); |
103 | - if($app === false) { |
|
103 | + if ($app === false) { |
|
104 | 104 | throw new \Exception('App not found in any app directory'); |
105 | 105 | } |
106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | $l = \OC::$server->getL10N('core'); |
111 | 111 | |
112 | - if(!is_array($info)) { |
|
112 | + if (!is_array($info)) { |
|
113 | 113 | throw new \Exception( |
114 | 114 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
115 | 115 | [$info['name']] |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | \OC_App::registerAutoloading($appId, $basedir); |
133 | 133 | |
134 | 134 | //install the database |
135 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
135 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
136 | 136 | if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
137 | 137 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
138 | 138 | } else { |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
147 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
147 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
148 | 148 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
149 | 149 | } |
150 | 150 | |
151 | 151 | //run appinfo/install.php |
152 | - if(!isset($data['noinstall']) or $data['noinstall']==false) { |
|
153 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
152 | + if (!isset($data['noinstall']) or $data['noinstall'] == false) { |
|
153 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | $appData = OC_App::getAppInfo($appId); |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
162 | 162 | |
163 | 163 | //set remote/public handlers |
164 | - foreach($info['remote'] as $name=>$path) { |
|
164 | + foreach ($info['remote'] as $name=>$path) { |
|
165 | 165 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
166 | 166 | } |
167 | - foreach($info['public'] as $name=>$path) { |
|
167 | + foreach ($info['public'] as $name=>$path) { |
|
168 | 168 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
169 | 169 | } |
170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * |
181 | 181 | * Checks whether or not an app is installed, i.e. registered in apps table. |
182 | 182 | */ |
183 | - public static function isInstalled( $app ) { |
|
183 | + public static function isInstalled($app) { |
|
184 | 184 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
185 | 185 | } |
186 | 186 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @return bool |
192 | 192 | */ |
193 | 193 | public function updateAppstoreApp($appId) { |
194 | - if($this->isUpdateAvailable($appId)) { |
|
194 | + if ($this->isUpdateAvailable($appId)) { |
|
195 | 195 | try { |
196 | 196 | $this->downloadApp($appId); |
197 | 197 | } catch (\Exception $e) { |
@@ -218,18 +218,18 @@ discard block |
||
218 | 218 | $appId = strtolower($appId); |
219 | 219 | |
220 | 220 | $apps = $this->appFetcher->get(); |
221 | - foreach($apps as $app) { |
|
222 | - if($app['id'] === $appId) { |
|
221 | + foreach ($apps as $app) { |
|
222 | + if ($app['id'] === $appId) { |
|
223 | 223 | // Load the certificate |
224 | 224 | $certificate = new X509(); |
225 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
225 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
226 | 226 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
227 | 227 | |
228 | 228 | // Verify if the certificate has been revoked |
229 | 229 | $crl = new X509(); |
230 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
231 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
232 | - if($crl->validateSignature() !== true) { |
|
230 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
231 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
232 | + if ($crl->validateSignature() !== true) { |
|
233 | 233 | throw new \Exception('Could not validate CRL signature'); |
234 | 234 | } |
235 | 235 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
247 | - if($certificate->validateSignature() !== true) { |
|
247 | + if ($certificate->validateSignature() !== true) { |
|
248 | 248 | throw new \Exception( |
249 | 249 | sprintf( |
250 | 250 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | // Verify if the certificate is issued for the requested app id |
257 | 257 | $certInfo = openssl_x509_parse($app['certificate']); |
258 | - if(!isset($certInfo['subject']['CN'])) { |
|
258 | + if (!isset($certInfo['subject']['CN'])) { |
|
259 | 259 | throw new \Exception( |
260 | 260 | sprintf( |
261 | 261 | 'App with id %s has a cert with no CN', |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | ) |
264 | 264 | ); |
265 | 265 | } |
266 | - if($certInfo['subject']['CN'] !== $appId) { |
|
266 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
267 | 267 | throw new \Exception( |
268 | 268 | sprintf( |
269 | 269 | 'App with id %s has a cert issued to %s', |
@@ -280,15 +280,15 @@ discard block |
||
280 | 280 | |
281 | 281 | // Check if the signature actually matches the downloaded content |
282 | 282 | $certificate = openssl_get_publickey($app['certificate']); |
283 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
283 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
284 | 284 | openssl_free_key($certificate); |
285 | 285 | |
286 | - if($verified === true) { |
|
286 | + if ($verified === true) { |
|
287 | 287 | // Seems to match, let's proceed |
288 | 288 | $extractDir = $this->tempManager->getTemporaryFolder(); |
289 | 289 | $archive = new TAR($tempFile); |
290 | 290 | |
291 | - if($archive) { |
|
291 | + if ($archive) { |
|
292 | 292 | if (!$archive->extract($extractDir)) { |
293 | 293 | throw new \Exception( |
294 | 294 | sprintf( |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $folders = array_diff($allFiles, ['.', '..']); |
302 | 302 | $folders = array_values($folders); |
303 | 303 | |
304 | - if(count($folders) > 1) { |
|
304 | + if (count($folders) > 1) { |
|
305 | 305 | throw new \Exception( |
306 | 306 | sprintf( |
307 | 307 | 'Extracted app %s has more than 1 folder', |
@@ -312,22 +312,22 @@ discard block |
||
312 | 312 | |
313 | 313 | // Check if appinfo/info.xml has the same app ID as well |
314 | 314 | $loadEntities = libxml_disable_entity_loader(false); |
315 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
315 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
316 | 316 | libxml_disable_entity_loader($loadEntities); |
317 | - if((string)$xml->id !== $appId) { |
|
317 | + if ((string) $xml->id !== $appId) { |
|
318 | 318 | throw new \Exception( |
319 | 319 | sprintf( |
320 | 320 | 'App for id %s has a wrong app ID in info.xml: %s', |
321 | 321 | $appId, |
322 | - (string)$xml->id |
|
322 | + (string) $xml->id |
|
323 | 323 | ) |
324 | 324 | ); |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Check if the version is lower than before |
328 | 328 | $currentVersion = OC_App::getAppVersion($appId); |
329 | - $newVersion = (string)$xml->version; |
|
330 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
329 | + $newVersion = (string) $xml->version; |
|
330 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
331 | 331 | throw new \Exception( |
332 | 332 | sprintf( |
333 | 333 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -338,12 +338,12 @@ discard block |
||
338 | 338 | ); |
339 | 339 | } |
340 | 340 | |
341 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
341 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
342 | 342 | // Remove old app with the ID if existent |
343 | 343 | OC_Helper::rmdirr($baseDir); |
344 | 344 | // Move to app folder |
345 | - if(@mkdir($baseDir)) { |
|
346 | - $extractDir .= '/' . $folders[0]; |
|
345 | + if (@mkdir($baseDir)) { |
|
346 | + $extractDir .= '/'.$folders[0]; |
|
347 | 347 | OC_Helper::copyr($extractDir, $baseDir); |
348 | 348 | } |
349 | 349 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | $this->apps = $this->appFetcher->get(); |
407 | 407 | } |
408 | 408 | |
409 | - foreach($this->apps as $app) { |
|
410 | - if($app['id'] === $appId) { |
|
409 | + foreach ($this->apps as $app) { |
|
410 | + if ($app['id'] === $appId) { |
|
411 | 411 | $currentVersion = OC_App::getAppVersion($appId); |
412 | 412 | $newestVersion = $app['releases'][0]['version']; |
413 | 413 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | */ |
431 | 431 | private function isInstalledFromGit($appId) { |
432 | 432 | $app = \OC_App::findAppInDirectories($appId); |
433 | - if($app === false) { |
|
433 | + if ($app === false) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | $basedir = $app['path'].'/'.$appId; |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * The function will check if the app is already downloaded in the apps repository |
446 | 446 | */ |
447 | 447 | public function isDownloaded($name) { |
448 | - foreach(\OC::$APPSROOTS as $dir) { |
|
448 | + foreach (\OC::$APPSROOTS as $dir) { |
|
449 | 449 | $dirToTest = $dir['path']; |
450 | 450 | $dirToTest .= '/'; |
451 | 451 | $dirToTest .= $name; |
@@ -473,14 +473,14 @@ discard block |
||
473 | 473 | * this has to be done by the function oc_app_uninstall(). |
474 | 474 | */ |
475 | 475 | public function removeApp($appId) { |
476 | - if($this->isDownloaded( $appId )) { |
|
476 | + if ($this->isDownloaded($appId)) { |
|
477 | 477 | if (\OC::$server->getAppManager()->isShipped($appId)) { |
478 | 478 | return false; |
479 | 479 | } |
480 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
480 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
481 | 481 | OC_Helper::rmdirr($appDir); |
482 | 482 | return true; |
483 | - }else{ |
|
483 | + } else { |
|
484 | 484 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
485 | 485 | |
486 | 486 | return false; |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | */ |
497 | 497 | public function installAppBundle(Bundle $bundle) { |
498 | 498 | $appIds = $bundle->getAppIdentifiers(); |
499 | - foreach($appIds as $appId) { |
|
500 | - if(!$this->isDownloaded($appId)) { |
|
499 | + foreach ($appIds as $appId) { |
|
500 | + if (!$this->isDownloaded($appId)) { |
|
501 | 501 | $this->downloadApp($appId); |
502 | 502 | } |
503 | 503 | $this->installApp($appId); |
@@ -519,13 +519,13 @@ discard block |
||
519 | 519 | */ |
520 | 520 | public static function installShippedApps($softErrors = false) { |
521 | 521 | $errors = []; |
522 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
523 | - if($dir = opendir( $app_dir['path'] )) { |
|
524 | - while( false !== ( $filename = readdir( $dir ))) { |
|
525 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
526 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
527 | - if(!Installer::isInstalled($filename)) { |
|
528 | - $info=OC_App::getAppInfo($filename); |
|
522 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
523 | + if ($dir = opendir($app_dir['path'])) { |
|
524 | + while (false !== ($filename = readdir($dir))) { |
|
525 | + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
526 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
527 | + if (!Installer::isInstalled($filename)) { |
|
528 | + $info = OC_App::getAppInfo($filename); |
|
529 | 529 | $enabled = isset($info['default_enable']); |
530 | 530 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
531 | 531 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | } |
549 | 549 | } |
550 | 550 | } |
551 | - closedir( $dir ); |
|
551 | + closedir($dir); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
@@ -565,12 +565,12 @@ discard block |
||
565 | 565 | $appPath = OC_App::getAppPath($app); |
566 | 566 | \OC_App::registerAutoloading($app, $appPath); |
567 | 567 | |
568 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
568 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
569 | 569 | try { |
570 | 570 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
571 | 571 | } catch (TableExistsException $e) { |
572 | 572 | throw new HintException( |
573 | - 'Failed to enable app ' . $app, |
|
573 | + 'Failed to enable app '.$app, |
|
574 | 574 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
575 | 575 | 0, $e |
576 | 576 | ); |
@@ -599,16 +599,16 @@ discard block |
||
599 | 599 | } |
600 | 600 | |
601 | 601 | //set remote/public handlers |
602 | - foreach($info['remote'] as $name=>$path) { |
|
602 | + foreach ($info['remote'] as $name=>$path) { |
|
603 | 603 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
604 | 604 | } |
605 | - foreach($info['public'] as $name=>$path) { |
|
605 | + foreach ($info['public'] as $name=>$path) { |
|
606 | 606 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
607 | 607 | } |
608 | 608 | |
609 | 609 | OC_App::setAppTypes($info['id']); |
610 | 610 | |
611 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
611 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
612 | 612 | // requires that autoloading was registered for the app, |
613 | 613 | // as happens before running the install.php some lines above |
614 | 614 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * @param string $script |
622 | 622 | */ |
623 | 623 | private static function includeAppScript($script) { |
624 | - if ( file_exists($script) ){ |
|
624 | + if (file_exists($script)) { |
|
625 | 625 | include $script; |
626 | 626 | } |
627 | 627 | } |
@@ -37,122 +37,122 @@ |
||
37 | 37 | */ |
38 | 38 | interface IAppManager { |
39 | 39 | |
40 | - /** |
|
41 | - * Returns the app information from "appinfo/info.xml". |
|
42 | - * |
|
43 | - * @param string $appId |
|
44 | - * @return mixed |
|
45 | - * @since 14.0.0 |
|
46 | - */ |
|
47 | - public function getAppInfo(string $appId, bool $path = false, $lang = null); |
|
48 | - |
|
49 | - /** |
|
50 | - * Returns the app information from "appinfo/info.xml". |
|
51 | - * |
|
52 | - * @param string $appId |
|
53 | - * @param bool $useCache |
|
54 | - * @return mixed |
|
55 | - * @since 14.0.0 |
|
56 | - */ |
|
57 | - public function getAppVersion(string $appId, bool $useCache = true); |
|
58 | - |
|
59 | - /** |
|
60 | - * Check if an app is enabled for user |
|
61 | - * |
|
62 | - * @param string $appId |
|
63 | - * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used |
|
64 | - * @return bool |
|
65 | - * @since 8.0.0 |
|
66 | - */ |
|
67 | - public function isEnabledForUser($appId, $user = null); |
|
68 | - |
|
69 | - /** |
|
70 | - * Check if an app is installed in the instance |
|
71 | - * |
|
72 | - * @param string $appId |
|
73 | - * @return bool |
|
74 | - * @since 8.0.0 |
|
75 | - */ |
|
76 | - public function isInstalled($appId); |
|
77 | - |
|
78 | - /** |
|
79 | - * Enable an app for every user |
|
80 | - * |
|
81 | - * @param string $appId |
|
82 | - * @throws AppPathNotFoundException |
|
83 | - * @since 8.0.0 |
|
84 | - */ |
|
85 | - public function enableApp($appId); |
|
86 | - |
|
87 | - /** |
|
88 | - * Whether a list of types contains a protected app type |
|
89 | - * |
|
90 | - * @param string[] $types |
|
91 | - * @return bool |
|
92 | - * @since 12.0.0 |
|
93 | - */ |
|
94 | - public function hasProtectedAppType($types); |
|
95 | - |
|
96 | - /** |
|
97 | - * Enable an app only for specific groups |
|
98 | - * |
|
99 | - * @param string $appId |
|
100 | - * @param \OCP\IGroup[] $groups |
|
101 | - * @since 8.0.0 |
|
102 | - */ |
|
103 | - public function enableAppForGroups($appId, $groups); |
|
104 | - |
|
105 | - /** |
|
106 | - * Disable an app for every user |
|
107 | - * |
|
108 | - * @param string $appId |
|
109 | - * @since 8.0.0 |
|
110 | - */ |
|
111 | - public function disableApp($appId); |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the directory for the given app. |
|
115 | - * |
|
116 | - * @param string $appId |
|
117 | - * @return string |
|
118 | - * @since 11.0.0 |
|
119 | - * @throws AppPathNotFoundException |
|
120 | - */ |
|
121 | - public function getAppPath($appId); |
|
122 | - |
|
123 | - /** |
|
124 | - * List all apps enabled for a user |
|
125 | - * |
|
126 | - * @param \OCP\IUser $user |
|
127 | - * @return string[] |
|
128 | - * @since 8.1.0 |
|
129 | - */ |
|
130 | - public function getEnabledAppsForUser(IUser $user); |
|
131 | - |
|
132 | - /** |
|
133 | - * List all installed apps |
|
134 | - * |
|
135 | - * @return string[] |
|
136 | - * @since 8.1.0 |
|
137 | - */ |
|
138 | - public function getInstalledApps(); |
|
139 | - |
|
140 | - /** |
|
141 | - * Clear the cached list of apps when enabling/disabling an app |
|
142 | - * @since 8.1.0 |
|
143 | - */ |
|
144 | - public function clearAppsCache(); |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $appId |
|
148 | - * @return boolean |
|
149 | - * @since 9.0.0 |
|
150 | - */ |
|
151 | - public function isShipped($appId); |
|
152 | - |
|
153 | - /** |
|
154 | - * @return string[] |
|
155 | - * @since 9.0.0 |
|
156 | - */ |
|
157 | - public function getAlwaysEnabledApps(); |
|
40 | + /** |
|
41 | + * Returns the app information from "appinfo/info.xml". |
|
42 | + * |
|
43 | + * @param string $appId |
|
44 | + * @return mixed |
|
45 | + * @since 14.0.0 |
|
46 | + */ |
|
47 | + public function getAppInfo(string $appId, bool $path = false, $lang = null); |
|
48 | + |
|
49 | + /** |
|
50 | + * Returns the app information from "appinfo/info.xml". |
|
51 | + * |
|
52 | + * @param string $appId |
|
53 | + * @param bool $useCache |
|
54 | + * @return mixed |
|
55 | + * @since 14.0.0 |
|
56 | + */ |
|
57 | + public function getAppVersion(string $appId, bool $useCache = true); |
|
58 | + |
|
59 | + /** |
|
60 | + * Check if an app is enabled for user |
|
61 | + * |
|
62 | + * @param string $appId |
|
63 | + * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used |
|
64 | + * @return bool |
|
65 | + * @since 8.0.0 |
|
66 | + */ |
|
67 | + public function isEnabledForUser($appId, $user = null); |
|
68 | + |
|
69 | + /** |
|
70 | + * Check if an app is installed in the instance |
|
71 | + * |
|
72 | + * @param string $appId |
|
73 | + * @return bool |
|
74 | + * @since 8.0.0 |
|
75 | + */ |
|
76 | + public function isInstalled($appId); |
|
77 | + |
|
78 | + /** |
|
79 | + * Enable an app for every user |
|
80 | + * |
|
81 | + * @param string $appId |
|
82 | + * @throws AppPathNotFoundException |
|
83 | + * @since 8.0.0 |
|
84 | + */ |
|
85 | + public function enableApp($appId); |
|
86 | + |
|
87 | + /** |
|
88 | + * Whether a list of types contains a protected app type |
|
89 | + * |
|
90 | + * @param string[] $types |
|
91 | + * @return bool |
|
92 | + * @since 12.0.0 |
|
93 | + */ |
|
94 | + public function hasProtectedAppType($types); |
|
95 | + |
|
96 | + /** |
|
97 | + * Enable an app only for specific groups |
|
98 | + * |
|
99 | + * @param string $appId |
|
100 | + * @param \OCP\IGroup[] $groups |
|
101 | + * @since 8.0.0 |
|
102 | + */ |
|
103 | + public function enableAppForGroups($appId, $groups); |
|
104 | + |
|
105 | + /** |
|
106 | + * Disable an app for every user |
|
107 | + * |
|
108 | + * @param string $appId |
|
109 | + * @since 8.0.0 |
|
110 | + */ |
|
111 | + public function disableApp($appId); |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the directory for the given app. |
|
115 | + * |
|
116 | + * @param string $appId |
|
117 | + * @return string |
|
118 | + * @since 11.0.0 |
|
119 | + * @throws AppPathNotFoundException |
|
120 | + */ |
|
121 | + public function getAppPath($appId); |
|
122 | + |
|
123 | + /** |
|
124 | + * List all apps enabled for a user |
|
125 | + * |
|
126 | + * @param \OCP\IUser $user |
|
127 | + * @return string[] |
|
128 | + * @since 8.1.0 |
|
129 | + */ |
|
130 | + public function getEnabledAppsForUser(IUser $user); |
|
131 | + |
|
132 | + /** |
|
133 | + * List all installed apps |
|
134 | + * |
|
135 | + * @return string[] |
|
136 | + * @since 8.1.0 |
|
137 | + */ |
|
138 | + public function getInstalledApps(); |
|
139 | + |
|
140 | + /** |
|
141 | + * Clear the cached list of apps when enabling/disabling an app |
|
142 | + * @since 8.1.0 |
|
143 | + */ |
|
144 | + public function clearAppsCache(); |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $appId |
|
148 | + * @return boolean |
|
149 | + * @since 9.0.0 |
|
150 | + */ |
|
151 | + public function isShipped($appId); |
|
152 | + |
|
153 | + /** |
|
154 | + * @return string[] |
|
155 | + * @since 9.0.0 |
|
156 | + */ |
|
157 | + public function getAlwaysEnabledApps(); |
|
158 | 158 | } |
@@ -45,73 +45,73 @@ |
||
45 | 45 | class App { |
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Register a Configuration Screen that should appear in the personal settings section. |
|
50 | - * @param string $app appid |
|
51 | - * @param string $page page to be included |
|
52 | - * @return void |
|
53 | - * @since 4.0.0 |
|
54 | - * @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections |
|
55 | - */ |
|
56 | - public static function registerPersonal( $app, $page ) { |
|
57 | - \OC_App::registerPersonal( $app, $page ); |
|
58 | - } |
|
48 | + /** |
|
49 | + * Register a Configuration Screen that should appear in the personal settings section. |
|
50 | + * @param string $app appid |
|
51 | + * @param string $page page to be included |
|
52 | + * @return void |
|
53 | + * @since 4.0.0 |
|
54 | + * @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections |
|
55 | + */ |
|
56 | + public static function registerPersonal( $app, $page ) { |
|
57 | + \OC_App::registerPersonal( $app, $page ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Register a Configuration Screen that should appear in the Admin section. |
|
62 | - * @param string $app string appid |
|
63 | - * @param string $page string page to be included |
|
64 | - * @return void |
|
65 | - * @since 4.0.0 |
|
66 | - * @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections |
|
67 | - */ |
|
68 | - public static function registerAdmin( $app, $page ) { |
|
69 | - \OC_App::registerAdmin( $app, $page ); |
|
70 | - } |
|
60 | + /** |
|
61 | + * Register a Configuration Screen that should appear in the Admin section. |
|
62 | + * @param string $app string appid |
|
63 | + * @param string $page string page to be included |
|
64 | + * @return void |
|
65 | + * @since 4.0.0 |
|
66 | + * @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections |
|
67 | + */ |
|
68 | + public static function registerAdmin( $app, $page ) { |
|
69 | + \OC_App::registerAdmin( $app, $page ); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Read app metadata from the info.xml file |
|
74 | - * @param string $app id of the app or the path of the info.xml file |
|
75 | - * @param boolean $path (optional) |
|
76 | - * @return array|null |
|
77 | - * @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId) |
|
78 | - * @since 4.0.0 |
|
79 | - */ |
|
80 | - public static function getAppInfo( $app, $path=false ) { |
|
81 | - return \OC_App::getAppInfo( $app, $path); |
|
82 | - } |
|
72 | + /** |
|
73 | + * Read app metadata from the info.xml file |
|
74 | + * @param string $app id of the app or the path of the info.xml file |
|
75 | + * @param boolean $path (optional) |
|
76 | + * @return array|null |
|
77 | + * @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId) |
|
78 | + * @since 4.0.0 |
|
79 | + */ |
|
80 | + public static function getAppInfo( $app, $path=false ) { |
|
81 | + return \OC_App::getAppInfo( $app, $path); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * checks whether or not an app is enabled |
|
86 | - * @param string $app |
|
87 | - * @return boolean |
|
88 | - * |
|
89 | - * This function checks whether or not an app is enabled. |
|
90 | - * @since 4.0.0 |
|
91 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
92 | - */ |
|
93 | - public static function isEnabled( $app ) { |
|
94 | - return \OC::$server->getAppManager()->isEnabledForUser( $app ); |
|
95 | - } |
|
84 | + /** |
|
85 | + * checks whether or not an app is enabled |
|
86 | + * @param string $app |
|
87 | + * @return boolean |
|
88 | + * |
|
89 | + * This function checks whether or not an app is enabled. |
|
90 | + * @since 4.0.0 |
|
91 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
92 | + */ |
|
93 | + public static function isEnabled( $app ) { |
|
94 | + return \OC::$server->getAppManager()->isEnabledForUser( $app ); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Check if the app is enabled, redirects to home if not |
|
99 | - * @param string $app |
|
100 | - * @return void |
|
101 | - * @since 4.0.0 |
|
102 | - * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs |
|
103 | - */ |
|
104 | - public static function checkAppEnabled( $app ) { |
|
105 | - } |
|
97 | + /** |
|
98 | + * Check if the app is enabled, redirects to home if not |
|
99 | + * @param string $app |
|
100 | + * @return void |
|
101 | + * @since 4.0.0 |
|
102 | + * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs |
|
103 | + */ |
|
104 | + public static function checkAppEnabled( $app ) { |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Get the last version of the app from appinfo/info.xml |
|
109 | - * @param string $app |
|
110 | - * @return string |
|
111 | - * @since 4.0.0 |
|
112 | - * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId) |
|
113 | - */ |
|
114 | - public static function getAppVersion( $app ) { |
|
115 | - return \OC::$server->getAppManager()->getAppVersion($app); |
|
116 | - } |
|
107 | + /** |
|
108 | + * Get the last version of the app from appinfo/info.xml |
|
109 | + * @param string $app |
|
110 | + * @return string |
|
111 | + * @since 4.0.0 |
|
112 | + * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId) |
|
113 | + */ |
|
114 | + public static function getAppVersion( $app ) { |
|
115 | + return \OC::$server->getAppManager()->getAppVersion($app); |
|
116 | + } |
|
117 | 117 | } |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @since 4.0.0 |
54 | 54 | * @deprecated 14.0.0 Use settings section in appinfo.xml to register personal admin sections |
55 | 55 | */ |
56 | - public static function registerPersonal( $app, $page ) { |
|
57 | - \OC_App::registerPersonal( $app, $page ); |
|
56 | + public static function registerPersonal($app, $page) { |
|
57 | + \OC_App::registerPersonal($app, $page); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @since 4.0.0 |
66 | 66 | * @deprecated 14.0.0 Use settings section in appinfo.xml to register admin sections |
67 | 67 | */ |
68 | - public static function registerAdmin( $app, $page ) { |
|
69 | - \OC_App::registerAdmin( $app, $page ); |
|
68 | + public static function registerAdmin($app, $page) { |
|
69 | + \OC_App::registerAdmin($app, $page); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | * @deprecated 14.0.0 ise \OC::$server->getAppManager()->getAppInfo($appId) |
78 | 78 | * @since 4.0.0 |
79 | 79 | */ |
80 | - public static function getAppInfo( $app, $path=false ) { |
|
81 | - return \OC_App::getAppInfo( $app, $path); |
|
80 | + public static function getAppInfo($app, $path = false) { |
|
81 | + return \OC_App::getAppInfo($app, $path); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * @since 4.0.0 |
91 | 91 | * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
92 | 92 | */ |
93 | - public static function isEnabled( $app ) { |
|
94 | - return \OC::$server->getAppManager()->isEnabledForUser( $app ); |
|
93 | + public static function isEnabled($app) { |
|
94 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @since 4.0.0 |
102 | 102 | * @deprecated 9.0.0 ownCloud core will handle disabled apps and redirects to valid URLs |
103 | 103 | */ |
104 | - public static function checkAppEnabled( $app ) { |
|
104 | + public static function checkAppEnabled($app) { |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @since 4.0.0 |
112 | 112 | * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion($appId) |
113 | 113 | */ |
114 | - public static function getAppVersion( $app ) { |
|
114 | + public static function getAppVersion($app) { |
|
115 | 115 | return \OC::$server->getAppManager()->getAppVersion($app); |
116 | 116 | } |
117 | 117 | } |
@@ -149,1834 +149,1834 @@ |
||
149 | 149 | * TODO: hookup all manager classes |
150 | 150 | */ |
151 | 151 | class Server extends ServerContainer implements IServerContainer { |
152 | - /** @var string */ |
|
153 | - private $webRoot; |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $webRoot |
|
157 | - * @param \OC\Config $config |
|
158 | - */ |
|
159 | - public function __construct($webRoot, \OC\Config $config) { |
|
160 | - parent::__construct(); |
|
161 | - $this->webRoot = $webRoot; |
|
162 | - |
|
163 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
164 | - return $c; |
|
165 | - }); |
|
166 | - |
|
167 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
168 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
169 | - |
|
170 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
171 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
172 | - |
|
173 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
174 | - |
|
175 | - |
|
176 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
177 | - return new PreviewManager( |
|
178 | - $c->getConfig(), |
|
179 | - $c->getRootFolder(), |
|
180 | - $c->getAppDataDir('preview'), |
|
181 | - $c->getEventDispatcher(), |
|
182 | - $c->getSession()->get('user_id') |
|
183 | - ); |
|
184 | - }); |
|
185 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
186 | - |
|
187 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
188 | - return new \OC\Preview\Watcher( |
|
189 | - $c->getAppDataDir('preview') |
|
190 | - ); |
|
191 | - }); |
|
192 | - |
|
193 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
194 | - $view = new View(); |
|
195 | - $util = new Encryption\Util( |
|
196 | - $view, |
|
197 | - $c->getUserManager(), |
|
198 | - $c->getGroupManager(), |
|
199 | - $c->getConfig() |
|
200 | - ); |
|
201 | - return new Encryption\Manager( |
|
202 | - $c->getConfig(), |
|
203 | - $c->getLogger(), |
|
204 | - $c->getL10N('core'), |
|
205 | - new View(), |
|
206 | - $util, |
|
207 | - new ArrayCache() |
|
208 | - ); |
|
209 | - }); |
|
210 | - |
|
211 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
212 | - $util = new Encryption\Util( |
|
213 | - new View(), |
|
214 | - $c->getUserManager(), |
|
215 | - $c->getGroupManager(), |
|
216 | - $c->getConfig() |
|
217 | - ); |
|
218 | - return new Encryption\File( |
|
219 | - $util, |
|
220 | - $c->getRootFolder(), |
|
221 | - $c->getShareManager() |
|
222 | - ); |
|
223 | - }); |
|
224 | - |
|
225 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
226 | - $view = new View(); |
|
227 | - $util = new Encryption\Util( |
|
228 | - $view, |
|
229 | - $c->getUserManager(), |
|
230 | - $c->getGroupManager(), |
|
231 | - $c->getConfig() |
|
232 | - ); |
|
233 | - |
|
234 | - return new Encryption\Keys\Storage($view, $util); |
|
235 | - }); |
|
236 | - $this->registerService('TagMapper', function (Server $c) { |
|
237 | - return new TagMapper($c->getDatabaseConnection()); |
|
238 | - }); |
|
239 | - |
|
240 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
241 | - $tagMapper = $c->query('TagMapper'); |
|
242 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
243 | - }); |
|
244 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
245 | - |
|
246 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
247 | - $config = $c->getConfig(); |
|
248 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
249 | - return new $factoryClass($this); |
|
250 | - }); |
|
251 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
252 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
253 | - }); |
|
254 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
255 | - |
|
256 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
257 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
258 | - }); |
|
259 | - $this->registerService('RootFolder', function (Server $c) { |
|
260 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
261 | - $view = new View(); |
|
262 | - $root = new Root( |
|
263 | - $manager, |
|
264 | - $view, |
|
265 | - null, |
|
266 | - $c->getUserMountCache(), |
|
267 | - $this->getLogger(), |
|
268 | - $this->getUserManager() |
|
269 | - ); |
|
270 | - $connector = new HookConnector($root, $view); |
|
271 | - $connector->viewToNode(); |
|
272 | - |
|
273 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
274 | - $previewConnector->connectWatcher(); |
|
275 | - |
|
276 | - return $root; |
|
277 | - }); |
|
278 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
279 | - |
|
280 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
281 | - return new LazyRoot(function () use ($c) { |
|
282 | - return $c->query('RootFolder'); |
|
283 | - }); |
|
284 | - }); |
|
285 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
286 | - |
|
287 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
288 | - $config = $c->getConfig(); |
|
289 | - return new \OC\User\Manager($config); |
|
290 | - }); |
|
291 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
292 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
293 | - |
|
294 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
295 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
296 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
297 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
298 | - }); |
|
299 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
300 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
301 | - }); |
|
302 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
303 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
304 | - }); |
|
305 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
306 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
307 | - }); |
|
308 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
310 | - }); |
|
311 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
312 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
313 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
314 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
315 | - }); |
|
316 | - return $groupManager; |
|
317 | - }); |
|
318 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
319 | - |
|
320 | - $this->registerService(Store::class, function (Server $c) { |
|
321 | - $session = $c->getSession(); |
|
322 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
323 | - $tokenProvider = $c->query(IProvider::class); |
|
324 | - } else { |
|
325 | - $tokenProvider = null; |
|
326 | - } |
|
327 | - $logger = $c->getLogger(); |
|
328 | - return new Store($session, $logger, $tokenProvider); |
|
329 | - }); |
|
330 | - $this->registerAlias(IStore::class, Store::class); |
|
331 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
332 | - $dbConnection = $c->getDatabaseConnection(); |
|
333 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
334 | - }); |
|
335 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
336 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
337 | - $crypto = $c->getCrypto(); |
|
338 | - $config = $c->getConfig(); |
|
339 | - $logger = $c->getLogger(); |
|
340 | - $timeFactory = new TimeFactory(); |
|
341 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
342 | - }); |
|
343 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
344 | - |
|
345 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
346 | - $manager = $c->getUserManager(); |
|
347 | - $session = new \OC\Session\Memory(''); |
|
348 | - $timeFactory = new TimeFactory(); |
|
349 | - // Token providers might require a working database. This code |
|
350 | - // might however be called when ownCloud is not yet setup. |
|
351 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
353 | - } else { |
|
354 | - $defaultTokenProvider = null; |
|
355 | - } |
|
356 | - |
|
357 | - $dispatcher = $c->getEventDispatcher(); |
|
358 | - |
|
359 | - $userSession = new \OC\User\Session( |
|
360 | - $manager, |
|
361 | - $session, |
|
362 | - $timeFactory, |
|
363 | - $defaultTokenProvider, |
|
364 | - $c->getConfig(), |
|
365 | - $c->getSecureRandom(), |
|
366 | - $c->getLockdownManager(), |
|
367 | - $c->getLogger() |
|
368 | - ); |
|
369 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
370 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
371 | - }); |
|
372 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
373 | - /** @var $user \OC\User\User */ |
|
374 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
375 | - }); |
|
376 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
377 | - /** @var $user \OC\User\User */ |
|
378 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
379 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
380 | - }); |
|
381 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
382 | - /** @var $user \OC\User\User */ |
|
383 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
384 | - }); |
|
385 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
386 | - /** @var $user \OC\User\User */ |
|
387 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
388 | - }); |
|
389 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
390 | - /** @var $user \OC\User\User */ |
|
391 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
394 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
395 | - }); |
|
396 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
397 | - /** @var $user \OC\User\User */ |
|
398 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
399 | - }); |
|
400 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
401 | - /** @var $user \OC\User\User */ |
|
402 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
403 | - }); |
|
404 | - $userSession->listen('\OC\User', 'logout', function () { |
|
405 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
406 | - }); |
|
407 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
408 | - /** @var $user \OC\User\User */ |
|
409 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
410 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
411 | - }); |
|
412 | - return $userSession; |
|
413 | - }); |
|
414 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
415 | - |
|
416 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
417 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
418 | - $c->getAppManager(), |
|
419 | - $c->getSession(), |
|
420 | - $c->getConfig(), |
|
421 | - $c->getActivityManager(), |
|
422 | - $c->getLogger(), |
|
423 | - $c->query(IProvider::class), |
|
424 | - $c->query(ITimeFactory::class), |
|
425 | - $c->query(EventDispatcherInterface::class) |
|
426 | - ); |
|
427 | - }); |
|
428 | - |
|
429 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
430 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
431 | - |
|
432 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
433 | - return new \OC\AllConfig( |
|
434 | - $c->getSystemConfig() |
|
435 | - ); |
|
436 | - }); |
|
437 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
438 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
439 | - |
|
440 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
441 | - return new \OC\SystemConfig($config); |
|
442 | - }); |
|
443 | - |
|
444 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
445 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
446 | - }); |
|
447 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
448 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
449 | - |
|
450 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
451 | - return new \OC\L10N\Factory( |
|
452 | - $c->getConfig(), |
|
453 | - $c->getRequest(), |
|
454 | - $c->getUserSession(), |
|
455 | - \OC::$SERVERROOT |
|
456 | - ); |
|
457 | - }); |
|
458 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
459 | - |
|
460 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
461 | - $config = $c->getConfig(); |
|
462 | - $cacheFactory = $c->getMemCacheFactory(); |
|
463 | - $request = $c->getRequest(); |
|
464 | - return new \OC\URLGenerator( |
|
465 | - $config, |
|
466 | - $cacheFactory, |
|
467 | - $request |
|
468 | - ); |
|
469 | - }); |
|
470 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
471 | - |
|
472 | - $this->registerService('AppHelper', function ($c) { |
|
473 | - return new \OC\AppHelper(); |
|
474 | - }); |
|
475 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
476 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
477 | - |
|
478 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
479 | - return new Cache\File(); |
|
480 | - }); |
|
481 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
482 | - |
|
483 | - $this->registerService(Factory::class, function (Server $c) { |
|
484 | - |
|
485 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
486 | - ArrayCache::class, |
|
487 | - ArrayCache::class, |
|
488 | - ArrayCache::class |
|
489 | - ); |
|
490 | - $config = $c->getConfig(); |
|
491 | - $request = $c->getRequest(); |
|
492 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
493 | - |
|
494 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
495 | - $v = \OC_App::getAppVersions(); |
|
496 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
497 | - $version = implode(',', $v); |
|
498 | - $instanceId = \OC_Util::getInstanceId(); |
|
499 | - $path = \OC::$SERVERROOT; |
|
500 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
501 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
502 | - $config->getSystemValue('memcache.local', null), |
|
503 | - $config->getSystemValue('memcache.distributed', null), |
|
504 | - $config->getSystemValue('memcache.locking', null) |
|
505 | - ); |
|
506 | - } |
|
507 | - return $arrayCacheFactory; |
|
508 | - |
|
509 | - }); |
|
510 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
511 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
512 | - |
|
513 | - $this->registerService('RedisFactory', function (Server $c) { |
|
514 | - $systemConfig = $c->getSystemConfig(); |
|
515 | - return new RedisFactory($systemConfig); |
|
516 | - }); |
|
517 | - |
|
518 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
519 | - return new \OC\Activity\Manager( |
|
520 | - $c->getRequest(), |
|
521 | - $c->getUserSession(), |
|
522 | - $c->getConfig(), |
|
523 | - $c->query(IValidator::class) |
|
524 | - ); |
|
525 | - }); |
|
526 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
527 | - |
|
528 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
529 | - return new \OC\Activity\EventMerger( |
|
530 | - $c->getL10N('lib') |
|
531 | - ); |
|
532 | - }); |
|
533 | - $this->registerAlias(IValidator::class, Validator::class); |
|
534 | - |
|
535 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
536 | - return new AvatarManager( |
|
537 | - $c->query(\OC\User\Manager::class), |
|
538 | - $c->getAppDataDir('avatar'), |
|
539 | - $c->getL10N('lib'), |
|
540 | - $c->getLogger(), |
|
541 | - $c->getConfig() |
|
542 | - ); |
|
543 | - }); |
|
544 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
545 | - |
|
546 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
547 | - |
|
548 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
549 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
550 | - $logger = Log::getLogClass($logType); |
|
551 | - call_user_func(array($logger, 'init')); |
|
552 | - $config = $this->getSystemConfig(); |
|
553 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
554 | - |
|
555 | - return new Log($logger, $config, null, $registry); |
|
556 | - }); |
|
557 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
558 | - |
|
559 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
560 | - $config = $c->getConfig(); |
|
561 | - return new \OC\BackgroundJob\JobList( |
|
562 | - $c->getDatabaseConnection(), |
|
563 | - $config, |
|
564 | - new TimeFactory() |
|
565 | - ); |
|
566 | - }); |
|
567 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
568 | - |
|
569 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
570 | - $cacheFactory = $c->getMemCacheFactory(); |
|
571 | - $logger = $c->getLogger(); |
|
572 | - if ($cacheFactory->isAvailableLowLatency()) { |
|
573 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
574 | - } else { |
|
575 | - $router = new \OC\Route\Router($logger); |
|
576 | - } |
|
577 | - return $router; |
|
578 | - }); |
|
579 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
580 | - |
|
581 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
582 | - return new Search(); |
|
583 | - }); |
|
584 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
585 | - |
|
586 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
587 | - return new \OC\Security\RateLimiting\Limiter( |
|
588 | - $this->getUserSession(), |
|
589 | - $this->getRequest(), |
|
590 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
591 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
592 | - ); |
|
593 | - }); |
|
594 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
595 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
596 | - $this->getMemCacheFactory(), |
|
597 | - new \OC\AppFramework\Utility\TimeFactory() |
|
598 | - ); |
|
599 | - }); |
|
600 | - |
|
601 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
602 | - return new SecureRandom(); |
|
603 | - }); |
|
604 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
605 | - |
|
606 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
607 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
608 | - }); |
|
609 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
610 | - |
|
611 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
612 | - return new Hasher($c->getConfig()); |
|
613 | - }); |
|
614 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
615 | - |
|
616 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
617 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
618 | - }); |
|
619 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
620 | - |
|
621 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
622 | - $systemConfig = $c->getSystemConfig(); |
|
623 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
624 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
625 | - if (!$factory->isValidType($type)) { |
|
626 | - throw new \OC\DatabaseException('Invalid database type'); |
|
627 | - } |
|
628 | - $connectionParams = $factory->createConnectionParams(); |
|
629 | - $connection = $factory->getConnection($type, $connectionParams); |
|
630 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
631 | - return $connection; |
|
632 | - }); |
|
633 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
634 | - |
|
635 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
636 | - $config = $c->getConfig(); |
|
637 | - return new HTTPHelper( |
|
638 | - $config, |
|
639 | - $c->getHTTPClientService() |
|
640 | - ); |
|
641 | - }); |
|
642 | - |
|
643 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
644 | - $user = \OC_User::getUser(); |
|
645 | - $uid = $user ? $user : null; |
|
646 | - return new ClientService( |
|
647 | - $c->getConfig(), |
|
648 | - new \OC\Security\CertificateManager( |
|
649 | - $uid, |
|
650 | - new View(), |
|
651 | - $c->getConfig(), |
|
652 | - $c->getLogger(), |
|
653 | - $c->getSecureRandom() |
|
654 | - ) |
|
655 | - ); |
|
656 | - }); |
|
657 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
658 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
659 | - $eventLogger = new EventLogger(); |
|
660 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
661 | - // In debug mode, module is being activated by default |
|
662 | - $eventLogger->activate(); |
|
663 | - } |
|
664 | - return $eventLogger; |
|
665 | - }); |
|
666 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
667 | - |
|
668 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
669 | - $queryLogger = new QueryLogger(); |
|
670 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
671 | - // In debug mode, module is being activated by default |
|
672 | - $queryLogger->activate(); |
|
673 | - } |
|
674 | - return $queryLogger; |
|
675 | - }); |
|
676 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
677 | - |
|
678 | - $this->registerService(TempManager::class, function (Server $c) { |
|
679 | - return new TempManager( |
|
680 | - $c->getLogger(), |
|
681 | - $c->getConfig() |
|
682 | - ); |
|
683 | - }); |
|
684 | - $this->registerAlias('TempManager', TempManager::class); |
|
685 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
686 | - |
|
687 | - $this->registerService(AppManager::class, function (Server $c) { |
|
688 | - return new \OC\App\AppManager( |
|
689 | - $c->getUserSession(), |
|
690 | - $this->getAppConfig(), |
|
691 | - $c->getGroupManager(), |
|
692 | - $c->getMemCacheFactory(), |
|
693 | - $c->getEventDispatcher() |
|
694 | - ); |
|
695 | - }); |
|
696 | - $this->registerAlias('AppManager', AppManager::class); |
|
697 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
698 | - |
|
699 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
700 | - return new DateTimeZone( |
|
701 | - $c->getConfig(), |
|
702 | - $c->getSession() |
|
703 | - ); |
|
704 | - }); |
|
705 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
706 | - |
|
707 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
708 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
709 | - |
|
710 | - return new DateTimeFormatter( |
|
711 | - $c->getDateTimeZone()->getTimeZone(), |
|
712 | - $c->getL10N('lib', $language) |
|
713 | - ); |
|
714 | - }); |
|
715 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
716 | - |
|
717 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
718 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
719 | - $listener = new UserMountCacheListener($mountCache); |
|
720 | - $listener->listen($c->getUserManager()); |
|
721 | - return $mountCache; |
|
722 | - }); |
|
723 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
724 | - |
|
725 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
726 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
727 | - $mountCache = $c->query('UserMountCache'); |
|
728 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
729 | - |
|
730 | - // builtin providers |
|
731 | - |
|
732 | - $config = $c->getConfig(); |
|
733 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
734 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
735 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
736 | - |
|
737 | - return $manager; |
|
738 | - }); |
|
739 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
740 | - |
|
741 | - $this->registerService('IniWrapper', function ($c) { |
|
742 | - return new IniGetWrapper(); |
|
743 | - }); |
|
744 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
745 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
746 | - if ($busClass) { |
|
747 | - list($app, $class) = explode('::', $busClass, 2); |
|
748 | - if ($c->getAppManager()->isInstalled($app)) { |
|
749 | - \OC_App::loadApp($app); |
|
750 | - return $c->query($class); |
|
751 | - } else { |
|
752 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
753 | - } |
|
754 | - } else { |
|
755 | - $jobList = $c->getJobList(); |
|
756 | - return new CronBus($jobList); |
|
757 | - } |
|
758 | - }); |
|
759 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
760 | - return new TrustedDomainHelper($this->getConfig()); |
|
761 | - }); |
|
762 | - $this->registerService('Throttler', function (Server $c) { |
|
763 | - return new Throttler( |
|
764 | - $c->getDatabaseConnection(), |
|
765 | - new TimeFactory(), |
|
766 | - $c->getLogger(), |
|
767 | - $c->getConfig() |
|
768 | - ); |
|
769 | - }); |
|
770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
771 | - // IConfig and IAppManager requires a working database. This code |
|
772 | - // might however be called when ownCloud is not yet setup. |
|
773 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
774 | - $config = $c->getConfig(); |
|
775 | - $appManager = $c->getAppManager(); |
|
776 | - } else { |
|
777 | - $config = null; |
|
778 | - $appManager = null; |
|
779 | - } |
|
780 | - |
|
781 | - return new Checker( |
|
782 | - new EnvironmentHelper(), |
|
783 | - new FileAccessHelper(), |
|
784 | - new AppLocator(), |
|
785 | - $config, |
|
786 | - $c->getMemCacheFactory(), |
|
787 | - $appManager, |
|
788 | - $c->getTempManager() |
|
789 | - ); |
|
790 | - }); |
|
791 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
792 | - if (isset($this['urlParams'])) { |
|
793 | - $urlParams = $this['urlParams']; |
|
794 | - } else { |
|
795 | - $urlParams = []; |
|
796 | - } |
|
797 | - |
|
798 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
799 | - && in_array('fakeinput', stream_get_wrappers()) |
|
800 | - ) { |
|
801 | - $stream = 'fakeinput://data'; |
|
802 | - } else { |
|
803 | - $stream = 'php://input'; |
|
804 | - } |
|
805 | - |
|
806 | - return new Request( |
|
807 | - [ |
|
808 | - 'get' => $_GET, |
|
809 | - 'post' => $_POST, |
|
810 | - 'files' => $_FILES, |
|
811 | - 'server' => $_SERVER, |
|
812 | - 'env' => $_ENV, |
|
813 | - 'cookies' => $_COOKIE, |
|
814 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
815 | - ? $_SERVER['REQUEST_METHOD'] |
|
816 | - : null, |
|
817 | - 'urlParams' => $urlParams, |
|
818 | - ], |
|
819 | - $this->getSecureRandom(), |
|
820 | - $this->getConfig(), |
|
821 | - $this->getCsrfTokenManager(), |
|
822 | - $stream |
|
823 | - ); |
|
824 | - }); |
|
825 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
826 | - |
|
827 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
828 | - return new Mailer( |
|
829 | - $c->getConfig(), |
|
830 | - $c->getLogger(), |
|
831 | - $c->query(Defaults::class), |
|
832 | - $c->getURLGenerator(), |
|
833 | - $c->getL10N('lib') |
|
834 | - ); |
|
835 | - }); |
|
836 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
837 | - |
|
838 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
839 | - $config = $c->getConfig(); |
|
840 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
841 | - if (is_null($factoryClass)) { |
|
842 | - throw new \Exception('ldapProviderFactory not set'); |
|
843 | - } |
|
844 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
845 | - $factory = new $factoryClass($this); |
|
846 | - return $factory->getLDAPProvider(); |
|
847 | - }); |
|
848 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
849 | - $ini = $c->getIniWrapper(); |
|
850 | - $config = $c->getConfig(); |
|
851 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
852 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
853 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
854 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
855 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
856 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
857 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
858 | - } |
|
859 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
860 | - } |
|
861 | - return new NoopLockingProvider(); |
|
862 | - }); |
|
863 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
864 | - |
|
865 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
866 | - return new \OC\Files\Mount\Manager(); |
|
867 | - }); |
|
868 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
869 | - |
|
870 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
871 | - return new \OC\Files\Type\Detection( |
|
872 | - $c->getURLGenerator(), |
|
873 | - \OC::$configDir, |
|
874 | - \OC::$SERVERROOT . '/resources/config/' |
|
875 | - ); |
|
876 | - }); |
|
877 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
878 | - |
|
879 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
880 | - return new \OC\Files\Type\Loader( |
|
881 | - $c->getDatabaseConnection() |
|
882 | - ); |
|
883 | - }); |
|
884 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
885 | - $this->registerService(BundleFetcher::class, function () { |
|
886 | - return new BundleFetcher($this->getL10N('lib')); |
|
887 | - }); |
|
888 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
889 | - return new Manager( |
|
890 | - $c->query(IValidator::class) |
|
891 | - ); |
|
892 | - }); |
|
893 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
894 | - |
|
895 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
896 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
897 | - $manager->registerCapability(function () use ($c) { |
|
898 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
899 | - }); |
|
900 | - $manager->registerCapability(function () use ($c) { |
|
901 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
902 | - }); |
|
903 | - return $manager; |
|
904 | - }); |
|
905 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
906 | - |
|
907 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
908 | - $config = $c->getConfig(); |
|
909 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
910 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
911 | - $factory = new $factoryClass($this); |
|
912 | - $manager = $factory->getManager(); |
|
913 | - |
|
914 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
915 | - $manager = $c->getUserManager(); |
|
916 | - $user = $manager->get($id); |
|
917 | - if(is_null($user)) { |
|
918 | - $l = $c->getL10N('core'); |
|
919 | - $displayName = $l->t('Unknown user'); |
|
920 | - } else { |
|
921 | - $displayName = $user->getDisplayName(); |
|
922 | - } |
|
923 | - return $displayName; |
|
924 | - }); |
|
925 | - |
|
926 | - return $manager; |
|
927 | - }); |
|
928 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
929 | - |
|
930 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
931 | - /* |
|
152 | + /** @var string */ |
|
153 | + private $webRoot; |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $webRoot |
|
157 | + * @param \OC\Config $config |
|
158 | + */ |
|
159 | + public function __construct($webRoot, \OC\Config $config) { |
|
160 | + parent::__construct(); |
|
161 | + $this->webRoot = $webRoot; |
|
162 | + |
|
163 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
164 | + return $c; |
|
165 | + }); |
|
166 | + |
|
167 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
168 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
169 | + |
|
170 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
171 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
172 | + |
|
173 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
174 | + |
|
175 | + |
|
176 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
177 | + return new PreviewManager( |
|
178 | + $c->getConfig(), |
|
179 | + $c->getRootFolder(), |
|
180 | + $c->getAppDataDir('preview'), |
|
181 | + $c->getEventDispatcher(), |
|
182 | + $c->getSession()->get('user_id') |
|
183 | + ); |
|
184 | + }); |
|
185 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
186 | + |
|
187 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
188 | + return new \OC\Preview\Watcher( |
|
189 | + $c->getAppDataDir('preview') |
|
190 | + ); |
|
191 | + }); |
|
192 | + |
|
193 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
194 | + $view = new View(); |
|
195 | + $util = new Encryption\Util( |
|
196 | + $view, |
|
197 | + $c->getUserManager(), |
|
198 | + $c->getGroupManager(), |
|
199 | + $c->getConfig() |
|
200 | + ); |
|
201 | + return new Encryption\Manager( |
|
202 | + $c->getConfig(), |
|
203 | + $c->getLogger(), |
|
204 | + $c->getL10N('core'), |
|
205 | + new View(), |
|
206 | + $util, |
|
207 | + new ArrayCache() |
|
208 | + ); |
|
209 | + }); |
|
210 | + |
|
211 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
212 | + $util = new Encryption\Util( |
|
213 | + new View(), |
|
214 | + $c->getUserManager(), |
|
215 | + $c->getGroupManager(), |
|
216 | + $c->getConfig() |
|
217 | + ); |
|
218 | + return new Encryption\File( |
|
219 | + $util, |
|
220 | + $c->getRootFolder(), |
|
221 | + $c->getShareManager() |
|
222 | + ); |
|
223 | + }); |
|
224 | + |
|
225 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
226 | + $view = new View(); |
|
227 | + $util = new Encryption\Util( |
|
228 | + $view, |
|
229 | + $c->getUserManager(), |
|
230 | + $c->getGroupManager(), |
|
231 | + $c->getConfig() |
|
232 | + ); |
|
233 | + |
|
234 | + return new Encryption\Keys\Storage($view, $util); |
|
235 | + }); |
|
236 | + $this->registerService('TagMapper', function (Server $c) { |
|
237 | + return new TagMapper($c->getDatabaseConnection()); |
|
238 | + }); |
|
239 | + |
|
240 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
241 | + $tagMapper = $c->query('TagMapper'); |
|
242 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
243 | + }); |
|
244 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
245 | + |
|
246 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
247 | + $config = $c->getConfig(); |
|
248 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
249 | + return new $factoryClass($this); |
|
250 | + }); |
|
251 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
252 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
253 | + }); |
|
254 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
255 | + |
|
256 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
257 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
258 | + }); |
|
259 | + $this->registerService('RootFolder', function (Server $c) { |
|
260 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
261 | + $view = new View(); |
|
262 | + $root = new Root( |
|
263 | + $manager, |
|
264 | + $view, |
|
265 | + null, |
|
266 | + $c->getUserMountCache(), |
|
267 | + $this->getLogger(), |
|
268 | + $this->getUserManager() |
|
269 | + ); |
|
270 | + $connector = new HookConnector($root, $view); |
|
271 | + $connector->viewToNode(); |
|
272 | + |
|
273 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
274 | + $previewConnector->connectWatcher(); |
|
275 | + |
|
276 | + return $root; |
|
277 | + }); |
|
278 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
279 | + |
|
280 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
281 | + return new LazyRoot(function () use ($c) { |
|
282 | + return $c->query('RootFolder'); |
|
283 | + }); |
|
284 | + }); |
|
285 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
286 | + |
|
287 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
288 | + $config = $c->getConfig(); |
|
289 | + return new \OC\User\Manager($config); |
|
290 | + }); |
|
291 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
292 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
293 | + |
|
294 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
295 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
296 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
297 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
298 | + }); |
|
299 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
300 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
301 | + }); |
|
302 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
303 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
304 | + }); |
|
305 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
306 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
307 | + }); |
|
308 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
310 | + }); |
|
311 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
312 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
313 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
314 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
315 | + }); |
|
316 | + return $groupManager; |
|
317 | + }); |
|
318 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
319 | + |
|
320 | + $this->registerService(Store::class, function (Server $c) { |
|
321 | + $session = $c->getSession(); |
|
322 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
323 | + $tokenProvider = $c->query(IProvider::class); |
|
324 | + } else { |
|
325 | + $tokenProvider = null; |
|
326 | + } |
|
327 | + $logger = $c->getLogger(); |
|
328 | + return new Store($session, $logger, $tokenProvider); |
|
329 | + }); |
|
330 | + $this->registerAlias(IStore::class, Store::class); |
|
331 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
332 | + $dbConnection = $c->getDatabaseConnection(); |
|
333 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
334 | + }); |
|
335 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
336 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
337 | + $crypto = $c->getCrypto(); |
|
338 | + $config = $c->getConfig(); |
|
339 | + $logger = $c->getLogger(); |
|
340 | + $timeFactory = new TimeFactory(); |
|
341 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
342 | + }); |
|
343 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
344 | + |
|
345 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
346 | + $manager = $c->getUserManager(); |
|
347 | + $session = new \OC\Session\Memory(''); |
|
348 | + $timeFactory = new TimeFactory(); |
|
349 | + // Token providers might require a working database. This code |
|
350 | + // might however be called when ownCloud is not yet setup. |
|
351 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
352 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
353 | + } else { |
|
354 | + $defaultTokenProvider = null; |
|
355 | + } |
|
356 | + |
|
357 | + $dispatcher = $c->getEventDispatcher(); |
|
358 | + |
|
359 | + $userSession = new \OC\User\Session( |
|
360 | + $manager, |
|
361 | + $session, |
|
362 | + $timeFactory, |
|
363 | + $defaultTokenProvider, |
|
364 | + $c->getConfig(), |
|
365 | + $c->getSecureRandom(), |
|
366 | + $c->getLockdownManager(), |
|
367 | + $c->getLogger() |
|
368 | + ); |
|
369 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
370 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
371 | + }); |
|
372 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
373 | + /** @var $user \OC\User\User */ |
|
374 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
375 | + }); |
|
376 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
377 | + /** @var $user \OC\User\User */ |
|
378 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
379 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
380 | + }); |
|
381 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
382 | + /** @var $user \OC\User\User */ |
|
383 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
384 | + }); |
|
385 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
386 | + /** @var $user \OC\User\User */ |
|
387 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
388 | + }); |
|
389 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
390 | + /** @var $user \OC\User\User */ |
|
391 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
394 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
395 | + }); |
|
396 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
397 | + /** @var $user \OC\User\User */ |
|
398 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
399 | + }); |
|
400 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
401 | + /** @var $user \OC\User\User */ |
|
402 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
403 | + }); |
|
404 | + $userSession->listen('\OC\User', 'logout', function () { |
|
405 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
406 | + }); |
|
407 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
408 | + /** @var $user \OC\User\User */ |
|
409 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
410 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
411 | + }); |
|
412 | + return $userSession; |
|
413 | + }); |
|
414 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
415 | + |
|
416 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
417 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
418 | + $c->getAppManager(), |
|
419 | + $c->getSession(), |
|
420 | + $c->getConfig(), |
|
421 | + $c->getActivityManager(), |
|
422 | + $c->getLogger(), |
|
423 | + $c->query(IProvider::class), |
|
424 | + $c->query(ITimeFactory::class), |
|
425 | + $c->query(EventDispatcherInterface::class) |
|
426 | + ); |
|
427 | + }); |
|
428 | + |
|
429 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
430 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
431 | + |
|
432 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
433 | + return new \OC\AllConfig( |
|
434 | + $c->getSystemConfig() |
|
435 | + ); |
|
436 | + }); |
|
437 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
438 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
439 | + |
|
440 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
441 | + return new \OC\SystemConfig($config); |
|
442 | + }); |
|
443 | + |
|
444 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
445 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
446 | + }); |
|
447 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
448 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
449 | + |
|
450 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
451 | + return new \OC\L10N\Factory( |
|
452 | + $c->getConfig(), |
|
453 | + $c->getRequest(), |
|
454 | + $c->getUserSession(), |
|
455 | + \OC::$SERVERROOT |
|
456 | + ); |
|
457 | + }); |
|
458 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
459 | + |
|
460 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
461 | + $config = $c->getConfig(); |
|
462 | + $cacheFactory = $c->getMemCacheFactory(); |
|
463 | + $request = $c->getRequest(); |
|
464 | + return new \OC\URLGenerator( |
|
465 | + $config, |
|
466 | + $cacheFactory, |
|
467 | + $request |
|
468 | + ); |
|
469 | + }); |
|
470 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
471 | + |
|
472 | + $this->registerService('AppHelper', function ($c) { |
|
473 | + return new \OC\AppHelper(); |
|
474 | + }); |
|
475 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
476 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
477 | + |
|
478 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
479 | + return new Cache\File(); |
|
480 | + }); |
|
481 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
482 | + |
|
483 | + $this->registerService(Factory::class, function (Server $c) { |
|
484 | + |
|
485 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
486 | + ArrayCache::class, |
|
487 | + ArrayCache::class, |
|
488 | + ArrayCache::class |
|
489 | + ); |
|
490 | + $config = $c->getConfig(); |
|
491 | + $request = $c->getRequest(); |
|
492 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
493 | + |
|
494 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
495 | + $v = \OC_App::getAppVersions(); |
|
496 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
497 | + $version = implode(',', $v); |
|
498 | + $instanceId = \OC_Util::getInstanceId(); |
|
499 | + $path = \OC::$SERVERROOT; |
|
500 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
501 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
502 | + $config->getSystemValue('memcache.local', null), |
|
503 | + $config->getSystemValue('memcache.distributed', null), |
|
504 | + $config->getSystemValue('memcache.locking', null) |
|
505 | + ); |
|
506 | + } |
|
507 | + return $arrayCacheFactory; |
|
508 | + |
|
509 | + }); |
|
510 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
511 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
512 | + |
|
513 | + $this->registerService('RedisFactory', function (Server $c) { |
|
514 | + $systemConfig = $c->getSystemConfig(); |
|
515 | + return new RedisFactory($systemConfig); |
|
516 | + }); |
|
517 | + |
|
518 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
519 | + return new \OC\Activity\Manager( |
|
520 | + $c->getRequest(), |
|
521 | + $c->getUserSession(), |
|
522 | + $c->getConfig(), |
|
523 | + $c->query(IValidator::class) |
|
524 | + ); |
|
525 | + }); |
|
526 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
527 | + |
|
528 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
529 | + return new \OC\Activity\EventMerger( |
|
530 | + $c->getL10N('lib') |
|
531 | + ); |
|
532 | + }); |
|
533 | + $this->registerAlias(IValidator::class, Validator::class); |
|
534 | + |
|
535 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
536 | + return new AvatarManager( |
|
537 | + $c->query(\OC\User\Manager::class), |
|
538 | + $c->getAppDataDir('avatar'), |
|
539 | + $c->getL10N('lib'), |
|
540 | + $c->getLogger(), |
|
541 | + $c->getConfig() |
|
542 | + ); |
|
543 | + }); |
|
544 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
545 | + |
|
546 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
547 | + |
|
548 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
549 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
550 | + $logger = Log::getLogClass($logType); |
|
551 | + call_user_func(array($logger, 'init')); |
|
552 | + $config = $this->getSystemConfig(); |
|
553 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
554 | + |
|
555 | + return new Log($logger, $config, null, $registry); |
|
556 | + }); |
|
557 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
558 | + |
|
559 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
560 | + $config = $c->getConfig(); |
|
561 | + return new \OC\BackgroundJob\JobList( |
|
562 | + $c->getDatabaseConnection(), |
|
563 | + $config, |
|
564 | + new TimeFactory() |
|
565 | + ); |
|
566 | + }); |
|
567 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
568 | + |
|
569 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
570 | + $cacheFactory = $c->getMemCacheFactory(); |
|
571 | + $logger = $c->getLogger(); |
|
572 | + if ($cacheFactory->isAvailableLowLatency()) { |
|
573 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
574 | + } else { |
|
575 | + $router = new \OC\Route\Router($logger); |
|
576 | + } |
|
577 | + return $router; |
|
578 | + }); |
|
579 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
580 | + |
|
581 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
582 | + return new Search(); |
|
583 | + }); |
|
584 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
585 | + |
|
586 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
587 | + return new \OC\Security\RateLimiting\Limiter( |
|
588 | + $this->getUserSession(), |
|
589 | + $this->getRequest(), |
|
590 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
591 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
592 | + ); |
|
593 | + }); |
|
594 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
595 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
596 | + $this->getMemCacheFactory(), |
|
597 | + new \OC\AppFramework\Utility\TimeFactory() |
|
598 | + ); |
|
599 | + }); |
|
600 | + |
|
601 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
602 | + return new SecureRandom(); |
|
603 | + }); |
|
604 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
605 | + |
|
606 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
607 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
608 | + }); |
|
609 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
610 | + |
|
611 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
612 | + return new Hasher($c->getConfig()); |
|
613 | + }); |
|
614 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
615 | + |
|
616 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
617 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
618 | + }); |
|
619 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
620 | + |
|
621 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
622 | + $systemConfig = $c->getSystemConfig(); |
|
623 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
624 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
625 | + if (!$factory->isValidType($type)) { |
|
626 | + throw new \OC\DatabaseException('Invalid database type'); |
|
627 | + } |
|
628 | + $connectionParams = $factory->createConnectionParams(); |
|
629 | + $connection = $factory->getConnection($type, $connectionParams); |
|
630 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
631 | + return $connection; |
|
632 | + }); |
|
633 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
634 | + |
|
635 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
636 | + $config = $c->getConfig(); |
|
637 | + return new HTTPHelper( |
|
638 | + $config, |
|
639 | + $c->getHTTPClientService() |
|
640 | + ); |
|
641 | + }); |
|
642 | + |
|
643 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
644 | + $user = \OC_User::getUser(); |
|
645 | + $uid = $user ? $user : null; |
|
646 | + return new ClientService( |
|
647 | + $c->getConfig(), |
|
648 | + new \OC\Security\CertificateManager( |
|
649 | + $uid, |
|
650 | + new View(), |
|
651 | + $c->getConfig(), |
|
652 | + $c->getLogger(), |
|
653 | + $c->getSecureRandom() |
|
654 | + ) |
|
655 | + ); |
|
656 | + }); |
|
657 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
658 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
659 | + $eventLogger = new EventLogger(); |
|
660 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
661 | + // In debug mode, module is being activated by default |
|
662 | + $eventLogger->activate(); |
|
663 | + } |
|
664 | + return $eventLogger; |
|
665 | + }); |
|
666 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
667 | + |
|
668 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
669 | + $queryLogger = new QueryLogger(); |
|
670 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
671 | + // In debug mode, module is being activated by default |
|
672 | + $queryLogger->activate(); |
|
673 | + } |
|
674 | + return $queryLogger; |
|
675 | + }); |
|
676 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
677 | + |
|
678 | + $this->registerService(TempManager::class, function (Server $c) { |
|
679 | + return new TempManager( |
|
680 | + $c->getLogger(), |
|
681 | + $c->getConfig() |
|
682 | + ); |
|
683 | + }); |
|
684 | + $this->registerAlias('TempManager', TempManager::class); |
|
685 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
686 | + |
|
687 | + $this->registerService(AppManager::class, function (Server $c) { |
|
688 | + return new \OC\App\AppManager( |
|
689 | + $c->getUserSession(), |
|
690 | + $this->getAppConfig(), |
|
691 | + $c->getGroupManager(), |
|
692 | + $c->getMemCacheFactory(), |
|
693 | + $c->getEventDispatcher() |
|
694 | + ); |
|
695 | + }); |
|
696 | + $this->registerAlias('AppManager', AppManager::class); |
|
697 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
698 | + |
|
699 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
700 | + return new DateTimeZone( |
|
701 | + $c->getConfig(), |
|
702 | + $c->getSession() |
|
703 | + ); |
|
704 | + }); |
|
705 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
706 | + |
|
707 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
708 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
709 | + |
|
710 | + return new DateTimeFormatter( |
|
711 | + $c->getDateTimeZone()->getTimeZone(), |
|
712 | + $c->getL10N('lib', $language) |
|
713 | + ); |
|
714 | + }); |
|
715 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
716 | + |
|
717 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
718 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
719 | + $listener = new UserMountCacheListener($mountCache); |
|
720 | + $listener->listen($c->getUserManager()); |
|
721 | + return $mountCache; |
|
722 | + }); |
|
723 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
724 | + |
|
725 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
726 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
727 | + $mountCache = $c->query('UserMountCache'); |
|
728 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
729 | + |
|
730 | + // builtin providers |
|
731 | + |
|
732 | + $config = $c->getConfig(); |
|
733 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
734 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
735 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
736 | + |
|
737 | + return $manager; |
|
738 | + }); |
|
739 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
740 | + |
|
741 | + $this->registerService('IniWrapper', function ($c) { |
|
742 | + return new IniGetWrapper(); |
|
743 | + }); |
|
744 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
745 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
746 | + if ($busClass) { |
|
747 | + list($app, $class) = explode('::', $busClass, 2); |
|
748 | + if ($c->getAppManager()->isInstalled($app)) { |
|
749 | + \OC_App::loadApp($app); |
|
750 | + return $c->query($class); |
|
751 | + } else { |
|
752 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
753 | + } |
|
754 | + } else { |
|
755 | + $jobList = $c->getJobList(); |
|
756 | + return new CronBus($jobList); |
|
757 | + } |
|
758 | + }); |
|
759 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
760 | + return new TrustedDomainHelper($this->getConfig()); |
|
761 | + }); |
|
762 | + $this->registerService('Throttler', function (Server $c) { |
|
763 | + return new Throttler( |
|
764 | + $c->getDatabaseConnection(), |
|
765 | + new TimeFactory(), |
|
766 | + $c->getLogger(), |
|
767 | + $c->getConfig() |
|
768 | + ); |
|
769 | + }); |
|
770 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
771 | + // IConfig and IAppManager requires a working database. This code |
|
772 | + // might however be called when ownCloud is not yet setup. |
|
773 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
774 | + $config = $c->getConfig(); |
|
775 | + $appManager = $c->getAppManager(); |
|
776 | + } else { |
|
777 | + $config = null; |
|
778 | + $appManager = null; |
|
779 | + } |
|
780 | + |
|
781 | + return new Checker( |
|
782 | + new EnvironmentHelper(), |
|
783 | + new FileAccessHelper(), |
|
784 | + new AppLocator(), |
|
785 | + $config, |
|
786 | + $c->getMemCacheFactory(), |
|
787 | + $appManager, |
|
788 | + $c->getTempManager() |
|
789 | + ); |
|
790 | + }); |
|
791 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
792 | + if (isset($this['urlParams'])) { |
|
793 | + $urlParams = $this['urlParams']; |
|
794 | + } else { |
|
795 | + $urlParams = []; |
|
796 | + } |
|
797 | + |
|
798 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
799 | + && in_array('fakeinput', stream_get_wrappers()) |
|
800 | + ) { |
|
801 | + $stream = 'fakeinput://data'; |
|
802 | + } else { |
|
803 | + $stream = 'php://input'; |
|
804 | + } |
|
805 | + |
|
806 | + return new Request( |
|
807 | + [ |
|
808 | + 'get' => $_GET, |
|
809 | + 'post' => $_POST, |
|
810 | + 'files' => $_FILES, |
|
811 | + 'server' => $_SERVER, |
|
812 | + 'env' => $_ENV, |
|
813 | + 'cookies' => $_COOKIE, |
|
814 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
815 | + ? $_SERVER['REQUEST_METHOD'] |
|
816 | + : null, |
|
817 | + 'urlParams' => $urlParams, |
|
818 | + ], |
|
819 | + $this->getSecureRandom(), |
|
820 | + $this->getConfig(), |
|
821 | + $this->getCsrfTokenManager(), |
|
822 | + $stream |
|
823 | + ); |
|
824 | + }); |
|
825 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
826 | + |
|
827 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
828 | + return new Mailer( |
|
829 | + $c->getConfig(), |
|
830 | + $c->getLogger(), |
|
831 | + $c->query(Defaults::class), |
|
832 | + $c->getURLGenerator(), |
|
833 | + $c->getL10N('lib') |
|
834 | + ); |
|
835 | + }); |
|
836 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
837 | + |
|
838 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
839 | + $config = $c->getConfig(); |
|
840 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
841 | + if (is_null($factoryClass)) { |
|
842 | + throw new \Exception('ldapProviderFactory not set'); |
|
843 | + } |
|
844 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
845 | + $factory = new $factoryClass($this); |
|
846 | + return $factory->getLDAPProvider(); |
|
847 | + }); |
|
848 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
849 | + $ini = $c->getIniWrapper(); |
|
850 | + $config = $c->getConfig(); |
|
851 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
852 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
853 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
854 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
855 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
856 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
857 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
858 | + } |
|
859 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
860 | + } |
|
861 | + return new NoopLockingProvider(); |
|
862 | + }); |
|
863 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
864 | + |
|
865 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
866 | + return new \OC\Files\Mount\Manager(); |
|
867 | + }); |
|
868 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
869 | + |
|
870 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
871 | + return new \OC\Files\Type\Detection( |
|
872 | + $c->getURLGenerator(), |
|
873 | + \OC::$configDir, |
|
874 | + \OC::$SERVERROOT . '/resources/config/' |
|
875 | + ); |
|
876 | + }); |
|
877 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
878 | + |
|
879 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
880 | + return new \OC\Files\Type\Loader( |
|
881 | + $c->getDatabaseConnection() |
|
882 | + ); |
|
883 | + }); |
|
884 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
885 | + $this->registerService(BundleFetcher::class, function () { |
|
886 | + return new BundleFetcher($this->getL10N('lib')); |
|
887 | + }); |
|
888 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
889 | + return new Manager( |
|
890 | + $c->query(IValidator::class) |
|
891 | + ); |
|
892 | + }); |
|
893 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
894 | + |
|
895 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
896 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
897 | + $manager->registerCapability(function () use ($c) { |
|
898 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
899 | + }); |
|
900 | + $manager->registerCapability(function () use ($c) { |
|
901 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
902 | + }); |
|
903 | + return $manager; |
|
904 | + }); |
|
905 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
906 | + |
|
907 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
908 | + $config = $c->getConfig(); |
|
909 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
910 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
911 | + $factory = new $factoryClass($this); |
|
912 | + $manager = $factory->getManager(); |
|
913 | + |
|
914 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
915 | + $manager = $c->getUserManager(); |
|
916 | + $user = $manager->get($id); |
|
917 | + if(is_null($user)) { |
|
918 | + $l = $c->getL10N('core'); |
|
919 | + $displayName = $l->t('Unknown user'); |
|
920 | + } else { |
|
921 | + $displayName = $user->getDisplayName(); |
|
922 | + } |
|
923 | + return $displayName; |
|
924 | + }); |
|
925 | + |
|
926 | + return $manager; |
|
927 | + }); |
|
928 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
929 | + |
|
930 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
931 | + /* |
|
932 | 932 | * Dark magic for autoloader. |
933 | 933 | * If we do a class_exists it will try to load the class which will |
934 | 934 | * make composer cache the result. Resulting in errors when enabling |
935 | 935 | * the theming app. |
936 | 936 | */ |
937 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
938 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
939 | - $classExists = true; |
|
940 | - } else { |
|
941 | - $classExists = false; |
|
942 | - } |
|
943 | - |
|
944 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
945 | - return new ThemingDefaults( |
|
946 | - $c->getConfig(), |
|
947 | - $c->getL10N('theming'), |
|
948 | - $c->getURLGenerator(), |
|
949 | - $c->getAppDataDir('theming'), |
|
950 | - $c->getMemCacheFactory(), |
|
951 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
952 | - $this->getAppManager() |
|
953 | - ); |
|
954 | - } |
|
955 | - return new \OC_Defaults(); |
|
956 | - }); |
|
957 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
958 | - /** @var Factory $cacheFactory */ |
|
959 | - $cacheFactory = $c->query(Factory::class); |
|
960 | - return new SCSSCacher( |
|
961 | - $c->getLogger(), |
|
962 | - $c->query(\OC\Files\AppData\Factory::class), |
|
963 | - $c->getURLGenerator(), |
|
964 | - $c->getConfig(), |
|
965 | - $c->getThemingDefaults(), |
|
966 | - \OC::$SERVERROOT, |
|
967 | - $cacheFactory->createDistributed('SCSS') |
|
968 | - ); |
|
969 | - }); |
|
970 | - $this->registerService(EventDispatcher::class, function () { |
|
971 | - return new EventDispatcher(); |
|
972 | - }); |
|
973 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
974 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
975 | - |
|
976 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
977 | - // FIXME: Instantiiated here due to cyclic dependency |
|
978 | - $request = new Request( |
|
979 | - [ |
|
980 | - 'get' => $_GET, |
|
981 | - 'post' => $_POST, |
|
982 | - 'files' => $_FILES, |
|
983 | - 'server' => $_SERVER, |
|
984 | - 'env' => $_ENV, |
|
985 | - 'cookies' => $_COOKIE, |
|
986 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
987 | - ? $_SERVER['REQUEST_METHOD'] |
|
988 | - : null, |
|
989 | - ], |
|
990 | - $c->getSecureRandom(), |
|
991 | - $c->getConfig() |
|
992 | - ); |
|
993 | - |
|
994 | - return new CryptoWrapper( |
|
995 | - $c->getConfig(), |
|
996 | - $c->getCrypto(), |
|
997 | - $c->getSecureRandom(), |
|
998 | - $request |
|
999 | - ); |
|
1000 | - }); |
|
1001 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1002 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1003 | - |
|
1004 | - return new CsrfTokenManager( |
|
1005 | - $tokenGenerator, |
|
1006 | - $c->query(SessionStorage::class) |
|
1007 | - ); |
|
1008 | - }); |
|
1009 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1010 | - return new SessionStorage($c->getSession()); |
|
1011 | - }); |
|
1012 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1013 | - return new ContentSecurityPolicyManager(); |
|
1014 | - }); |
|
1015 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1016 | - |
|
1017 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1018 | - return new ContentSecurityPolicyNonceManager( |
|
1019 | - $c->getCsrfTokenManager(), |
|
1020 | - $c->getRequest() |
|
1021 | - ); |
|
1022 | - }); |
|
1023 | - |
|
1024 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1025 | - $config = $c->getConfig(); |
|
1026 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1027 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1028 | - $factory = new $factoryClass($this); |
|
1029 | - |
|
1030 | - $manager = new \OC\Share20\Manager( |
|
1031 | - $c->getLogger(), |
|
1032 | - $c->getConfig(), |
|
1033 | - $c->getSecureRandom(), |
|
1034 | - $c->getHasher(), |
|
1035 | - $c->getMountManager(), |
|
1036 | - $c->getGroupManager(), |
|
1037 | - $c->getL10N('lib'), |
|
1038 | - $c->getL10NFactory(), |
|
1039 | - $factory, |
|
1040 | - $c->getUserManager(), |
|
1041 | - $c->getLazyRootFolder(), |
|
1042 | - $c->getEventDispatcher(), |
|
1043 | - $c->getMailer(), |
|
1044 | - $c->getURLGenerator(), |
|
1045 | - $c->getThemingDefaults() |
|
1046 | - ); |
|
1047 | - |
|
1048 | - return $manager; |
|
1049 | - }); |
|
1050 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1051 | - |
|
1052 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1053 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1054 | - |
|
1055 | - // register default plugins |
|
1056 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1057 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1058 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1059 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1060 | - |
|
1061 | - return $instance; |
|
1062 | - }); |
|
1063 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1064 | - |
|
1065 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1066 | - |
|
1067 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1068 | - $manager = new \OC\Settings\Manager( |
|
1069 | - $c->getLogger(), |
|
1070 | - $c->getDatabaseConnection(), |
|
1071 | - $c->getL10N('lib'), |
|
1072 | - $c->getConfig(), |
|
1073 | - $c->getEncryptionManager(), |
|
1074 | - $c->getUserManager(), |
|
1075 | - $c->getLockingProvider(), |
|
1076 | - $c->getRequest(), |
|
1077 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1078 | - $c->getURLGenerator(), |
|
1079 | - $c->query(AccountManager::class), |
|
1080 | - $c->getGroupManager(), |
|
1081 | - $c->getL10NFactory(), |
|
1082 | - $c->getThemingDefaults(), |
|
1083 | - $c->getAppManager() |
|
1084 | - ); |
|
1085 | - return $manager; |
|
1086 | - }); |
|
1087 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1088 | - return new \OC\Files\AppData\Factory( |
|
1089 | - $c->getRootFolder(), |
|
1090 | - $c->getSystemConfig() |
|
1091 | - ); |
|
1092 | - }); |
|
1093 | - |
|
1094 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1095 | - return new LockdownManager(function () use ($c) { |
|
1096 | - return $c->getSession(); |
|
1097 | - }); |
|
1098 | - }); |
|
1099 | - |
|
1100 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1101 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1102 | - }); |
|
1103 | - |
|
1104 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1105 | - return new CloudIdManager(); |
|
1106 | - }); |
|
1107 | - |
|
1108 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1109 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1110 | - |
|
1111 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1112 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1113 | - |
|
1114 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1115 | - return new Defaults( |
|
1116 | - $c->getThemingDefaults() |
|
1117 | - ); |
|
1118 | - }); |
|
1119 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1120 | - |
|
1121 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1122 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1123 | - }); |
|
1124 | - |
|
1125 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1126 | - return new ShareHelper( |
|
1127 | - $c->query(\OCP\Share\IManager::class) |
|
1128 | - ); |
|
1129 | - }); |
|
1130 | - |
|
1131 | - $this->registerService(Installer::class, function(Server $c) { |
|
1132 | - return new Installer( |
|
1133 | - $c->getAppFetcher(), |
|
1134 | - $c->getHTTPClientService(), |
|
1135 | - $c->getTempManager(), |
|
1136 | - $c->getLogger(), |
|
1137 | - $c->getConfig() |
|
1138 | - ); |
|
1139 | - }); |
|
1140 | - |
|
1141 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1142 | - return new ApiFactory($c->getHTTPClientService()); |
|
1143 | - }); |
|
1144 | - |
|
1145 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1146 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1147 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1148 | - }); |
|
1149 | - |
|
1150 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1151 | - return new ContactsStore( |
|
1152 | - $c->getContactsManager(), |
|
1153 | - $c->getConfig(), |
|
1154 | - $c->getUserManager(), |
|
1155 | - $c->getGroupManager() |
|
1156 | - ); |
|
1157 | - }); |
|
1158 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1159 | - |
|
1160 | - $this->connectDispatcher(); |
|
1161 | - } |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * @return \OCP\Calendar\IManager |
|
1165 | - */ |
|
1166 | - public function getCalendarManager() { |
|
1167 | - return $this->query('CalendarManager'); |
|
1168 | - } |
|
1169 | - |
|
1170 | - private function connectDispatcher() { |
|
1171 | - $dispatcher = $this->getEventDispatcher(); |
|
1172 | - |
|
1173 | - // Delete avatar on user deletion |
|
1174 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1175 | - $logger = $this->getLogger(); |
|
1176 | - $manager = $this->getAvatarManager(); |
|
1177 | - /** @var IUser $user */ |
|
1178 | - $user = $e->getSubject(); |
|
1179 | - |
|
1180 | - try { |
|
1181 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1182 | - $avatar->remove(); |
|
1183 | - } catch (NotFoundException $e) { |
|
1184 | - // no avatar to remove |
|
1185 | - } catch (\Exception $e) { |
|
1186 | - // Ignore exceptions |
|
1187 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1188 | - } |
|
1189 | - }); |
|
1190 | - |
|
1191 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1192 | - $manager = $this->getAvatarManager(); |
|
1193 | - /** @var IUser $user */ |
|
1194 | - $user = $e->getSubject(); |
|
1195 | - $feature = $e->getArgument('feature'); |
|
1196 | - $oldValue = $e->getArgument('oldValue'); |
|
1197 | - $value = $e->getArgument('value'); |
|
1198 | - |
|
1199 | - try { |
|
1200 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1201 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1202 | - } catch (NotFoundException $e) { |
|
1203 | - // no avatar to remove |
|
1204 | - } |
|
1205 | - }); |
|
1206 | - } |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * @return \OCP\Contacts\IManager |
|
1210 | - */ |
|
1211 | - public function getContactsManager() { |
|
1212 | - return $this->query('ContactsManager'); |
|
1213 | - } |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * @return \OC\Encryption\Manager |
|
1217 | - */ |
|
1218 | - public function getEncryptionManager() { |
|
1219 | - return $this->query('EncryptionManager'); |
|
1220 | - } |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * @return \OC\Encryption\File |
|
1224 | - */ |
|
1225 | - public function getEncryptionFilesHelper() { |
|
1226 | - return $this->query('EncryptionFileHelper'); |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * @return \OCP\Encryption\Keys\IStorage |
|
1231 | - */ |
|
1232 | - public function getEncryptionKeyStorage() { |
|
1233 | - return $this->query('EncryptionKeyStorage'); |
|
1234 | - } |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * The current request object holding all information about the request |
|
1238 | - * currently being processed is returned from this method. |
|
1239 | - * In case the current execution was not initiated by a web request null is returned |
|
1240 | - * |
|
1241 | - * @return \OCP\IRequest |
|
1242 | - */ |
|
1243 | - public function getRequest() { |
|
1244 | - return $this->query('Request'); |
|
1245 | - } |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * Returns the preview manager which can create preview images for a given file |
|
1249 | - * |
|
1250 | - * @return \OCP\IPreview |
|
1251 | - */ |
|
1252 | - public function getPreviewManager() { |
|
1253 | - return $this->query('PreviewManager'); |
|
1254 | - } |
|
1255 | - |
|
1256 | - /** |
|
1257 | - * Returns the tag manager which can get and set tags for different object types |
|
1258 | - * |
|
1259 | - * @see \OCP\ITagManager::load() |
|
1260 | - * @return \OCP\ITagManager |
|
1261 | - */ |
|
1262 | - public function getTagManager() { |
|
1263 | - return $this->query('TagManager'); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Returns the system-tag manager |
|
1268 | - * |
|
1269 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1270 | - * |
|
1271 | - * @since 9.0.0 |
|
1272 | - */ |
|
1273 | - public function getSystemTagManager() { |
|
1274 | - return $this->query('SystemTagManager'); |
|
1275 | - } |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * Returns the system-tag object mapper |
|
1279 | - * |
|
1280 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1281 | - * |
|
1282 | - * @since 9.0.0 |
|
1283 | - */ |
|
1284 | - public function getSystemTagObjectMapper() { |
|
1285 | - return $this->query('SystemTagObjectMapper'); |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * Returns the avatar manager, used for avatar functionality |
|
1290 | - * |
|
1291 | - * @return \OCP\IAvatarManager |
|
1292 | - */ |
|
1293 | - public function getAvatarManager() { |
|
1294 | - return $this->query('AvatarManager'); |
|
1295 | - } |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * Returns the root folder of ownCloud's data directory |
|
1299 | - * |
|
1300 | - * @return \OCP\Files\IRootFolder |
|
1301 | - */ |
|
1302 | - public function getRootFolder() { |
|
1303 | - return $this->query('LazyRootFolder'); |
|
1304 | - } |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * Returns the root folder of ownCloud's data directory |
|
1308 | - * This is the lazy variant so this gets only initialized once it |
|
1309 | - * is actually used. |
|
1310 | - * |
|
1311 | - * @return \OCP\Files\IRootFolder |
|
1312 | - */ |
|
1313 | - public function getLazyRootFolder() { |
|
1314 | - return $this->query('LazyRootFolder'); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * Returns a view to ownCloud's files folder |
|
1319 | - * |
|
1320 | - * @param string $userId user ID |
|
1321 | - * @return \OCP\Files\Folder|null |
|
1322 | - */ |
|
1323 | - public function getUserFolder($userId = null) { |
|
1324 | - if ($userId === null) { |
|
1325 | - $user = $this->getUserSession()->getUser(); |
|
1326 | - if (!$user) { |
|
1327 | - return null; |
|
1328 | - } |
|
1329 | - $userId = $user->getUID(); |
|
1330 | - } |
|
1331 | - $root = $this->getRootFolder(); |
|
1332 | - return $root->getUserFolder($userId); |
|
1333 | - } |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Returns an app-specific view in ownClouds data directory |
|
1337 | - * |
|
1338 | - * @return \OCP\Files\Folder |
|
1339 | - * @deprecated since 9.2.0 use IAppData |
|
1340 | - */ |
|
1341 | - public function getAppFolder() { |
|
1342 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1343 | - $root = $this->getRootFolder(); |
|
1344 | - if (!$root->nodeExists($dir)) { |
|
1345 | - $folder = $root->newFolder($dir); |
|
1346 | - } else { |
|
1347 | - $folder = $root->get($dir); |
|
1348 | - } |
|
1349 | - return $folder; |
|
1350 | - } |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * @return \OC\User\Manager |
|
1354 | - */ |
|
1355 | - public function getUserManager() { |
|
1356 | - return $this->query('UserManager'); |
|
1357 | - } |
|
1358 | - |
|
1359 | - /** |
|
1360 | - * @return \OC\Group\Manager |
|
1361 | - */ |
|
1362 | - public function getGroupManager() { |
|
1363 | - return $this->query('GroupManager'); |
|
1364 | - } |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * @return \OC\User\Session |
|
1368 | - */ |
|
1369 | - public function getUserSession() { |
|
1370 | - return $this->query('UserSession'); |
|
1371 | - } |
|
1372 | - |
|
1373 | - /** |
|
1374 | - * @return \OCP\ISession |
|
1375 | - */ |
|
1376 | - public function getSession() { |
|
1377 | - return $this->query('UserSession')->getSession(); |
|
1378 | - } |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * @param \OCP\ISession $session |
|
1382 | - */ |
|
1383 | - public function setSession(\OCP\ISession $session) { |
|
1384 | - $this->query(SessionStorage::class)->setSession($session); |
|
1385 | - $this->query('UserSession')->setSession($session); |
|
1386 | - $this->query(Store::class)->setSession($session); |
|
1387 | - } |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1391 | - */ |
|
1392 | - public function getTwoFactorAuthManager() { |
|
1393 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1394 | - } |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * @return \OC\NavigationManager |
|
1398 | - */ |
|
1399 | - public function getNavigationManager() { |
|
1400 | - return $this->query('NavigationManager'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * @return \OCP\IConfig |
|
1405 | - */ |
|
1406 | - public function getConfig() { |
|
1407 | - return $this->query('AllConfig'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * @return \OC\SystemConfig |
|
1412 | - */ |
|
1413 | - public function getSystemConfig() { |
|
1414 | - return $this->query('SystemConfig'); |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Returns the app config manager |
|
1419 | - * |
|
1420 | - * @return \OCP\IAppConfig |
|
1421 | - */ |
|
1422 | - public function getAppConfig() { |
|
1423 | - return $this->query('AppConfig'); |
|
1424 | - } |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * @return \OCP\L10N\IFactory |
|
1428 | - */ |
|
1429 | - public function getL10NFactory() { |
|
1430 | - return $this->query('L10NFactory'); |
|
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * get an L10N instance |
|
1435 | - * |
|
1436 | - * @param string $app appid |
|
1437 | - * @param string $lang |
|
1438 | - * @return IL10N |
|
1439 | - */ |
|
1440 | - public function getL10N($app, $lang = null) { |
|
1441 | - return $this->getL10NFactory()->get($app, $lang); |
|
1442 | - } |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * @return \OCP\IURLGenerator |
|
1446 | - */ |
|
1447 | - public function getURLGenerator() { |
|
1448 | - return $this->query('URLGenerator'); |
|
1449 | - } |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * @return \OCP\IHelper |
|
1453 | - */ |
|
1454 | - public function getHelper() { |
|
1455 | - return $this->query('AppHelper'); |
|
1456 | - } |
|
1457 | - |
|
1458 | - /** |
|
1459 | - * @return AppFetcher |
|
1460 | - */ |
|
1461 | - public function getAppFetcher() { |
|
1462 | - return $this->query(AppFetcher::class); |
|
1463 | - } |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1467 | - * getMemCacheFactory() instead. |
|
1468 | - * |
|
1469 | - * @return \OCP\ICache |
|
1470 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1471 | - */ |
|
1472 | - public function getCache() { |
|
1473 | - return $this->query('UserCache'); |
|
1474 | - } |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * Returns an \OCP\CacheFactory instance |
|
1478 | - * |
|
1479 | - * @return \OCP\ICacheFactory |
|
1480 | - */ |
|
1481 | - public function getMemCacheFactory() { |
|
1482 | - return $this->query('MemCacheFactory'); |
|
1483 | - } |
|
1484 | - |
|
1485 | - /** |
|
1486 | - * Returns an \OC\RedisFactory instance |
|
1487 | - * |
|
1488 | - * @return \OC\RedisFactory |
|
1489 | - */ |
|
1490 | - public function getGetRedisFactory() { |
|
1491 | - return $this->query('RedisFactory'); |
|
1492 | - } |
|
1493 | - |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * Returns the current session |
|
1497 | - * |
|
1498 | - * @return \OCP\IDBConnection |
|
1499 | - */ |
|
1500 | - public function getDatabaseConnection() { |
|
1501 | - return $this->query('DatabaseConnection'); |
|
1502 | - } |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * Returns the activity manager |
|
1506 | - * |
|
1507 | - * @return \OCP\Activity\IManager |
|
1508 | - */ |
|
1509 | - public function getActivityManager() { |
|
1510 | - return $this->query('ActivityManager'); |
|
1511 | - } |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * Returns an job list for controlling background jobs |
|
1515 | - * |
|
1516 | - * @return \OCP\BackgroundJob\IJobList |
|
1517 | - */ |
|
1518 | - public function getJobList() { |
|
1519 | - return $this->query('JobList'); |
|
1520 | - } |
|
1521 | - |
|
1522 | - /** |
|
1523 | - * Returns a logger instance |
|
1524 | - * |
|
1525 | - * @return \OCP\ILogger |
|
1526 | - */ |
|
1527 | - public function getLogger() { |
|
1528 | - return $this->query('Logger'); |
|
1529 | - } |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * Returns a router for generating and matching urls |
|
1533 | - * |
|
1534 | - * @return \OCP\Route\IRouter |
|
1535 | - */ |
|
1536 | - public function getRouter() { |
|
1537 | - return $this->query('Router'); |
|
1538 | - } |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Returns a search instance |
|
1542 | - * |
|
1543 | - * @return \OCP\ISearch |
|
1544 | - */ |
|
1545 | - public function getSearch() { |
|
1546 | - return $this->query('Search'); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Returns a SecureRandom instance |
|
1551 | - * |
|
1552 | - * @return \OCP\Security\ISecureRandom |
|
1553 | - */ |
|
1554 | - public function getSecureRandom() { |
|
1555 | - return $this->query('SecureRandom'); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * Returns a Crypto instance |
|
1560 | - * |
|
1561 | - * @return \OCP\Security\ICrypto |
|
1562 | - */ |
|
1563 | - public function getCrypto() { |
|
1564 | - return $this->query('Crypto'); |
|
1565 | - } |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * Returns a Hasher instance |
|
1569 | - * |
|
1570 | - * @return \OCP\Security\IHasher |
|
1571 | - */ |
|
1572 | - public function getHasher() { |
|
1573 | - return $this->query('Hasher'); |
|
1574 | - } |
|
1575 | - |
|
1576 | - /** |
|
1577 | - * Returns a CredentialsManager instance |
|
1578 | - * |
|
1579 | - * @return \OCP\Security\ICredentialsManager |
|
1580 | - */ |
|
1581 | - public function getCredentialsManager() { |
|
1582 | - return $this->query('CredentialsManager'); |
|
1583 | - } |
|
1584 | - |
|
1585 | - /** |
|
1586 | - * Returns an instance of the HTTP helper class |
|
1587 | - * |
|
1588 | - * @deprecated Use getHTTPClientService() |
|
1589 | - * @return \OC\HTTPHelper |
|
1590 | - */ |
|
1591 | - public function getHTTPHelper() { |
|
1592 | - return $this->query('HTTPHelper'); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * Get the certificate manager for the user |
|
1597 | - * |
|
1598 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1599 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1600 | - */ |
|
1601 | - public function getCertificateManager($userId = '') { |
|
1602 | - if ($userId === '') { |
|
1603 | - $userSession = $this->getUserSession(); |
|
1604 | - $user = $userSession->getUser(); |
|
1605 | - if (is_null($user)) { |
|
1606 | - return null; |
|
1607 | - } |
|
1608 | - $userId = $user->getUID(); |
|
1609 | - } |
|
1610 | - return new CertificateManager( |
|
1611 | - $userId, |
|
1612 | - new View(), |
|
1613 | - $this->getConfig(), |
|
1614 | - $this->getLogger(), |
|
1615 | - $this->getSecureRandom() |
|
1616 | - ); |
|
1617 | - } |
|
1618 | - |
|
1619 | - /** |
|
1620 | - * Returns an instance of the HTTP client service |
|
1621 | - * |
|
1622 | - * @return \OCP\Http\Client\IClientService |
|
1623 | - */ |
|
1624 | - public function getHTTPClientService() { |
|
1625 | - return $this->query('HttpClientService'); |
|
1626 | - } |
|
1627 | - |
|
1628 | - /** |
|
1629 | - * Create a new event source |
|
1630 | - * |
|
1631 | - * @return \OCP\IEventSource |
|
1632 | - */ |
|
1633 | - public function createEventSource() { |
|
1634 | - return new \OC_EventSource(); |
|
1635 | - } |
|
1636 | - |
|
1637 | - /** |
|
1638 | - * Get the active event logger |
|
1639 | - * |
|
1640 | - * The returned logger only logs data when debug mode is enabled |
|
1641 | - * |
|
1642 | - * @return \OCP\Diagnostics\IEventLogger |
|
1643 | - */ |
|
1644 | - public function getEventLogger() { |
|
1645 | - return $this->query('EventLogger'); |
|
1646 | - } |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * Get the active query logger |
|
1650 | - * |
|
1651 | - * The returned logger only logs data when debug mode is enabled |
|
1652 | - * |
|
1653 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1654 | - */ |
|
1655 | - public function getQueryLogger() { |
|
1656 | - return $this->query('QueryLogger'); |
|
1657 | - } |
|
1658 | - |
|
1659 | - /** |
|
1660 | - * Get the manager for temporary files and folders |
|
1661 | - * |
|
1662 | - * @return \OCP\ITempManager |
|
1663 | - */ |
|
1664 | - public function getTempManager() { |
|
1665 | - return $this->query('TempManager'); |
|
1666 | - } |
|
1667 | - |
|
1668 | - /** |
|
1669 | - * Get the app manager |
|
1670 | - * |
|
1671 | - * @return \OCP\App\IAppManager |
|
1672 | - */ |
|
1673 | - public function getAppManager() { |
|
1674 | - return $this->query('AppManager'); |
|
1675 | - } |
|
1676 | - |
|
1677 | - /** |
|
1678 | - * Creates a new mailer |
|
1679 | - * |
|
1680 | - * @return \OCP\Mail\IMailer |
|
1681 | - */ |
|
1682 | - public function getMailer() { |
|
1683 | - return $this->query('Mailer'); |
|
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * Get the webroot |
|
1688 | - * |
|
1689 | - * @return string |
|
1690 | - */ |
|
1691 | - public function getWebRoot() { |
|
1692 | - return $this->webRoot; |
|
1693 | - } |
|
1694 | - |
|
1695 | - /** |
|
1696 | - * @return \OC\OCSClient |
|
1697 | - */ |
|
1698 | - public function getOcsClient() { |
|
1699 | - return $this->query('OcsClient'); |
|
1700 | - } |
|
1701 | - |
|
1702 | - /** |
|
1703 | - * @return \OCP\IDateTimeZone |
|
1704 | - */ |
|
1705 | - public function getDateTimeZone() { |
|
1706 | - return $this->query('DateTimeZone'); |
|
1707 | - } |
|
1708 | - |
|
1709 | - /** |
|
1710 | - * @return \OCP\IDateTimeFormatter |
|
1711 | - */ |
|
1712 | - public function getDateTimeFormatter() { |
|
1713 | - return $this->query('DateTimeFormatter'); |
|
1714 | - } |
|
1715 | - |
|
1716 | - /** |
|
1717 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1718 | - */ |
|
1719 | - public function getMountProviderCollection() { |
|
1720 | - return $this->query('MountConfigManager'); |
|
1721 | - } |
|
1722 | - |
|
1723 | - /** |
|
1724 | - * Get the IniWrapper |
|
1725 | - * |
|
1726 | - * @return IniGetWrapper |
|
1727 | - */ |
|
1728 | - public function getIniWrapper() { |
|
1729 | - return $this->query('IniWrapper'); |
|
1730 | - } |
|
1731 | - |
|
1732 | - /** |
|
1733 | - * @return \OCP\Command\IBus |
|
1734 | - */ |
|
1735 | - public function getCommandBus() { |
|
1736 | - return $this->query('AsyncCommandBus'); |
|
1737 | - } |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * Get the trusted domain helper |
|
1741 | - * |
|
1742 | - * @return TrustedDomainHelper |
|
1743 | - */ |
|
1744 | - public function getTrustedDomainHelper() { |
|
1745 | - return $this->query('TrustedDomainHelper'); |
|
1746 | - } |
|
1747 | - |
|
1748 | - /** |
|
1749 | - * Get the locking provider |
|
1750 | - * |
|
1751 | - * @return \OCP\Lock\ILockingProvider |
|
1752 | - * @since 8.1.0 |
|
1753 | - */ |
|
1754 | - public function getLockingProvider() { |
|
1755 | - return $this->query('LockingProvider'); |
|
1756 | - } |
|
1757 | - |
|
1758 | - /** |
|
1759 | - * @return \OCP\Files\Mount\IMountManager |
|
1760 | - **/ |
|
1761 | - function getMountManager() { |
|
1762 | - return $this->query('MountManager'); |
|
1763 | - } |
|
1764 | - |
|
1765 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1766 | - function getUserMountCache() { |
|
1767 | - return $this->query('UserMountCache'); |
|
1768 | - } |
|
1769 | - |
|
1770 | - /** |
|
1771 | - * Get the MimeTypeDetector |
|
1772 | - * |
|
1773 | - * @return \OCP\Files\IMimeTypeDetector |
|
1774 | - */ |
|
1775 | - public function getMimeTypeDetector() { |
|
1776 | - return $this->query('MimeTypeDetector'); |
|
1777 | - } |
|
1778 | - |
|
1779 | - /** |
|
1780 | - * Get the MimeTypeLoader |
|
1781 | - * |
|
1782 | - * @return \OCP\Files\IMimeTypeLoader |
|
1783 | - */ |
|
1784 | - public function getMimeTypeLoader() { |
|
1785 | - return $this->query('MimeTypeLoader'); |
|
1786 | - } |
|
1787 | - |
|
1788 | - /** |
|
1789 | - * Get the manager of all the capabilities |
|
1790 | - * |
|
1791 | - * @return \OC\CapabilitiesManager |
|
1792 | - */ |
|
1793 | - public function getCapabilitiesManager() { |
|
1794 | - return $this->query('CapabilitiesManager'); |
|
1795 | - } |
|
1796 | - |
|
1797 | - /** |
|
1798 | - * Get the EventDispatcher |
|
1799 | - * |
|
1800 | - * @return EventDispatcherInterface |
|
1801 | - * @since 8.2.0 |
|
1802 | - */ |
|
1803 | - public function getEventDispatcher() { |
|
1804 | - return $this->query('EventDispatcher'); |
|
1805 | - } |
|
1806 | - |
|
1807 | - /** |
|
1808 | - * Get the Notification Manager |
|
1809 | - * |
|
1810 | - * @return \OCP\Notification\IManager |
|
1811 | - * @since 8.2.0 |
|
1812 | - */ |
|
1813 | - public function getNotificationManager() { |
|
1814 | - return $this->query('NotificationManager'); |
|
1815 | - } |
|
1816 | - |
|
1817 | - /** |
|
1818 | - * @return \OCP\Comments\ICommentsManager |
|
1819 | - */ |
|
1820 | - public function getCommentsManager() { |
|
1821 | - return $this->query('CommentsManager'); |
|
1822 | - } |
|
1823 | - |
|
1824 | - /** |
|
1825 | - * @return \OCA\Theming\ThemingDefaults |
|
1826 | - */ |
|
1827 | - public function getThemingDefaults() { |
|
1828 | - return $this->query('ThemingDefaults'); |
|
1829 | - } |
|
1830 | - |
|
1831 | - /** |
|
1832 | - * @return \OC\IntegrityCheck\Checker |
|
1833 | - */ |
|
1834 | - public function getIntegrityCodeChecker() { |
|
1835 | - return $this->query('IntegrityCodeChecker'); |
|
1836 | - } |
|
1837 | - |
|
1838 | - /** |
|
1839 | - * @return \OC\Session\CryptoWrapper |
|
1840 | - */ |
|
1841 | - public function getSessionCryptoWrapper() { |
|
1842 | - return $this->query('CryptoWrapper'); |
|
1843 | - } |
|
1844 | - |
|
1845 | - /** |
|
1846 | - * @return CsrfTokenManager |
|
1847 | - */ |
|
1848 | - public function getCsrfTokenManager() { |
|
1849 | - return $this->query('CsrfTokenManager'); |
|
1850 | - } |
|
1851 | - |
|
1852 | - /** |
|
1853 | - * @return Throttler |
|
1854 | - */ |
|
1855 | - public function getBruteForceThrottler() { |
|
1856 | - return $this->query('Throttler'); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * @return IContentSecurityPolicyManager |
|
1861 | - */ |
|
1862 | - public function getContentSecurityPolicyManager() { |
|
1863 | - return $this->query('ContentSecurityPolicyManager'); |
|
1864 | - } |
|
1865 | - |
|
1866 | - /** |
|
1867 | - * @return ContentSecurityPolicyNonceManager |
|
1868 | - */ |
|
1869 | - public function getContentSecurityPolicyNonceManager() { |
|
1870 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1871 | - } |
|
1872 | - |
|
1873 | - /** |
|
1874 | - * Not a public API as of 8.2, wait for 9.0 |
|
1875 | - * |
|
1876 | - * @return \OCA\Files_External\Service\BackendService |
|
1877 | - */ |
|
1878 | - public function getStoragesBackendService() { |
|
1879 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1880 | - } |
|
1881 | - |
|
1882 | - /** |
|
1883 | - * Not a public API as of 8.2, wait for 9.0 |
|
1884 | - * |
|
1885 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1886 | - */ |
|
1887 | - public function getGlobalStoragesService() { |
|
1888 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1889 | - } |
|
1890 | - |
|
1891 | - /** |
|
1892 | - * Not a public API as of 8.2, wait for 9.0 |
|
1893 | - * |
|
1894 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1895 | - */ |
|
1896 | - public function getUserGlobalStoragesService() { |
|
1897 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1898 | - } |
|
1899 | - |
|
1900 | - /** |
|
1901 | - * Not a public API as of 8.2, wait for 9.0 |
|
1902 | - * |
|
1903 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1904 | - */ |
|
1905 | - public function getUserStoragesService() { |
|
1906 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1907 | - } |
|
1908 | - |
|
1909 | - /** |
|
1910 | - * @return \OCP\Share\IManager |
|
1911 | - */ |
|
1912 | - public function getShareManager() { |
|
1913 | - return $this->query('ShareManager'); |
|
1914 | - } |
|
1915 | - |
|
1916 | - /** |
|
1917 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1918 | - */ |
|
1919 | - public function getCollaboratorSearch() { |
|
1920 | - return $this->query('CollaboratorSearch'); |
|
1921 | - } |
|
1922 | - |
|
1923 | - /** |
|
1924 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1925 | - */ |
|
1926 | - public function getAutoCompleteManager(){ |
|
1927 | - return $this->query(IManager::class); |
|
1928 | - } |
|
1929 | - |
|
1930 | - /** |
|
1931 | - * Returns the LDAP Provider |
|
1932 | - * |
|
1933 | - * @return \OCP\LDAP\ILDAPProvider |
|
1934 | - */ |
|
1935 | - public function getLDAPProvider() { |
|
1936 | - return $this->query('LDAPProvider'); |
|
1937 | - } |
|
1938 | - |
|
1939 | - /** |
|
1940 | - * @return \OCP\Settings\IManager |
|
1941 | - */ |
|
1942 | - public function getSettingsManager() { |
|
1943 | - return $this->query('SettingsManager'); |
|
1944 | - } |
|
1945 | - |
|
1946 | - /** |
|
1947 | - * @return \OCP\Files\IAppData |
|
1948 | - */ |
|
1949 | - public function getAppDataDir($app) { |
|
1950 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1951 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1952 | - return $factory->get($app); |
|
1953 | - } |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * @return \OCP\Lockdown\ILockdownManager |
|
1957 | - */ |
|
1958 | - public function getLockdownManager() { |
|
1959 | - return $this->query('LockdownManager'); |
|
1960 | - } |
|
1961 | - |
|
1962 | - /** |
|
1963 | - * @return \OCP\Federation\ICloudIdManager |
|
1964 | - */ |
|
1965 | - public function getCloudIdManager() { |
|
1966 | - return $this->query(ICloudIdManager::class); |
|
1967 | - } |
|
1968 | - |
|
1969 | - /** |
|
1970 | - * @return \OCP\Remote\Api\IApiFactory |
|
1971 | - */ |
|
1972 | - public function getRemoteApiFactory() { |
|
1973 | - return $this->query(IApiFactory::class); |
|
1974 | - } |
|
1975 | - |
|
1976 | - /** |
|
1977 | - * @return \OCP\Remote\IInstanceFactory |
|
1978 | - */ |
|
1979 | - public function getRemoteInstanceFactory() { |
|
1980 | - return $this->query(IInstanceFactory::class); |
|
1981 | - } |
|
937 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
938 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
939 | + $classExists = true; |
|
940 | + } else { |
|
941 | + $classExists = false; |
|
942 | + } |
|
943 | + |
|
944 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
945 | + return new ThemingDefaults( |
|
946 | + $c->getConfig(), |
|
947 | + $c->getL10N('theming'), |
|
948 | + $c->getURLGenerator(), |
|
949 | + $c->getAppDataDir('theming'), |
|
950 | + $c->getMemCacheFactory(), |
|
951 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
952 | + $this->getAppManager() |
|
953 | + ); |
|
954 | + } |
|
955 | + return new \OC_Defaults(); |
|
956 | + }); |
|
957 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
958 | + /** @var Factory $cacheFactory */ |
|
959 | + $cacheFactory = $c->query(Factory::class); |
|
960 | + return new SCSSCacher( |
|
961 | + $c->getLogger(), |
|
962 | + $c->query(\OC\Files\AppData\Factory::class), |
|
963 | + $c->getURLGenerator(), |
|
964 | + $c->getConfig(), |
|
965 | + $c->getThemingDefaults(), |
|
966 | + \OC::$SERVERROOT, |
|
967 | + $cacheFactory->createDistributed('SCSS') |
|
968 | + ); |
|
969 | + }); |
|
970 | + $this->registerService(EventDispatcher::class, function () { |
|
971 | + return new EventDispatcher(); |
|
972 | + }); |
|
973 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
974 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
975 | + |
|
976 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
977 | + // FIXME: Instantiiated here due to cyclic dependency |
|
978 | + $request = new Request( |
|
979 | + [ |
|
980 | + 'get' => $_GET, |
|
981 | + 'post' => $_POST, |
|
982 | + 'files' => $_FILES, |
|
983 | + 'server' => $_SERVER, |
|
984 | + 'env' => $_ENV, |
|
985 | + 'cookies' => $_COOKIE, |
|
986 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
987 | + ? $_SERVER['REQUEST_METHOD'] |
|
988 | + : null, |
|
989 | + ], |
|
990 | + $c->getSecureRandom(), |
|
991 | + $c->getConfig() |
|
992 | + ); |
|
993 | + |
|
994 | + return new CryptoWrapper( |
|
995 | + $c->getConfig(), |
|
996 | + $c->getCrypto(), |
|
997 | + $c->getSecureRandom(), |
|
998 | + $request |
|
999 | + ); |
|
1000 | + }); |
|
1001 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1002 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1003 | + |
|
1004 | + return new CsrfTokenManager( |
|
1005 | + $tokenGenerator, |
|
1006 | + $c->query(SessionStorage::class) |
|
1007 | + ); |
|
1008 | + }); |
|
1009 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1010 | + return new SessionStorage($c->getSession()); |
|
1011 | + }); |
|
1012 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1013 | + return new ContentSecurityPolicyManager(); |
|
1014 | + }); |
|
1015 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1016 | + |
|
1017 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1018 | + return new ContentSecurityPolicyNonceManager( |
|
1019 | + $c->getCsrfTokenManager(), |
|
1020 | + $c->getRequest() |
|
1021 | + ); |
|
1022 | + }); |
|
1023 | + |
|
1024 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1025 | + $config = $c->getConfig(); |
|
1026 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1027 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1028 | + $factory = new $factoryClass($this); |
|
1029 | + |
|
1030 | + $manager = new \OC\Share20\Manager( |
|
1031 | + $c->getLogger(), |
|
1032 | + $c->getConfig(), |
|
1033 | + $c->getSecureRandom(), |
|
1034 | + $c->getHasher(), |
|
1035 | + $c->getMountManager(), |
|
1036 | + $c->getGroupManager(), |
|
1037 | + $c->getL10N('lib'), |
|
1038 | + $c->getL10NFactory(), |
|
1039 | + $factory, |
|
1040 | + $c->getUserManager(), |
|
1041 | + $c->getLazyRootFolder(), |
|
1042 | + $c->getEventDispatcher(), |
|
1043 | + $c->getMailer(), |
|
1044 | + $c->getURLGenerator(), |
|
1045 | + $c->getThemingDefaults() |
|
1046 | + ); |
|
1047 | + |
|
1048 | + return $manager; |
|
1049 | + }); |
|
1050 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1051 | + |
|
1052 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1053 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1054 | + |
|
1055 | + // register default plugins |
|
1056 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1057 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1058 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1059 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1060 | + |
|
1061 | + return $instance; |
|
1062 | + }); |
|
1063 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1064 | + |
|
1065 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1066 | + |
|
1067 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1068 | + $manager = new \OC\Settings\Manager( |
|
1069 | + $c->getLogger(), |
|
1070 | + $c->getDatabaseConnection(), |
|
1071 | + $c->getL10N('lib'), |
|
1072 | + $c->getConfig(), |
|
1073 | + $c->getEncryptionManager(), |
|
1074 | + $c->getUserManager(), |
|
1075 | + $c->getLockingProvider(), |
|
1076 | + $c->getRequest(), |
|
1077 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1078 | + $c->getURLGenerator(), |
|
1079 | + $c->query(AccountManager::class), |
|
1080 | + $c->getGroupManager(), |
|
1081 | + $c->getL10NFactory(), |
|
1082 | + $c->getThemingDefaults(), |
|
1083 | + $c->getAppManager() |
|
1084 | + ); |
|
1085 | + return $manager; |
|
1086 | + }); |
|
1087 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1088 | + return new \OC\Files\AppData\Factory( |
|
1089 | + $c->getRootFolder(), |
|
1090 | + $c->getSystemConfig() |
|
1091 | + ); |
|
1092 | + }); |
|
1093 | + |
|
1094 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1095 | + return new LockdownManager(function () use ($c) { |
|
1096 | + return $c->getSession(); |
|
1097 | + }); |
|
1098 | + }); |
|
1099 | + |
|
1100 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1101 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1102 | + }); |
|
1103 | + |
|
1104 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1105 | + return new CloudIdManager(); |
|
1106 | + }); |
|
1107 | + |
|
1108 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1109 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1110 | + |
|
1111 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1112 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1113 | + |
|
1114 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1115 | + return new Defaults( |
|
1116 | + $c->getThemingDefaults() |
|
1117 | + ); |
|
1118 | + }); |
|
1119 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1120 | + |
|
1121 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1122 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1123 | + }); |
|
1124 | + |
|
1125 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1126 | + return new ShareHelper( |
|
1127 | + $c->query(\OCP\Share\IManager::class) |
|
1128 | + ); |
|
1129 | + }); |
|
1130 | + |
|
1131 | + $this->registerService(Installer::class, function(Server $c) { |
|
1132 | + return new Installer( |
|
1133 | + $c->getAppFetcher(), |
|
1134 | + $c->getHTTPClientService(), |
|
1135 | + $c->getTempManager(), |
|
1136 | + $c->getLogger(), |
|
1137 | + $c->getConfig() |
|
1138 | + ); |
|
1139 | + }); |
|
1140 | + |
|
1141 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1142 | + return new ApiFactory($c->getHTTPClientService()); |
|
1143 | + }); |
|
1144 | + |
|
1145 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1146 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1147 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1148 | + }); |
|
1149 | + |
|
1150 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1151 | + return new ContactsStore( |
|
1152 | + $c->getContactsManager(), |
|
1153 | + $c->getConfig(), |
|
1154 | + $c->getUserManager(), |
|
1155 | + $c->getGroupManager() |
|
1156 | + ); |
|
1157 | + }); |
|
1158 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1159 | + |
|
1160 | + $this->connectDispatcher(); |
|
1161 | + } |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * @return \OCP\Calendar\IManager |
|
1165 | + */ |
|
1166 | + public function getCalendarManager() { |
|
1167 | + return $this->query('CalendarManager'); |
|
1168 | + } |
|
1169 | + |
|
1170 | + private function connectDispatcher() { |
|
1171 | + $dispatcher = $this->getEventDispatcher(); |
|
1172 | + |
|
1173 | + // Delete avatar on user deletion |
|
1174 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1175 | + $logger = $this->getLogger(); |
|
1176 | + $manager = $this->getAvatarManager(); |
|
1177 | + /** @var IUser $user */ |
|
1178 | + $user = $e->getSubject(); |
|
1179 | + |
|
1180 | + try { |
|
1181 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1182 | + $avatar->remove(); |
|
1183 | + } catch (NotFoundException $e) { |
|
1184 | + // no avatar to remove |
|
1185 | + } catch (\Exception $e) { |
|
1186 | + // Ignore exceptions |
|
1187 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1188 | + } |
|
1189 | + }); |
|
1190 | + |
|
1191 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1192 | + $manager = $this->getAvatarManager(); |
|
1193 | + /** @var IUser $user */ |
|
1194 | + $user = $e->getSubject(); |
|
1195 | + $feature = $e->getArgument('feature'); |
|
1196 | + $oldValue = $e->getArgument('oldValue'); |
|
1197 | + $value = $e->getArgument('value'); |
|
1198 | + |
|
1199 | + try { |
|
1200 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1201 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1202 | + } catch (NotFoundException $e) { |
|
1203 | + // no avatar to remove |
|
1204 | + } |
|
1205 | + }); |
|
1206 | + } |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * @return \OCP\Contacts\IManager |
|
1210 | + */ |
|
1211 | + public function getContactsManager() { |
|
1212 | + return $this->query('ContactsManager'); |
|
1213 | + } |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * @return \OC\Encryption\Manager |
|
1217 | + */ |
|
1218 | + public function getEncryptionManager() { |
|
1219 | + return $this->query('EncryptionManager'); |
|
1220 | + } |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * @return \OC\Encryption\File |
|
1224 | + */ |
|
1225 | + public function getEncryptionFilesHelper() { |
|
1226 | + return $this->query('EncryptionFileHelper'); |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * @return \OCP\Encryption\Keys\IStorage |
|
1231 | + */ |
|
1232 | + public function getEncryptionKeyStorage() { |
|
1233 | + return $this->query('EncryptionKeyStorage'); |
|
1234 | + } |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * The current request object holding all information about the request |
|
1238 | + * currently being processed is returned from this method. |
|
1239 | + * In case the current execution was not initiated by a web request null is returned |
|
1240 | + * |
|
1241 | + * @return \OCP\IRequest |
|
1242 | + */ |
|
1243 | + public function getRequest() { |
|
1244 | + return $this->query('Request'); |
|
1245 | + } |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * Returns the preview manager which can create preview images for a given file |
|
1249 | + * |
|
1250 | + * @return \OCP\IPreview |
|
1251 | + */ |
|
1252 | + public function getPreviewManager() { |
|
1253 | + return $this->query('PreviewManager'); |
|
1254 | + } |
|
1255 | + |
|
1256 | + /** |
|
1257 | + * Returns the tag manager which can get and set tags for different object types |
|
1258 | + * |
|
1259 | + * @see \OCP\ITagManager::load() |
|
1260 | + * @return \OCP\ITagManager |
|
1261 | + */ |
|
1262 | + public function getTagManager() { |
|
1263 | + return $this->query('TagManager'); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Returns the system-tag manager |
|
1268 | + * |
|
1269 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1270 | + * |
|
1271 | + * @since 9.0.0 |
|
1272 | + */ |
|
1273 | + public function getSystemTagManager() { |
|
1274 | + return $this->query('SystemTagManager'); |
|
1275 | + } |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * Returns the system-tag object mapper |
|
1279 | + * |
|
1280 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1281 | + * |
|
1282 | + * @since 9.0.0 |
|
1283 | + */ |
|
1284 | + public function getSystemTagObjectMapper() { |
|
1285 | + return $this->query('SystemTagObjectMapper'); |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * Returns the avatar manager, used for avatar functionality |
|
1290 | + * |
|
1291 | + * @return \OCP\IAvatarManager |
|
1292 | + */ |
|
1293 | + public function getAvatarManager() { |
|
1294 | + return $this->query('AvatarManager'); |
|
1295 | + } |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * Returns the root folder of ownCloud's data directory |
|
1299 | + * |
|
1300 | + * @return \OCP\Files\IRootFolder |
|
1301 | + */ |
|
1302 | + public function getRootFolder() { |
|
1303 | + return $this->query('LazyRootFolder'); |
|
1304 | + } |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * Returns the root folder of ownCloud's data directory |
|
1308 | + * This is the lazy variant so this gets only initialized once it |
|
1309 | + * is actually used. |
|
1310 | + * |
|
1311 | + * @return \OCP\Files\IRootFolder |
|
1312 | + */ |
|
1313 | + public function getLazyRootFolder() { |
|
1314 | + return $this->query('LazyRootFolder'); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * Returns a view to ownCloud's files folder |
|
1319 | + * |
|
1320 | + * @param string $userId user ID |
|
1321 | + * @return \OCP\Files\Folder|null |
|
1322 | + */ |
|
1323 | + public function getUserFolder($userId = null) { |
|
1324 | + if ($userId === null) { |
|
1325 | + $user = $this->getUserSession()->getUser(); |
|
1326 | + if (!$user) { |
|
1327 | + return null; |
|
1328 | + } |
|
1329 | + $userId = $user->getUID(); |
|
1330 | + } |
|
1331 | + $root = $this->getRootFolder(); |
|
1332 | + return $root->getUserFolder($userId); |
|
1333 | + } |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Returns an app-specific view in ownClouds data directory |
|
1337 | + * |
|
1338 | + * @return \OCP\Files\Folder |
|
1339 | + * @deprecated since 9.2.0 use IAppData |
|
1340 | + */ |
|
1341 | + public function getAppFolder() { |
|
1342 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1343 | + $root = $this->getRootFolder(); |
|
1344 | + if (!$root->nodeExists($dir)) { |
|
1345 | + $folder = $root->newFolder($dir); |
|
1346 | + } else { |
|
1347 | + $folder = $root->get($dir); |
|
1348 | + } |
|
1349 | + return $folder; |
|
1350 | + } |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * @return \OC\User\Manager |
|
1354 | + */ |
|
1355 | + public function getUserManager() { |
|
1356 | + return $this->query('UserManager'); |
|
1357 | + } |
|
1358 | + |
|
1359 | + /** |
|
1360 | + * @return \OC\Group\Manager |
|
1361 | + */ |
|
1362 | + public function getGroupManager() { |
|
1363 | + return $this->query('GroupManager'); |
|
1364 | + } |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * @return \OC\User\Session |
|
1368 | + */ |
|
1369 | + public function getUserSession() { |
|
1370 | + return $this->query('UserSession'); |
|
1371 | + } |
|
1372 | + |
|
1373 | + /** |
|
1374 | + * @return \OCP\ISession |
|
1375 | + */ |
|
1376 | + public function getSession() { |
|
1377 | + return $this->query('UserSession')->getSession(); |
|
1378 | + } |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * @param \OCP\ISession $session |
|
1382 | + */ |
|
1383 | + public function setSession(\OCP\ISession $session) { |
|
1384 | + $this->query(SessionStorage::class)->setSession($session); |
|
1385 | + $this->query('UserSession')->setSession($session); |
|
1386 | + $this->query(Store::class)->setSession($session); |
|
1387 | + } |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1391 | + */ |
|
1392 | + public function getTwoFactorAuthManager() { |
|
1393 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1394 | + } |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * @return \OC\NavigationManager |
|
1398 | + */ |
|
1399 | + public function getNavigationManager() { |
|
1400 | + return $this->query('NavigationManager'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * @return \OCP\IConfig |
|
1405 | + */ |
|
1406 | + public function getConfig() { |
|
1407 | + return $this->query('AllConfig'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * @return \OC\SystemConfig |
|
1412 | + */ |
|
1413 | + public function getSystemConfig() { |
|
1414 | + return $this->query('SystemConfig'); |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Returns the app config manager |
|
1419 | + * |
|
1420 | + * @return \OCP\IAppConfig |
|
1421 | + */ |
|
1422 | + public function getAppConfig() { |
|
1423 | + return $this->query('AppConfig'); |
|
1424 | + } |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * @return \OCP\L10N\IFactory |
|
1428 | + */ |
|
1429 | + public function getL10NFactory() { |
|
1430 | + return $this->query('L10NFactory'); |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * get an L10N instance |
|
1435 | + * |
|
1436 | + * @param string $app appid |
|
1437 | + * @param string $lang |
|
1438 | + * @return IL10N |
|
1439 | + */ |
|
1440 | + public function getL10N($app, $lang = null) { |
|
1441 | + return $this->getL10NFactory()->get($app, $lang); |
|
1442 | + } |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * @return \OCP\IURLGenerator |
|
1446 | + */ |
|
1447 | + public function getURLGenerator() { |
|
1448 | + return $this->query('URLGenerator'); |
|
1449 | + } |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * @return \OCP\IHelper |
|
1453 | + */ |
|
1454 | + public function getHelper() { |
|
1455 | + return $this->query('AppHelper'); |
|
1456 | + } |
|
1457 | + |
|
1458 | + /** |
|
1459 | + * @return AppFetcher |
|
1460 | + */ |
|
1461 | + public function getAppFetcher() { |
|
1462 | + return $this->query(AppFetcher::class); |
|
1463 | + } |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1467 | + * getMemCacheFactory() instead. |
|
1468 | + * |
|
1469 | + * @return \OCP\ICache |
|
1470 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1471 | + */ |
|
1472 | + public function getCache() { |
|
1473 | + return $this->query('UserCache'); |
|
1474 | + } |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * Returns an \OCP\CacheFactory instance |
|
1478 | + * |
|
1479 | + * @return \OCP\ICacheFactory |
|
1480 | + */ |
|
1481 | + public function getMemCacheFactory() { |
|
1482 | + return $this->query('MemCacheFactory'); |
|
1483 | + } |
|
1484 | + |
|
1485 | + /** |
|
1486 | + * Returns an \OC\RedisFactory instance |
|
1487 | + * |
|
1488 | + * @return \OC\RedisFactory |
|
1489 | + */ |
|
1490 | + public function getGetRedisFactory() { |
|
1491 | + return $this->query('RedisFactory'); |
|
1492 | + } |
|
1493 | + |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * Returns the current session |
|
1497 | + * |
|
1498 | + * @return \OCP\IDBConnection |
|
1499 | + */ |
|
1500 | + public function getDatabaseConnection() { |
|
1501 | + return $this->query('DatabaseConnection'); |
|
1502 | + } |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * Returns the activity manager |
|
1506 | + * |
|
1507 | + * @return \OCP\Activity\IManager |
|
1508 | + */ |
|
1509 | + public function getActivityManager() { |
|
1510 | + return $this->query('ActivityManager'); |
|
1511 | + } |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * Returns an job list for controlling background jobs |
|
1515 | + * |
|
1516 | + * @return \OCP\BackgroundJob\IJobList |
|
1517 | + */ |
|
1518 | + public function getJobList() { |
|
1519 | + return $this->query('JobList'); |
|
1520 | + } |
|
1521 | + |
|
1522 | + /** |
|
1523 | + * Returns a logger instance |
|
1524 | + * |
|
1525 | + * @return \OCP\ILogger |
|
1526 | + */ |
|
1527 | + public function getLogger() { |
|
1528 | + return $this->query('Logger'); |
|
1529 | + } |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * Returns a router for generating and matching urls |
|
1533 | + * |
|
1534 | + * @return \OCP\Route\IRouter |
|
1535 | + */ |
|
1536 | + public function getRouter() { |
|
1537 | + return $this->query('Router'); |
|
1538 | + } |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Returns a search instance |
|
1542 | + * |
|
1543 | + * @return \OCP\ISearch |
|
1544 | + */ |
|
1545 | + public function getSearch() { |
|
1546 | + return $this->query('Search'); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Returns a SecureRandom instance |
|
1551 | + * |
|
1552 | + * @return \OCP\Security\ISecureRandom |
|
1553 | + */ |
|
1554 | + public function getSecureRandom() { |
|
1555 | + return $this->query('SecureRandom'); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * Returns a Crypto instance |
|
1560 | + * |
|
1561 | + * @return \OCP\Security\ICrypto |
|
1562 | + */ |
|
1563 | + public function getCrypto() { |
|
1564 | + return $this->query('Crypto'); |
|
1565 | + } |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * Returns a Hasher instance |
|
1569 | + * |
|
1570 | + * @return \OCP\Security\IHasher |
|
1571 | + */ |
|
1572 | + public function getHasher() { |
|
1573 | + return $this->query('Hasher'); |
|
1574 | + } |
|
1575 | + |
|
1576 | + /** |
|
1577 | + * Returns a CredentialsManager instance |
|
1578 | + * |
|
1579 | + * @return \OCP\Security\ICredentialsManager |
|
1580 | + */ |
|
1581 | + public function getCredentialsManager() { |
|
1582 | + return $this->query('CredentialsManager'); |
|
1583 | + } |
|
1584 | + |
|
1585 | + /** |
|
1586 | + * Returns an instance of the HTTP helper class |
|
1587 | + * |
|
1588 | + * @deprecated Use getHTTPClientService() |
|
1589 | + * @return \OC\HTTPHelper |
|
1590 | + */ |
|
1591 | + public function getHTTPHelper() { |
|
1592 | + return $this->query('HTTPHelper'); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * Get the certificate manager for the user |
|
1597 | + * |
|
1598 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1599 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1600 | + */ |
|
1601 | + public function getCertificateManager($userId = '') { |
|
1602 | + if ($userId === '') { |
|
1603 | + $userSession = $this->getUserSession(); |
|
1604 | + $user = $userSession->getUser(); |
|
1605 | + if (is_null($user)) { |
|
1606 | + return null; |
|
1607 | + } |
|
1608 | + $userId = $user->getUID(); |
|
1609 | + } |
|
1610 | + return new CertificateManager( |
|
1611 | + $userId, |
|
1612 | + new View(), |
|
1613 | + $this->getConfig(), |
|
1614 | + $this->getLogger(), |
|
1615 | + $this->getSecureRandom() |
|
1616 | + ); |
|
1617 | + } |
|
1618 | + |
|
1619 | + /** |
|
1620 | + * Returns an instance of the HTTP client service |
|
1621 | + * |
|
1622 | + * @return \OCP\Http\Client\IClientService |
|
1623 | + */ |
|
1624 | + public function getHTTPClientService() { |
|
1625 | + return $this->query('HttpClientService'); |
|
1626 | + } |
|
1627 | + |
|
1628 | + /** |
|
1629 | + * Create a new event source |
|
1630 | + * |
|
1631 | + * @return \OCP\IEventSource |
|
1632 | + */ |
|
1633 | + public function createEventSource() { |
|
1634 | + return new \OC_EventSource(); |
|
1635 | + } |
|
1636 | + |
|
1637 | + /** |
|
1638 | + * Get the active event logger |
|
1639 | + * |
|
1640 | + * The returned logger only logs data when debug mode is enabled |
|
1641 | + * |
|
1642 | + * @return \OCP\Diagnostics\IEventLogger |
|
1643 | + */ |
|
1644 | + public function getEventLogger() { |
|
1645 | + return $this->query('EventLogger'); |
|
1646 | + } |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * Get the active query logger |
|
1650 | + * |
|
1651 | + * The returned logger only logs data when debug mode is enabled |
|
1652 | + * |
|
1653 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1654 | + */ |
|
1655 | + public function getQueryLogger() { |
|
1656 | + return $this->query('QueryLogger'); |
|
1657 | + } |
|
1658 | + |
|
1659 | + /** |
|
1660 | + * Get the manager for temporary files and folders |
|
1661 | + * |
|
1662 | + * @return \OCP\ITempManager |
|
1663 | + */ |
|
1664 | + public function getTempManager() { |
|
1665 | + return $this->query('TempManager'); |
|
1666 | + } |
|
1667 | + |
|
1668 | + /** |
|
1669 | + * Get the app manager |
|
1670 | + * |
|
1671 | + * @return \OCP\App\IAppManager |
|
1672 | + */ |
|
1673 | + public function getAppManager() { |
|
1674 | + return $this->query('AppManager'); |
|
1675 | + } |
|
1676 | + |
|
1677 | + /** |
|
1678 | + * Creates a new mailer |
|
1679 | + * |
|
1680 | + * @return \OCP\Mail\IMailer |
|
1681 | + */ |
|
1682 | + public function getMailer() { |
|
1683 | + return $this->query('Mailer'); |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * Get the webroot |
|
1688 | + * |
|
1689 | + * @return string |
|
1690 | + */ |
|
1691 | + public function getWebRoot() { |
|
1692 | + return $this->webRoot; |
|
1693 | + } |
|
1694 | + |
|
1695 | + /** |
|
1696 | + * @return \OC\OCSClient |
|
1697 | + */ |
|
1698 | + public function getOcsClient() { |
|
1699 | + return $this->query('OcsClient'); |
|
1700 | + } |
|
1701 | + |
|
1702 | + /** |
|
1703 | + * @return \OCP\IDateTimeZone |
|
1704 | + */ |
|
1705 | + public function getDateTimeZone() { |
|
1706 | + return $this->query('DateTimeZone'); |
|
1707 | + } |
|
1708 | + |
|
1709 | + /** |
|
1710 | + * @return \OCP\IDateTimeFormatter |
|
1711 | + */ |
|
1712 | + public function getDateTimeFormatter() { |
|
1713 | + return $this->query('DateTimeFormatter'); |
|
1714 | + } |
|
1715 | + |
|
1716 | + /** |
|
1717 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1718 | + */ |
|
1719 | + public function getMountProviderCollection() { |
|
1720 | + return $this->query('MountConfigManager'); |
|
1721 | + } |
|
1722 | + |
|
1723 | + /** |
|
1724 | + * Get the IniWrapper |
|
1725 | + * |
|
1726 | + * @return IniGetWrapper |
|
1727 | + */ |
|
1728 | + public function getIniWrapper() { |
|
1729 | + return $this->query('IniWrapper'); |
|
1730 | + } |
|
1731 | + |
|
1732 | + /** |
|
1733 | + * @return \OCP\Command\IBus |
|
1734 | + */ |
|
1735 | + public function getCommandBus() { |
|
1736 | + return $this->query('AsyncCommandBus'); |
|
1737 | + } |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * Get the trusted domain helper |
|
1741 | + * |
|
1742 | + * @return TrustedDomainHelper |
|
1743 | + */ |
|
1744 | + public function getTrustedDomainHelper() { |
|
1745 | + return $this->query('TrustedDomainHelper'); |
|
1746 | + } |
|
1747 | + |
|
1748 | + /** |
|
1749 | + * Get the locking provider |
|
1750 | + * |
|
1751 | + * @return \OCP\Lock\ILockingProvider |
|
1752 | + * @since 8.1.0 |
|
1753 | + */ |
|
1754 | + public function getLockingProvider() { |
|
1755 | + return $this->query('LockingProvider'); |
|
1756 | + } |
|
1757 | + |
|
1758 | + /** |
|
1759 | + * @return \OCP\Files\Mount\IMountManager |
|
1760 | + **/ |
|
1761 | + function getMountManager() { |
|
1762 | + return $this->query('MountManager'); |
|
1763 | + } |
|
1764 | + |
|
1765 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1766 | + function getUserMountCache() { |
|
1767 | + return $this->query('UserMountCache'); |
|
1768 | + } |
|
1769 | + |
|
1770 | + /** |
|
1771 | + * Get the MimeTypeDetector |
|
1772 | + * |
|
1773 | + * @return \OCP\Files\IMimeTypeDetector |
|
1774 | + */ |
|
1775 | + public function getMimeTypeDetector() { |
|
1776 | + return $this->query('MimeTypeDetector'); |
|
1777 | + } |
|
1778 | + |
|
1779 | + /** |
|
1780 | + * Get the MimeTypeLoader |
|
1781 | + * |
|
1782 | + * @return \OCP\Files\IMimeTypeLoader |
|
1783 | + */ |
|
1784 | + public function getMimeTypeLoader() { |
|
1785 | + return $this->query('MimeTypeLoader'); |
|
1786 | + } |
|
1787 | + |
|
1788 | + /** |
|
1789 | + * Get the manager of all the capabilities |
|
1790 | + * |
|
1791 | + * @return \OC\CapabilitiesManager |
|
1792 | + */ |
|
1793 | + public function getCapabilitiesManager() { |
|
1794 | + return $this->query('CapabilitiesManager'); |
|
1795 | + } |
|
1796 | + |
|
1797 | + /** |
|
1798 | + * Get the EventDispatcher |
|
1799 | + * |
|
1800 | + * @return EventDispatcherInterface |
|
1801 | + * @since 8.2.0 |
|
1802 | + */ |
|
1803 | + public function getEventDispatcher() { |
|
1804 | + return $this->query('EventDispatcher'); |
|
1805 | + } |
|
1806 | + |
|
1807 | + /** |
|
1808 | + * Get the Notification Manager |
|
1809 | + * |
|
1810 | + * @return \OCP\Notification\IManager |
|
1811 | + * @since 8.2.0 |
|
1812 | + */ |
|
1813 | + public function getNotificationManager() { |
|
1814 | + return $this->query('NotificationManager'); |
|
1815 | + } |
|
1816 | + |
|
1817 | + /** |
|
1818 | + * @return \OCP\Comments\ICommentsManager |
|
1819 | + */ |
|
1820 | + public function getCommentsManager() { |
|
1821 | + return $this->query('CommentsManager'); |
|
1822 | + } |
|
1823 | + |
|
1824 | + /** |
|
1825 | + * @return \OCA\Theming\ThemingDefaults |
|
1826 | + */ |
|
1827 | + public function getThemingDefaults() { |
|
1828 | + return $this->query('ThemingDefaults'); |
|
1829 | + } |
|
1830 | + |
|
1831 | + /** |
|
1832 | + * @return \OC\IntegrityCheck\Checker |
|
1833 | + */ |
|
1834 | + public function getIntegrityCodeChecker() { |
|
1835 | + return $this->query('IntegrityCodeChecker'); |
|
1836 | + } |
|
1837 | + |
|
1838 | + /** |
|
1839 | + * @return \OC\Session\CryptoWrapper |
|
1840 | + */ |
|
1841 | + public function getSessionCryptoWrapper() { |
|
1842 | + return $this->query('CryptoWrapper'); |
|
1843 | + } |
|
1844 | + |
|
1845 | + /** |
|
1846 | + * @return CsrfTokenManager |
|
1847 | + */ |
|
1848 | + public function getCsrfTokenManager() { |
|
1849 | + return $this->query('CsrfTokenManager'); |
|
1850 | + } |
|
1851 | + |
|
1852 | + /** |
|
1853 | + * @return Throttler |
|
1854 | + */ |
|
1855 | + public function getBruteForceThrottler() { |
|
1856 | + return $this->query('Throttler'); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * @return IContentSecurityPolicyManager |
|
1861 | + */ |
|
1862 | + public function getContentSecurityPolicyManager() { |
|
1863 | + return $this->query('ContentSecurityPolicyManager'); |
|
1864 | + } |
|
1865 | + |
|
1866 | + /** |
|
1867 | + * @return ContentSecurityPolicyNonceManager |
|
1868 | + */ |
|
1869 | + public function getContentSecurityPolicyNonceManager() { |
|
1870 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1871 | + } |
|
1872 | + |
|
1873 | + /** |
|
1874 | + * Not a public API as of 8.2, wait for 9.0 |
|
1875 | + * |
|
1876 | + * @return \OCA\Files_External\Service\BackendService |
|
1877 | + */ |
|
1878 | + public function getStoragesBackendService() { |
|
1879 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1880 | + } |
|
1881 | + |
|
1882 | + /** |
|
1883 | + * Not a public API as of 8.2, wait for 9.0 |
|
1884 | + * |
|
1885 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1886 | + */ |
|
1887 | + public function getGlobalStoragesService() { |
|
1888 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1889 | + } |
|
1890 | + |
|
1891 | + /** |
|
1892 | + * Not a public API as of 8.2, wait for 9.0 |
|
1893 | + * |
|
1894 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1895 | + */ |
|
1896 | + public function getUserGlobalStoragesService() { |
|
1897 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1898 | + } |
|
1899 | + |
|
1900 | + /** |
|
1901 | + * Not a public API as of 8.2, wait for 9.0 |
|
1902 | + * |
|
1903 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1904 | + */ |
|
1905 | + public function getUserStoragesService() { |
|
1906 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1907 | + } |
|
1908 | + |
|
1909 | + /** |
|
1910 | + * @return \OCP\Share\IManager |
|
1911 | + */ |
|
1912 | + public function getShareManager() { |
|
1913 | + return $this->query('ShareManager'); |
|
1914 | + } |
|
1915 | + |
|
1916 | + /** |
|
1917 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1918 | + */ |
|
1919 | + public function getCollaboratorSearch() { |
|
1920 | + return $this->query('CollaboratorSearch'); |
|
1921 | + } |
|
1922 | + |
|
1923 | + /** |
|
1924 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1925 | + */ |
|
1926 | + public function getAutoCompleteManager(){ |
|
1927 | + return $this->query(IManager::class); |
|
1928 | + } |
|
1929 | + |
|
1930 | + /** |
|
1931 | + * Returns the LDAP Provider |
|
1932 | + * |
|
1933 | + * @return \OCP\LDAP\ILDAPProvider |
|
1934 | + */ |
|
1935 | + public function getLDAPProvider() { |
|
1936 | + return $this->query('LDAPProvider'); |
|
1937 | + } |
|
1938 | + |
|
1939 | + /** |
|
1940 | + * @return \OCP\Settings\IManager |
|
1941 | + */ |
|
1942 | + public function getSettingsManager() { |
|
1943 | + return $this->query('SettingsManager'); |
|
1944 | + } |
|
1945 | + |
|
1946 | + /** |
|
1947 | + * @return \OCP\Files\IAppData |
|
1948 | + */ |
|
1949 | + public function getAppDataDir($app) { |
|
1950 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1951 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1952 | + return $factory->get($app); |
|
1953 | + } |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * @return \OCP\Lockdown\ILockdownManager |
|
1957 | + */ |
|
1958 | + public function getLockdownManager() { |
|
1959 | + return $this->query('LockdownManager'); |
|
1960 | + } |
|
1961 | + |
|
1962 | + /** |
|
1963 | + * @return \OCP\Federation\ICloudIdManager |
|
1964 | + */ |
|
1965 | + public function getCloudIdManager() { |
|
1966 | + return $this->query(ICloudIdManager::class); |
|
1967 | + } |
|
1968 | + |
|
1969 | + /** |
|
1970 | + * @return \OCP\Remote\Api\IApiFactory |
|
1971 | + */ |
|
1972 | + public function getRemoteApiFactory() { |
|
1973 | + return $this->query(IApiFactory::class); |
|
1974 | + } |
|
1975 | + |
|
1976 | + /** |
|
1977 | + * @return \OCP\Remote\IInstanceFactory |
|
1978 | + */ |
|
1979 | + public function getRemoteInstanceFactory() { |
|
1980 | + return $this->query(IInstanceFactory::class); |
|
1981 | + } |
|
1982 | 1982 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | parent::__construct(); |
161 | 161 | $this->webRoot = $webRoot; |
162 | 162 | |
163 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
163 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
164 | 164 | return $c; |
165 | 165 | }); |
166 | 166 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
174 | 174 | |
175 | 175 | |
176 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
176 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
177 | 177 | return new PreviewManager( |
178 | 178 | $c->getConfig(), |
179 | 179 | $c->getRootFolder(), |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | }); |
185 | 185 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
186 | 186 | |
187 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
187 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
188 | 188 | return new \OC\Preview\Watcher( |
189 | 189 | $c->getAppDataDir('preview') |
190 | 190 | ); |
191 | 191 | }); |
192 | 192 | |
193 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
193 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
194 | 194 | $view = new View(); |
195 | 195 | $util = new Encryption\Util( |
196 | 196 | $view, |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | ); |
209 | 209 | }); |
210 | 210 | |
211 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
211 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
212 | 212 | $util = new Encryption\Util( |
213 | 213 | new View(), |
214 | 214 | $c->getUserManager(), |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | ); |
223 | 223 | }); |
224 | 224 | |
225 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
225 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
226 | 226 | $view = new View(); |
227 | 227 | $util = new Encryption\Util( |
228 | 228 | $view, |
@@ -233,30 +233,30 @@ discard block |
||
233 | 233 | |
234 | 234 | return new Encryption\Keys\Storage($view, $util); |
235 | 235 | }); |
236 | - $this->registerService('TagMapper', function (Server $c) { |
|
236 | + $this->registerService('TagMapper', function(Server $c) { |
|
237 | 237 | return new TagMapper($c->getDatabaseConnection()); |
238 | 238 | }); |
239 | 239 | |
240 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
240 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
241 | 241 | $tagMapper = $c->query('TagMapper'); |
242 | 242 | return new TagManager($tagMapper, $c->getUserSession()); |
243 | 243 | }); |
244 | 244 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
245 | 245 | |
246 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
246 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
247 | 247 | $config = $c->getConfig(); |
248 | 248 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
249 | 249 | return new $factoryClass($this); |
250 | 250 | }); |
251 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
251 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
252 | 252 | return $c->query('SystemTagManagerFactory')->getManager(); |
253 | 253 | }); |
254 | 254 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
255 | 255 | |
256 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
256 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
257 | 257 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
258 | 258 | }); |
259 | - $this->registerService('RootFolder', function (Server $c) { |
|
259 | + $this->registerService('RootFolder', function(Server $c) { |
|
260 | 260 | $manager = \OC\Files\Filesystem::getMountManager(null); |
261 | 261 | $view = new View(); |
262 | 262 | $root = new Root( |
@@ -277,38 +277,38 @@ discard block |
||
277 | 277 | }); |
278 | 278 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
279 | 279 | |
280 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
281 | - return new LazyRoot(function () use ($c) { |
|
280 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
281 | + return new LazyRoot(function() use ($c) { |
|
282 | 282 | return $c->query('RootFolder'); |
283 | 283 | }); |
284 | 284 | }); |
285 | 285 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
286 | 286 | |
287 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
287 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
288 | 288 | $config = $c->getConfig(); |
289 | 289 | return new \OC\User\Manager($config); |
290 | 290 | }); |
291 | 291 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
292 | 292 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
293 | 293 | |
294 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
294 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
295 | 295 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
296 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
296 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
297 | 297 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
298 | 298 | }); |
299 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
299 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
300 | 300 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
301 | 301 | }); |
302 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
302 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
303 | 303 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
304 | 304 | }); |
305 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
305 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
306 | 306 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
307 | 307 | }); |
308 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
308 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | 309 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
310 | 310 | }); |
311 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
311 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
312 | 312 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
313 | 313 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
314 | 314 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | }); |
318 | 318 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
319 | 319 | |
320 | - $this->registerService(Store::class, function (Server $c) { |
|
320 | + $this->registerService(Store::class, function(Server $c) { |
|
321 | 321 | $session = $c->getSession(); |
322 | 322 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
323 | 323 | $tokenProvider = $c->query(IProvider::class); |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | return new Store($session, $logger, $tokenProvider); |
329 | 329 | }); |
330 | 330 | $this->registerAlias(IStore::class, Store::class); |
331 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
331 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
332 | 332 | $dbConnection = $c->getDatabaseConnection(); |
333 | 333 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
334 | 334 | }); |
335 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
335 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function(Server $c) { |
|
336 | 336 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
337 | 337 | $crypto = $c->getCrypto(); |
338 | 338 | $config = $c->getConfig(); |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | }); |
343 | 343 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
344 | 344 | |
345 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
345 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
346 | 346 | $manager = $c->getUserManager(); |
347 | 347 | $session = new \OC\Session\Memory(''); |
348 | 348 | $timeFactory = new TimeFactory(); |
@@ -366,45 +366,45 @@ discard block |
||
366 | 366 | $c->getLockdownManager(), |
367 | 367 | $c->getLogger() |
368 | 368 | ); |
369 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
369 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
370 | 370 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
371 | 371 | }); |
372 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
372 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
373 | 373 | /** @var $user \OC\User\User */ |
374 | 374 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
375 | 375 | }); |
376 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
376 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
377 | 377 | /** @var $user \OC\User\User */ |
378 | 378 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
379 | 379 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
380 | 380 | }); |
381 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
381 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
382 | 382 | /** @var $user \OC\User\User */ |
383 | 383 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
384 | 384 | }); |
385 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
385 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
386 | 386 | /** @var $user \OC\User\User */ |
387 | 387 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
388 | 388 | }); |
389 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
389 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
390 | 390 | /** @var $user \OC\User\User */ |
391 | 391 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
392 | 392 | }); |
393 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
393 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
394 | 394 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
395 | 395 | }); |
396 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
396 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
397 | 397 | /** @var $user \OC\User\User */ |
398 | 398 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
399 | 399 | }); |
400 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
400 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
401 | 401 | /** @var $user \OC\User\User */ |
402 | 402 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
403 | 403 | }); |
404 | - $userSession->listen('\OC\User', 'logout', function () { |
|
404 | + $userSession->listen('\OC\User', 'logout', function() { |
|
405 | 405 | \OC_Hook::emit('OC_User', 'logout', array()); |
406 | 406 | }); |
407 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
407 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
408 | 408 | /** @var $user \OC\User\User */ |
409 | 409 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
410 | 410 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | }); |
414 | 414 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
415 | 415 | |
416 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
416 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
417 | 417 | return new \OC\Authentication\TwoFactorAuth\Manager( |
418 | 418 | $c->getAppManager(), |
419 | 419 | $c->getSession(), |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
430 | 430 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
431 | 431 | |
432 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
432 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
433 | 433 | return new \OC\AllConfig( |
434 | 434 | $c->getSystemConfig() |
435 | 435 | ); |
@@ -437,17 +437,17 @@ discard block |
||
437 | 437 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
438 | 438 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
439 | 439 | |
440 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
440 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
441 | 441 | return new \OC\SystemConfig($config); |
442 | 442 | }); |
443 | 443 | |
444 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
444 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
445 | 445 | return new \OC\AppConfig($c->getDatabaseConnection()); |
446 | 446 | }); |
447 | 447 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
448 | 448 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
449 | 449 | |
450 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
450 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
451 | 451 | return new \OC\L10N\Factory( |
452 | 452 | $c->getConfig(), |
453 | 453 | $c->getRequest(), |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | }); |
458 | 458 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
459 | 459 | |
460 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
460 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
461 | 461 | $config = $c->getConfig(); |
462 | 462 | $cacheFactory = $c->getMemCacheFactory(); |
463 | 463 | $request = $c->getRequest(); |
@@ -469,18 +469,18 @@ discard block |
||
469 | 469 | }); |
470 | 470 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
471 | 471 | |
472 | - $this->registerService('AppHelper', function ($c) { |
|
472 | + $this->registerService('AppHelper', function($c) { |
|
473 | 473 | return new \OC\AppHelper(); |
474 | 474 | }); |
475 | 475 | $this->registerAlias('AppFetcher', AppFetcher::class); |
476 | 476 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
477 | 477 | |
478 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
478 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
479 | 479 | return new Cache\File(); |
480 | 480 | }); |
481 | 481 | $this->registerAlias('UserCache', \OCP\ICache::class); |
482 | 482 | |
483 | - $this->registerService(Factory::class, function (Server $c) { |
|
483 | + $this->registerService(Factory::class, function(Server $c) { |
|
484 | 484 | |
485 | 485 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
486 | 486 | ArrayCache::class, |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $version = implode(',', $v); |
498 | 498 | $instanceId = \OC_Util::getInstanceId(); |
499 | 499 | $path = \OC::$SERVERROOT; |
500 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
500 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
501 | 501 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
502 | 502 | $config->getSystemValue('memcache.local', null), |
503 | 503 | $config->getSystemValue('memcache.distributed', null), |
@@ -510,12 +510,12 @@ discard block |
||
510 | 510 | $this->registerAlias('MemCacheFactory', Factory::class); |
511 | 511 | $this->registerAlias(ICacheFactory::class, Factory::class); |
512 | 512 | |
513 | - $this->registerService('RedisFactory', function (Server $c) { |
|
513 | + $this->registerService('RedisFactory', function(Server $c) { |
|
514 | 514 | $systemConfig = $c->getSystemConfig(); |
515 | 515 | return new RedisFactory($systemConfig); |
516 | 516 | }); |
517 | 517 | |
518 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
518 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
519 | 519 | return new \OC\Activity\Manager( |
520 | 520 | $c->getRequest(), |
521 | 521 | $c->getUserSession(), |
@@ -525,14 +525,14 @@ discard block |
||
525 | 525 | }); |
526 | 526 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
527 | 527 | |
528 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
528 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
529 | 529 | return new \OC\Activity\EventMerger( |
530 | 530 | $c->getL10N('lib') |
531 | 531 | ); |
532 | 532 | }); |
533 | 533 | $this->registerAlias(IValidator::class, Validator::class); |
534 | 534 | |
535 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
535 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
536 | 536 | return new AvatarManager( |
537 | 537 | $c->query(\OC\User\Manager::class), |
538 | 538 | $c->getAppDataDir('avatar'), |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | |
546 | 546 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
547 | 547 | |
548 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
548 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
549 | 549 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
550 | 550 | $logger = Log::getLogClass($logType); |
551 | 551 | call_user_func(array($logger, 'init')); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | }); |
557 | 557 | $this->registerAlias('Logger', \OCP\ILogger::class); |
558 | 558 | |
559 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
559 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
560 | 560 | $config = $c->getConfig(); |
561 | 561 | return new \OC\BackgroundJob\JobList( |
562 | 562 | $c->getDatabaseConnection(), |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | }); |
567 | 567 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
568 | 568 | |
569 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
569 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
570 | 570 | $cacheFactory = $c->getMemCacheFactory(); |
571 | 571 | $logger = $c->getLogger(); |
572 | 572 | if ($cacheFactory->isAvailableLowLatency()) { |
@@ -578,12 +578,12 @@ discard block |
||
578 | 578 | }); |
579 | 579 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
580 | 580 | |
581 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
581 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
582 | 582 | return new Search(); |
583 | 583 | }); |
584 | 584 | $this->registerAlias('Search', \OCP\ISearch::class); |
585 | 585 | |
586 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
586 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
587 | 587 | return new \OC\Security\RateLimiting\Limiter( |
588 | 588 | $this->getUserSession(), |
589 | 589 | $this->getRequest(), |
@@ -591,34 +591,34 @@ discard block |
||
591 | 591 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
592 | 592 | ); |
593 | 593 | }); |
594 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
594 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
595 | 595 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
596 | 596 | $this->getMemCacheFactory(), |
597 | 597 | new \OC\AppFramework\Utility\TimeFactory() |
598 | 598 | ); |
599 | 599 | }); |
600 | 600 | |
601 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
601 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
602 | 602 | return new SecureRandom(); |
603 | 603 | }); |
604 | 604 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
605 | 605 | |
606 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
606 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
607 | 607 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
608 | 608 | }); |
609 | 609 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
610 | 610 | |
611 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
611 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
612 | 612 | return new Hasher($c->getConfig()); |
613 | 613 | }); |
614 | 614 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
615 | 615 | |
616 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
616 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
617 | 617 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
618 | 618 | }); |
619 | 619 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
620 | 620 | |
621 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
621 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
622 | 622 | $systemConfig = $c->getSystemConfig(); |
623 | 623 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
624 | 624 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | }); |
633 | 633 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
634 | 634 | |
635 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
635 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
636 | 636 | $config = $c->getConfig(); |
637 | 637 | return new HTTPHelper( |
638 | 638 | $config, |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | ); |
641 | 641 | }); |
642 | 642 | |
643 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
643 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
644 | 644 | $user = \OC_User::getUser(); |
645 | 645 | $uid = $user ? $user : null; |
646 | 646 | return new ClientService( |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | ); |
656 | 656 | }); |
657 | 657 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
658 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
658 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
659 | 659 | $eventLogger = new EventLogger(); |
660 | 660 | if ($c->getSystemConfig()->getValue('debug', false)) { |
661 | 661 | // In debug mode, module is being activated by default |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | }); |
666 | 666 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
667 | 667 | |
668 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
668 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
669 | 669 | $queryLogger = new QueryLogger(); |
670 | 670 | if ($c->getSystemConfig()->getValue('debug', false)) { |
671 | 671 | // In debug mode, module is being activated by default |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | }); |
676 | 676 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
677 | 677 | |
678 | - $this->registerService(TempManager::class, function (Server $c) { |
|
678 | + $this->registerService(TempManager::class, function(Server $c) { |
|
679 | 679 | return new TempManager( |
680 | 680 | $c->getLogger(), |
681 | 681 | $c->getConfig() |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | $this->registerAlias('TempManager', TempManager::class); |
685 | 685 | $this->registerAlias(ITempManager::class, TempManager::class); |
686 | 686 | |
687 | - $this->registerService(AppManager::class, function (Server $c) { |
|
687 | + $this->registerService(AppManager::class, function(Server $c) { |
|
688 | 688 | return new \OC\App\AppManager( |
689 | 689 | $c->getUserSession(), |
690 | 690 | $this->getAppConfig(), |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | $this->registerAlias('AppManager', AppManager::class); |
697 | 697 | $this->registerAlias(IAppManager::class, AppManager::class); |
698 | 698 | |
699 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
699 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
700 | 700 | return new DateTimeZone( |
701 | 701 | $c->getConfig(), |
702 | 702 | $c->getSession() |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | }); |
705 | 705 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
706 | 706 | |
707 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
707 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
708 | 708 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
709 | 709 | |
710 | 710 | return new DateTimeFormatter( |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | }); |
715 | 715 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
716 | 716 | |
717 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
717 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
718 | 718 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
719 | 719 | $listener = new UserMountCacheListener($mountCache); |
720 | 720 | $listener->listen($c->getUserManager()); |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | }); |
723 | 723 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
724 | 724 | |
725 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
725 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
726 | 726 | $loader = \OC\Files\Filesystem::getLoader(); |
727 | 727 | $mountCache = $c->query('UserMountCache'); |
728 | 728 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -738,10 +738,10 @@ discard block |
||
738 | 738 | }); |
739 | 739 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
740 | 740 | |
741 | - $this->registerService('IniWrapper', function ($c) { |
|
741 | + $this->registerService('IniWrapper', function($c) { |
|
742 | 742 | return new IniGetWrapper(); |
743 | 743 | }); |
744 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
744 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
745 | 745 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
746 | 746 | if ($busClass) { |
747 | 747 | list($app, $class) = explode('::', $busClass, 2); |
@@ -756,10 +756,10 @@ discard block |
||
756 | 756 | return new CronBus($jobList); |
757 | 757 | } |
758 | 758 | }); |
759 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
759 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
760 | 760 | return new TrustedDomainHelper($this->getConfig()); |
761 | 761 | }); |
762 | - $this->registerService('Throttler', function (Server $c) { |
|
762 | + $this->registerService('Throttler', function(Server $c) { |
|
763 | 763 | return new Throttler( |
764 | 764 | $c->getDatabaseConnection(), |
765 | 765 | new TimeFactory(), |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | $c->getConfig() |
768 | 768 | ); |
769 | 769 | }); |
770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
770 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
771 | 771 | // IConfig and IAppManager requires a working database. This code |
772 | 772 | // might however be called when ownCloud is not yet setup. |
773 | 773 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | $c->getTempManager() |
789 | 789 | ); |
790 | 790 | }); |
791 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
791 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
792 | 792 | if (isset($this['urlParams'])) { |
793 | 793 | $urlParams = $this['urlParams']; |
794 | 794 | } else { |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | }); |
825 | 825 | $this->registerAlias('Request', \OCP\IRequest::class); |
826 | 826 | |
827 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
827 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
828 | 828 | return new Mailer( |
829 | 829 | $c->getConfig(), |
830 | 830 | $c->getLogger(), |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | }); |
836 | 836 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
837 | 837 | |
838 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
838 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
839 | 839 | $config = $c->getConfig(); |
840 | 840 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
841 | 841 | if (is_null($factoryClass)) { |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | $factory = new $factoryClass($this); |
846 | 846 | return $factory->getLDAPProvider(); |
847 | 847 | }); |
848 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
848 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
849 | 849 | $ini = $c->getIniWrapper(); |
850 | 850 | $config = $c->getConfig(); |
851 | 851 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -862,49 +862,49 @@ discard block |
||
862 | 862 | }); |
863 | 863 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
864 | 864 | |
865 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
865 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
866 | 866 | return new \OC\Files\Mount\Manager(); |
867 | 867 | }); |
868 | 868 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
869 | 869 | |
870 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
870 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
871 | 871 | return new \OC\Files\Type\Detection( |
872 | 872 | $c->getURLGenerator(), |
873 | 873 | \OC::$configDir, |
874 | - \OC::$SERVERROOT . '/resources/config/' |
|
874 | + \OC::$SERVERROOT.'/resources/config/' |
|
875 | 875 | ); |
876 | 876 | }); |
877 | 877 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
878 | 878 | |
879 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
879 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
880 | 880 | return new \OC\Files\Type\Loader( |
881 | 881 | $c->getDatabaseConnection() |
882 | 882 | ); |
883 | 883 | }); |
884 | 884 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
885 | - $this->registerService(BundleFetcher::class, function () { |
|
885 | + $this->registerService(BundleFetcher::class, function() { |
|
886 | 886 | return new BundleFetcher($this->getL10N('lib')); |
887 | 887 | }); |
888 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
888 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
889 | 889 | return new Manager( |
890 | 890 | $c->query(IValidator::class) |
891 | 891 | ); |
892 | 892 | }); |
893 | 893 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
894 | 894 | |
895 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
895 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
896 | 896 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
897 | - $manager->registerCapability(function () use ($c) { |
|
897 | + $manager->registerCapability(function() use ($c) { |
|
898 | 898 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
899 | 899 | }); |
900 | - $manager->registerCapability(function () use ($c) { |
|
900 | + $manager->registerCapability(function() use ($c) { |
|
901 | 901 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
902 | 902 | }); |
903 | 903 | return $manager; |
904 | 904 | }); |
905 | 905 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
906 | 906 | |
907 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
907 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
908 | 908 | $config = $c->getConfig(); |
909 | 909 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
910 | 910 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
915 | 915 | $manager = $c->getUserManager(); |
916 | 916 | $user = $manager->get($id); |
917 | - if(is_null($user)) { |
|
917 | + if (is_null($user)) { |
|
918 | 918 | $l = $c->getL10N('core'); |
919 | 919 | $displayName = $l->t('Unknown user'); |
920 | 920 | } else { |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | }); |
928 | 928 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
929 | 929 | |
930 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
930 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
931 | 931 | /* |
932 | 932 | * Dark magic for autoloader. |
933 | 933 | * If we do a class_exists it will try to load the class which will |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | } |
955 | 955 | return new \OC_Defaults(); |
956 | 956 | }); |
957 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
957 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
958 | 958 | /** @var Factory $cacheFactory */ |
959 | 959 | $cacheFactory = $c->query(Factory::class); |
960 | 960 | return new SCSSCacher( |
@@ -967,13 +967,13 @@ discard block |
||
967 | 967 | $cacheFactory->createDistributed('SCSS') |
968 | 968 | ); |
969 | 969 | }); |
970 | - $this->registerService(EventDispatcher::class, function () { |
|
970 | + $this->registerService(EventDispatcher::class, function() { |
|
971 | 971 | return new EventDispatcher(); |
972 | 972 | }); |
973 | 973 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
974 | 974 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
975 | 975 | |
976 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
976 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
977 | 977 | // FIXME: Instantiiated here due to cyclic dependency |
978 | 978 | $request = new Request( |
979 | 979 | [ |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $request |
999 | 999 | ); |
1000 | 1000 | }); |
1001 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1001 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1002 | 1002 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1003 | 1003 | |
1004 | 1004 | return new CsrfTokenManager( |
@@ -1006,22 +1006,22 @@ discard block |
||
1006 | 1006 | $c->query(SessionStorage::class) |
1007 | 1007 | ); |
1008 | 1008 | }); |
1009 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1009 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1010 | 1010 | return new SessionStorage($c->getSession()); |
1011 | 1011 | }); |
1012 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1012 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1013 | 1013 | return new ContentSecurityPolicyManager(); |
1014 | 1014 | }); |
1015 | 1015 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1016 | 1016 | |
1017 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1017 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1018 | 1018 | return new ContentSecurityPolicyNonceManager( |
1019 | 1019 | $c->getCsrfTokenManager(), |
1020 | 1020 | $c->getRequest() |
1021 | 1021 | ); |
1022 | 1022 | }); |
1023 | 1023 | |
1024 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1024 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1025 | 1025 | $config = $c->getConfig(); |
1026 | 1026 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1027 | 1027 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | |
1065 | 1065 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
1066 | 1066 | |
1067 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1067 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1068 | 1068 | $manager = new \OC\Settings\Manager( |
1069 | 1069 | $c->getLogger(), |
1070 | 1070 | $c->getDatabaseConnection(), |
@@ -1084,24 +1084,24 @@ discard block |
||
1084 | 1084 | ); |
1085 | 1085 | return $manager; |
1086 | 1086 | }); |
1087 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1087 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1088 | 1088 | return new \OC\Files\AppData\Factory( |
1089 | 1089 | $c->getRootFolder(), |
1090 | 1090 | $c->getSystemConfig() |
1091 | 1091 | ); |
1092 | 1092 | }); |
1093 | 1093 | |
1094 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1095 | - return new LockdownManager(function () use ($c) { |
|
1094 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1095 | + return new LockdownManager(function() use ($c) { |
|
1096 | 1096 | return $c->getSession(); |
1097 | 1097 | }); |
1098 | 1098 | }); |
1099 | 1099 | |
1100 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1100 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1101 | 1101 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1102 | 1102 | }); |
1103 | 1103 | |
1104 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1104 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1105 | 1105 | return new CloudIdManager(); |
1106 | 1106 | }); |
1107 | 1107 | |
@@ -1111,18 +1111,18 @@ discard block |
||
1111 | 1111 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1112 | 1112 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1113 | 1113 | |
1114 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1114 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1115 | 1115 | return new Defaults( |
1116 | 1116 | $c->getThemingDefaults() |
1117 | 1117 | ); |
1118 | 1118 | }); |
1119 | 1119 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1120 | 1120 | |
1121 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1121 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1122 | 1122 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1123 | 1123 | }); |
1124 | 1124 | |
1125 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1125 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1126 | 1126 | return new ShareHelper( |
1127 | 1127 | $c->query(\OCP\Share\IManager::class) |
1128 | 1128 | ); |
@@ -1184,11 +1184,11 @@ discard block |
||
1184 | 1184 | // no avatar to remove |
1185 | 1185 | } catch (\Exception $e) { |
1186 | 1186 | // Ignore exceptions |
1187 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1187 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1188 | 1188 | } |
1189 | 1189 | }); |
1190 | 1190 | |
1191 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1191 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1192 | 1192 | $manager = $this->getAvatarManager(); |
1193 | 1193 | /** @var IUser $user */ |
1194 | 1194 | $user = $e->getSubject(); |
@@ -1339,7 +1339,7 @@ discard block |
||
1339 | 1339 | * @deprecated since 9.2.0 use IAppData |
1340 | 1340 | */ |
1341 | 1341 | public function getAppFolder() { |
1342 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1342 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1343 | 1343 | $root = $this->getRootFolder(); |
1344 | 1344 | if (!$root->nodeExists($dir)) { |
1345 | 1345 | $folder = $root->newFolder($dir); |
@@ -1923,7 +1923,7 @@ discard block |
||
1923 | 1923 | /** |
1924 | 1924 | * @return \OCP\Collaboration\AutoComplete\IManager |
1925 | 1925 | */ |
1926 | - public function getAutoCompleteManager(){ |
|
1926 | + public function getAutoCompleteManager() { |
|
1927 | 1927 | return $this->query(IManager::class); |
1928 | 1928 | } |
1929 | 1929 |
@@ -45,284 +45,284 @@ |
||
45 | 45 | |
46 | 46 | class TemplateLayout extends \OC_Template { |
47 | 47 | |
48 | - private static $versionHash = ''; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var \OCP\IConfig |
|
52 | - */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $renderAs |
|
57 | - * @param string $appId application id |
|
58 | - */ |
|
59 | - public function __construct( $renderAs, $appId = '' ) { |
|
60 | - |
|
61 | - // yes - should be injected .... |
|
62 | - $this->config = \OC::$server->getConfig(); |
|
63 | - |
|
64 | - |
|
65 | - // Decide which page we show |
|
66 | - if($renderAs == 'user') { |
|
67 | - parent::__construct( 'core', 'layout.user' ); |
|
68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | - $this->assign('bodyid', 'body-settings'); |
|
70 | - }else{ |
|
71 | - $this->assign('bodyid', 'body-user'); |
|
72 | - } |
|
73 | - |
|
74 | - // Code integrity notification |
|
75 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | - } |
|
79 | - |
|
80 | - // Add navigation entry |
|
81 | - $this->assign( 'application', ''); |
|
82 | - $this->assign( 'appid', $appId ); |
|
83 | - $navigation = \OC_App::getNavigation(); |
|
84 | - $this->assign( 'navigation', $navigation); |
|
85 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | - foreach($navigation as $entry) { |
|
88 | - if ($entry['active']) { |
|
89 | - $this->assign( 'application', $entry['name'] ); |
|
90 | - break; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - foreach($settingsNavigation as $entry) { |
|
95 | - if ($entry['active']) { |
|
96 | - $this->assign( 'application', $entry['name'] ); |
|
97 | - break; |
|
98 | - } |
|
99 | - } |
|
100 | - $userDisplayName = \OC_User::getDisplayName(); |
|
101 | - $this->assign('user_displayname', $userDisplayName); |
|
102 | - $this->assign('user_uid', \OC_User::getUser()); |
|
103 | - |
|
104 | - if (\OC_User::getUser() === false) { |
|
105 | - $this->assign('userAvatarSet', false); |
|
106 | - } else { |
|
107 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | - } |
|
110 | - |
|
111 | - // check if app menu icons should be inverted |
|
112 | - try { |
|
113 | - /** @var \OCA\Theming\Util $util */ |
|
114 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | - $this->assign('themingInvertMenu', false); |
|
118 | - } |
|
119 | - |
|
120 | - } else if ($renderAs == 'error') { |
|
121 | - parent::__construct('core', 'layout.guest', '', false); |
|
122 | - \OC_Util::addStyle('guest'); |
|
123 | - $this->assign('bodyid', 'body-login'); |
|
124 | - } else if ($renderAs == 'guest') { |
|
125 | - parent::__construct('core', 'layout.guest'); |
|
126 | - \OC_Util::addStyle('guest'); |
|
127 | - $this->assign('bodyid', 'body-login'); |
|
128 | - } else { |
|
129 | - parent::__construct('core', 'layout.base'); |
|
130 | - |
|
131 | - } |
|
132 | - // Send the language to our layouts |
|
133 | - $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
134 | - |
|
135 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
136 | - if (empty(self::$versionHash)) { |
|
137 | - $v = \OC_App::getAppVersions(); |
|
138 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
139 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
140 | - } |
|
141 | - } else { |
|
142 | - self::$versionHash = md5('not installed'); |
|
143 | - } |
|
144 | - |
|
145 | - // Add the js files |
|
146 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
147 | - $this->assign('jsfiles', array()); |
|
148 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
149 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
150 | - $jsConfigHelper = new JSConfigHelper( |
|
151 | - \OC::$server->getL10N('lib'), |
|
152 | - \OC::$server->query(Defaults::class), |
|
153 | - \OC::$server->getAppManager(), |
|
154 | - \OC::$server->getSession(), |
|
155 | - \OC::$server->getUserSession()->getUser(), |
|
156 | - $this->config, |
|
157 | - \OC::$server->getGroupManager(), |
|
158 | - \OC::$server->getIniWrapper(), |
|
159 | - \OC::$server->getURLGenerator() |
|
160 | - ); |
|
161 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
162 | - } else { |
|
163 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
164 | - } |
|
165 | - } |
|
166 | - foreach($jsFiles as $info) { |
|
167 | - $web = $info[1]; |
|
168 | - $file = $info[2]; |
|
169 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
170 | - } |
|
171 | - |
|
172 | - try { |
|
173 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
174 | - } catch (\Exception $e) { |
|
175 | - $pathInfo = ''; |
|
176 | - } |
|
177 | - |
|
178 | - // Do not initialise scss appdata until we have a fully installed instance |
|
179 | - // Do not load scss for update, errors, installation or login page |
|
180 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
181 | - && !\OCP\Util::needUpgrade() |
|
182 | - && $pathInfo !== '' |
|
183 | - && !preg_match('/^\/login/', $pathInfo)) { |
|
184 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
185 | - } else { |
|
186 | - // If we ignore the scss compiler, |
|
187 | - // we need to load the guest css fallback |
|
188 | - \OC_Util::addStyle('guest'); |
|
189 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
190 | - } |
|
191 | - |
|
192 | - $this->assign('cssfiles', array()); |
|
193 | - $this->assign('printcssfiles', []); |
|
194 | - $this->assign('versionHash', self::$versionHash); |
|
195 | - foreach($cssFiles as $info) { |
|
196 | - $web = $info[1]; |
|
197 | - $file = $info[2]; |
|
198 | - |
|
199 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
200 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
201 | - } else { |
|
202 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param string $path |
|
209 | - * @param string $file |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
213 | - if ($this->config->getSystemValue('debug', false)) { |
|
214 | - // allows chrome workspace mapping in debug mode |
|
215 | - return ""; |
|
216 | - } |
|
217 | - $themingSuffix = ''; |
|
218 | - $v = []; |
|
219 | - |
|
220 | - if ($this->config->getSystemValue('installed', false)) { |
|
221 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
222 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
223 | - } |
|
224 | - $v = \OC_App::getAppVersions(); |
|
225 | - } |
|
226 | - |
|
227 | - // Try the webroot path for a match |
|
228 | - if ($path !== false && $path !== '') { |
|
229 | - $appName = $this->getAppNamefromPath($path); |
|
230 | - if(array_key_exists($appName, $v)) { |
|
231 | - $appVersion = $v[$appName]; |
|
232 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
233 | - } |
|
234 | - } |
|
235 | - // fallback to the file path instead |
|
236 | - if ($file !== false && $file !== '') { |
|
237 | - $appName = $this->getAppNamefromPath($file); |
|
238 | - if(array_key_exists($appName, $v)) { |
|
239 | - $appVersion = $v[$appName]; |
|
240 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array $styles |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
252 | - // Read the selected theme from the config file |
|
253 | - $theme = \OC_Util::getTheme(); |
|
254 | - |
|
255 | - if($compileScss) { |
|
256 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
257 | - } else { |
|
258 | - $SCSSCacher = null; |
|
259 | - } |
|
260 | - |
|
261 | - $locator = new \OC\Template\CSSResourceLocator( |
|
262 | - \OC::$server->getLogger(), |
|
263 | - $theme, |
|
264 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
265 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
266 | - $SCSSCacher |
|
267 | - ); |
|
268 | - $locator->find($styles); |
|
269 | - return $locator->getResources(); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $path |
|
274 | - * @return string|boolean |
|
275 | - */ |
|
276 | - public function getAppNamefromPath($path) { |
|
277 | - if ($path !== '' && is_string($path)) { |
|
278 | - $pathParts = explode('/', $path); |
|
279 | - if ($pathParts[0] === 'css') { |
|
280 | - // This is a scss request |
|
281 | - return $pathParts[1]; |
|
282 | - } |
|
283 | - return end($pathParts); |
|
284 | - } |
|
285 | - return false; |
|
286 | - |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @param array $scripts |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - static public function findJavascriptFiles($scripts) { |
|
294 | - // Read the selected theme from the config file |
|
295 | - $theme = \OC_Util::getTheme(); |
|
296 | - |
|
297 | - $locator = new \OC\Template\JSResourceLocator( |
|
298 | - \OC::$server->getLogger(), |
|
299 | - $theme, |
|
300 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
301 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
302 | - new JSCombiner( |
|
303 | - \OC::$server->getAppDataDir('js'), |
|
304 | - \OC::$server->getURLGenerator(), |
|
305 | - \OC::$server->getMemCacheFactory()->createDistributed('JS'), |
|
306 | - \OC::$server->getSystemConfig(), |
|
307 | - \OC::$server->getLogger() |
|
308 | - ) |
|
309 | - ); |
|
310 | - $locator->find($scripts); |
|
311 | - return $locator->getResources(); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
316 | - * @param string $filePath Absolute path |
|
317 | - * @return string Relative path |
|
318 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
319 | - */ |
|
320 | - public static function convertToRelativePath($filePath) { |
|
321 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
322 | - if(count($relativePath) !== 2) { |
|
323 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
324 | - } |
|
325 | - |
|
326 | - return $relativePath[1]; |
|
327 | - } |
|
48 | + private static $versionHash = ''; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var \OCP\IConfig |
|
52 | + */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $renderAs |
|
57 | + * @param string $appId application id |
|
58 | + */ |
|
59 | + public function __construct( $renderAs, $appId = '' ) { |
|
60 | + |
|
61 | + // yes - should be injected .... |
|
62 | + $this->config = \OC::$server->getConfig(); |
|
63 | + |
|
64 | + |
|
65 | + // Decide which page we show |
|
66 | + if($renderAs == 'user') { |
|
67 | + parent::__construct( 'core', 'layout.user' ); |
|
68 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | + $this->assign('bodyid', 'body-settings'); |
|
70 | + }else{ |
|
71 | + $this->assign('bodyid', 'body-user'); |
|
72 | + } |
|
73 | + |
|
74 | + // Code integrity notification |
|
75 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | + } |
|
79 | + |
|
80 | + // Add navigation entry |
|
81 | + $this->assign( 'application', ''); |
|
82 | + $this->assign( 'appid', $appId ); |
|
83 | + $navigation = \OC_App::getNavigation(); |
|
84 | + $this->assign( 'navigation', $navigation); |
|
85 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
86 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | + foreach($navigation as $entry) { |
|
88 | + if ($entry['active']) { |
|
89 | + $this->assign( 'application', $entry['name'] ); |
|
90 | + break; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + foreach($settingsNavigation as $entry) { |
|
95 | + if ($entry['active']) { |
|
96 | + $this->assign( 'application', $entry['name'] ); |
|
97 | + break; |
|
98 | + } |
|
99 | + } |
|
100 | + $userDisplayName = \OC_User::getDisplayName(); |
|
101 | + $this->assign('user_displayname', $userDisplayName); |
|
102 | + $this->assign('user_uid', \OC_User::getUser()); |
|
103 | + |
|
104 | + if (\OC_User::getUser() === false) { |
|
105 | + $this->assign('userAvatarSet', false); |
|
106 | + } else { |
|
107 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | + } |
|
110 | + |
|
111 | + // check if app menu icons should be inverted |
|
112 | + try { |
|
113 | + /** @var \OCA\Theming\Util $util */ |
|
114 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | + $this->assign('themingInvertMenu', false); |
|
118 | + } |
|
119 | + |
|
120 | + } else if ($renderAs == 'error') { |
|
121 | + parent::__construct('core', 'layout.guest', '', false); |
|
122 | + \OC_Util::addStyle('guest'); |
|
123 | + $this->assign('bodyid', 'body-login'); |
|
124 | + } else if ($renderAs == 'guest') { |
|
125 | + parent::__construct('core', 'layout.guest'); |
|
126 | + \OC_Util::addStyle('guest'); |
|
127 | + $this->assign('bodyid', 'body-login'); |
|
128 | + } else { |
|
129 | + parent::__construct('core', 'layout.base'); |
|
130 | + |
|
131 | + } |
|
132 | + // Send the language to our layouts |
|
133 | + $this->assign('language', \OC::$server->getL10NFactory()->findLanguage()); |
|
134 | + |
|
135 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
136 | + if (empty(self::$versionHash)) { |
|
137 | + $v = \OC_App::getAppVersions(); |
|
138 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
139 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
140 | + } |
|
141 | + } else { |
|
142 | + self::$versionHash = md5('not installed'); |
|
143 | + } |
|
144 | + |
|
145 | + // Add the js files |
|
146 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
147 | + $this->assign('jsfiles', array()); |
|
148 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
149 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
150 | + $jsConfigHelper = new JSConfigHelper( |
|
151 | + \OC::$server->getL10N('lib'), |
|
152 | + \OC::$server->query(Defaults::class), |
|
153 | + \OC::$server->getAppManager(), |
|
154 | + \OC::$server->getSession(), |
|
155 | + \OC::$server->getUserSession()->getUser(), |
|
156 | + $this->config, |
|
157 | + \OC::$server->getGroupManager(), |
|
158 | + \OC::$server->getIniWrapper(), |
|
159 | + \OC::$server->getURLGenerator() |
|
160 | + ); |
|
161 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
162 | + } else { |
|
163 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
164 | + } |
|
165 | + } |
|
166 | + foreach($jsFiles as $info) { |
|
167 | + $web = $info[1]; |
|
168 | + $file = $info[2]; |
|
169 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
170 | + } |
|
171 | + |
|
172 | + try { |
|
173 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
174 | + } catch (\Exception $e) { |
|
175 | + $pathInfo = ''; |
|
176 | + } |
|
177 | + |
|
178 | + // Do not initialise scss appdata until we have a fully installed instance |
|
179 | + // Do not load scss for update, errors, installation or login page |
|
180 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
181 | + && !\OCP\Util::needUpgrade() |
|
182 | + && $pathInfo !== '' |
|
183 | + && !preg_match('/^\/login/', $pathInfo)) { |
|
184 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
185 | + } else { |
|
186 | + // If we ignore the scss compiler, |
|
187 | + // we need to load the guest css fallback |
|
188 | + \OC_Util::addStyle('guest'); |
|
189 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
190 | + } |
|
191 | + |
|
192 | + $this->assign('cssfiles', array()); |
|
193 | + $this->assign('printcssfiles', []); |
|
194 | + $this->assign('versionHash', self::$versionHash); |
|
195 | + foreach($cssFiles as $info) { |
|
196 | + $web = $info[1]; |
|
197 | + $file = $info[2]; |
|
198 | + |
|
199 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
200 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
201 | + } else { |
|
202 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param string $path |
|
209 | + * @param string $file |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
213 | + if ($this->config->getSystemValue('debug', false)) { |
|
214 | + // allows chrome workspace mapping in debug mode |
|
215 | + return ""; |
|
216 | + } |
|
217 | + $themingSuffix = ''; |
|
218 | + $v = []; |
|
219 | + |
|
220 | + if ($this->config->getSystemValue('installed', false)) { |
|
221 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
222 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
223 | + } |
|
224 | + $v = \OC_App::getAppVersions(); |
|
225 | + } |
|
226 | + |
|
227 | + // Try the webroot path for a match |
|
228 | + if ($path !== false && $path !== '') { |
|
229 | + $appName = $this->getAppNamefromPath($path); |
|
230 | + if(array_key_exists($appName, $v)) { |
|
231 | + $appVersion = $v[$appName]; |
|
232 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
233 | + } |
|
234 | + } |
|
235 | + // fallback to the file path instead |
|
236 | + if ($file !== false && $file !== '') { |
|
237 | + $appName = $this->getAppNamefromPath($file); |
|
238 | + if(array_key_exists($appName, $v)) { |
|
239 | + $appVersion = $v[$appName]; |
|
240 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array $styles |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
252 | + // Read the selected theme from the config file |
|
253 | + $theme = \OC_Util::getTheme(); |
|
254 | + |
|
255 | + if($compileScss) { |
|
256 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
257 | + } else { |
|
258 | + $SCSSCacher = null; |
|
259 | + } |
|
260 | + |
|
261 | + $locator = new \OC\Template\CSSResourceLocator( |
|
262 | + \OC::$server->getLogger(), |
|
263 | + $theme, |
|
264 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
265 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
266 | + $SCSSCacher |
|
267 | + ); |
|
268 | + $locator->find($styles); |
|
269 | + return $locator->getResources(); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $path |
|
274 | + * @return string|boolean |
|
275 | + */ |
|
276 | + public function getAppNamefromPath($path) { |
|
277 | + if ($path !== '' && is_string($path)) { |
|
278 | + $pathParts = explode('/', $path); |
|
279 | + if ($pathParts[0] === 'css') { |
|
280 | + // This is a scss request |
|
281 | + return $pathParts[1]; |
|
282 | + } |
|
283 | + return end($pathParts); |
|
284 | + } |
|
285 | + return false; |
|
286 | + |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @param array $scripts |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + static public function findJavascriptFiles($scripts) { |
|
294 | + // Read the selected theme from the config file |
|
295 | + $theme = \OC_Util::getTheme(); |
|
296 | + |
|
297 | + $locator = new \OC\Template\JSResourceLocator( |
|
298 | + \OC::$server->getLogger(), |
|
299 | + $theme, |
|
300 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
301 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
302 | + new JSCombiner( |
|
303 | + \OC::$server->getAppDataDir('js'), |
|
304 | + \OC::$server->getURLGenerator(), |
|
305 | + \OC::$server->getMemCacheFactory()->createDistributed('JS'), |
|
306 | + \OC::$server->getSystemConfig(), |
|
307 | + \OC::$server->getLogger() |
|
308 | + ) |
|
309 | + ); |
|
310 | + $locator->find($scripts); |
|
311 | + return $locator->getResources(); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
316 | + * @param string $filePath Absolute path |
|
317 | + * @return string Relative path |
|
318 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
319 | + */ |
|
320 | + public static function convertToRelativePath($filePath) { |
|
321 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
322 | + if(count($relativePath) !== 2) { |
|
323 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
324 | + } |
|
325 | + |
|
326 | + return $relativePath[1]; |
|
327 | + } |
|
328 | 328 | } |