Completed
Push — master ( 94c2f1...705483 )
by Morris
31s
created
lib/private/Updater.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@
 block discarded – undo
32 32
 
33 33
 namespace OC;
34 34
 
35
-use OC\App\AppStore\Fetcher\AppFetcher;
36 35
 use OC\Hooks\BasicEmitter;
37 36
 use OC\IntegrityCheck\Checker;
38 37
 use OC_App;
Please login to merge, or discard this patch.
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -52,568 +52,568 @@
 block discarded – undo
52 52
  */
53 53
 class Updater extends BasicEmitter {
54 54
 
55
-	/** @var ILogger $log */
56
-	private $log;
57
-
58
-	/** @var IConfig */
59
-	private $config;
60
-
61
-	/** @var Checker */
62
-	private $checker;
63
-
64
-	/** @var bool */
65
-	private $skip3rdPartyAppsDisable;
66
-
67
-	private $logLevelNames = [
68
-		0 => 'Debug',
69
-		1 => 'Info',
70
-		2 => 'Warning',
71
-		3 => 'Error',
72
-		4 => 'Fatal',
73
-	];
74
-
75
-	/**
76
-	 * @param IConfig $config
77
-	 * @param Checker $checker
78
-	 * @param ILogger $log
79
-	 */
80
-	public function __construct(IConfig $config,
81
-								Checker $checker,
82
-								ILogger $log = null) {
83
-		$this->log = $log;
84
-		$this->config = $config;
85
-		$this->checker = $checker;
86
-
87
-		// If at least PHP 7.0.0 is used we don't need to disable apps as we catch
88
-		// fatal errors and exceptions and disable the app just instead.
89
-		if(version_compare(phpversion(), '7.0.0', '>=')) {
90
-			$this->skip3rdPartyAppsDisable = true;
91
-		}
92
-	}
93
-
94
-	/**
95
-	 * Sets whether the update disables 3rd party apps.
96
-	 * This can be set to true to skip the disable.
97
-	 *
98
-	 * @param bool $flag false to not disable, true otherwise
99
-	 */
100
-	public function setSkip3rdPartyAppsDisable($flag) {
101
-		$this->skip3rdPartyAppsDisable = $flag;
102
-	}
103
-
104
-	/**
105
-	 * runs the update actions in maintenance mode, does not upgrade the source files
106
-	 * except the main .htaccess file
107
-	 *
108
-	 * @return bool true if the operation succeeded, false otherwise
109
-	 */
110
-	public function upgrade() {
111
-		$this->emitRepairEvents();
112
-		$this->logAllEvents();
113
-
114
-		$logLevel = $this->config->getSystemValue('loglevel', Util::WARN);
115
-		$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
116
-		$this->config->setSystemValue('loglevel', Util::DEBUG);
117
-
118
-		$wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
119
-
120
-		if(!$wasMaintenanceModeEnabled) {
121
-			$this->config->setSystemValue('maintenance', true);
122
-			$this->emit('\OC\Updater', 'maintenanceEnabled');
123
-		}
124
-
125
-		$installedVersion = $this->config->getSystemValue('version', '0.0.0');
126
-		$currentVersion = implode('.', \OCP\Util::getVersion());
127
-		$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
128
-
129
-		$success = true;
130
-		try {
131
-			$this->doUpgrade($currentVersion, $installedVersion);
132
-		} catch (HintException $exception) {
133
-			$this->log->logException($exception, ['app' => 'core']);
134
-			$this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint()));
135
-			$success = false;
136
-		} catch (\Exception $exception) {
137
-			$this->log->logException($exception, ['app' => 'core']);
138
-			$this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
139
-			$success = false;
140
-		}
141
-
142
-		$this->emit('\OC\Updater', 'updateEnd', array($success));
143
-
144
-		if(!$wasMaintenanceModeEnabled && $success) {
145
-			$this->config->setSystemValue('maintenance', false);
146
-			$this->emit('\OC\Updater', 'maintenanceDisabled');
147
-		} else {
148
-			$this->emit('\OC\Updater', 'maintenanceActive');
149
-		}
150
-
151
-		$this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
152
-		$this->config->setSystemValue('loglevel', $logLevel);
153
-		$this->config->setSystemValue('installed', true);
154
-
155
-		return $success;
156
-	}
157
-
158
-	/**
159
-	 * Return version from which this version is allowed to upgrade from
160
-	 *
161
-	 * @return array allowed previous versions per vendor
162
-	 */
163
-	private function getAllowedPreviousVersions() {
164
-		// this should really be a JSON file
165
-		require \OC::$SERVERROOT . '/version.php';
166
-		/** @var array $OC_VersionCanBeUpgradedFrom */
167
-		return $OC_VersionCanBeUpgradedFrom;
168
-	}
169
-
170
-	/**
171
-	 * Return vendor from which this version was published
172
-	 *
173
-	 * @return string Get the vendor
174
-	 */
175
-	private function getVendor() {
176
-		// this should really be a JSON file
177
-		require \OC::$SERVERROOT . '/version.php';
178
-		/** @var string $vendor */
179
-		return (string) $vendor;
180
-	}
181
-
182
-	/**
183
-	 * Whether an upgrade to a specified version is possible
184
-	 * @param string $oldVersion
185
-	 * @param string $newVersion
186
-	 * @param array $allowedPreviousVersions
187
-	 * @return bool
188
-	 */
189
-	public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
190
-		$version = explode('.', $oldVersion);
191
-		$majorMinor = $version[0] . '.' . $version[1];
192
-
193
-		$currentVendor = $this->config->getAppValue('core', 'vendor', '');
194
-		if ($currentVendor === 'nextcloud') {
195
-			return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
196
-				&& (version_compare($oldVersion, $newVersion, '<=') ||
197
-					$this->config->getSystemValue('debug', false));
198
-		}
199
-
200
-		// Check if the instance can be migrated
201
-		return isset($allowedPreviousVersions[$currentVendor][$majorMinor]);
202
-	}
203
-
204
-	/**
205
-	 * runs the update actions in maintenance mode, does not upgrade the source files
206
-	 * except the main .htaccess file
207
-	 *
208
-	 * @param string $currentVersion current version to upgrade to
209
-	 * @param string $installedVersion previous version from which to upgrade from
210
-	 *
211
-	 * @throws \Exception
212
-	 */
213
-	private function doUpgrade($currentVersion, $installedVersion) {
214
-		// Stop update if the update is over several major versions
215
-		$allowedPreviousVersions = $this->getAllowedPreviousVersions();
216
-		if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
217
-			throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
218
-		}
219
-
220
-		// Update .htaccess files
221
-		try {
222
-			Setup::updateHtaccess();
223
-			Setup::protectDataDirectory();
224
-		} catch (\Exception $e) {
225
-			throw new \Exception($e->getMessage());
226
-		}
227
-
228
-		// create empty file in data dir, so we can later find
229
-		// out that this is indeed an ownCloud data directory
230
-		// (in case it didn't exist before)
231
-		file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
232
-
233
-		// pre-upgrade repairs
234
-		$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
235
-		$repair->run();
236
-
237
-		$this->doCoreUpgrade();
238
-
239
-		try {
240
-			// TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
241
-			Setup::installBackgroundJobs();
242
-		} catch (\Exception $e) {
243
-			throw new \Exception($e->getMessage());
244
-		}
245
-
246
-		// update all shipped apps
247
-		$this->checkAppsRequirements();
248
-		$this->doAppUpgrade();
249
-
250
-		// Update the appfetchers version so it downloads the correct list from the appstore
251
-		\OC::$server->getAppFetcher()->setVersion($currentVersion);
252
-
253
-		// upgrade appstore apps
254
-		$this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps());
255
-
256
-		// install new shipped apps on upgrade
257
-		OC_App::loadApps('authentication');
258
-		$errors = Installer::installShippedApps(true);
259
-		foreach ($errors as $appId => $exception) {
260
-			/** @var \Exception $exception */
261
-			$this->log->logException($exception, ['app' => $appId]);
262
-			$this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
263
-		}
264
-
265
-		// post-upgrade repairs
266
-		$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
267
-		$repair->run();
268
-
269
-		//Invalidate update feed
270
-		$this->config->setAppValue('core', 'lastupdatedat', 0);
271
-
272
-		// Check for code integrity if not disabled
273
-		if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
274
-			$this->emit('\OC\Updater', 'startCheckCodeIntegrity');
275
-			$this->checker->runInstanceVerification();
276
-			$this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
277
-		}
278
-
279
-		// only set the final version if everything went well
280
-		$this->config->setSystemValue('version', implode('.', Util::getVersion()));
281
-		$this->config->setAppValue('core', 'vendor', $this->getVendor());
282
-	}
283
-
284
-	protected function doCoreUpgrade() {
285
-		$this->emit('\OC\Updater', 'dbUpgradeBefore');
286
-
287
-		// do the real upgrade
288
-		\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
289
-
290
-		$this->emit('\OC\Updater', 'dbUpgrade');
291
-	}
292
-
293
-	/**
294
-	 * @param string $version the oc version to check app compatibility with
295
-	 */
296
-	protected function checkAppUpgrade($version) {
297
-		$apps = \OC_App::getEnabledApps();
298
-		$this->emit('\OC\Updater', 'appUpgradeCheckBefore');
299
-
300
-		foreach ($apps as $appId) {
301
-			$info = \OC_App::getAppInfo($appId);
302
-			$compatible = \OC_App::isAppCompatible($version, $info);
303
-			$isShipped = \OC_App::isShipped($appId);
304
-
305
-			if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) {
306
-				/**
307
-				 * FIXME: The preupdate check is performed before the database migration, otherwise database changes
308
-				 * are not possible anymore within it. - Consider this when touching the code.
309
-				 * @link https://github.com/owncloud/core/issues/10980
310
-				 * @see \OC_App::updateApp
311
-				 */
312
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
313
-					$this->includePreUpdate($appId);
314
-				}
315
-				if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
316
-					$this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
317
-					\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
318
-				}
319
-			}
320
-		}
321
-
322
-		$this->emit('\OC\Updater', 'appUpgradeCheck');
323
-	}
324
-
325
-	/**
326
-	 * Includes the pre-update file. Done here to prevent namespace mixups.
327
-	 * @param string $appId
328
-	 */
329
-	private function includePreUpdate($appId) {
330
-		include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
331
-	}
332
-
333
-	/**
334
-	 * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
335
-	 * (types authentication, filesystem, logging, in that order) afterwards.
336
-	 *
337
-	 * @throws NeedsUpdateException
338
-	 */
339
-	protected function doAppUpgrade() {
340
-		$apps = \OC_App::getEnabledApps();
341
-		$priorityTypes = array('authentication', 'filesystem', 'logging');
342
-		$pseudoOtherType = 'other';
343
-		$stacks = array($pseudoOtherType => array());
344
-
345
-		foreach ($apps as $appId) {
346
-			$priorityType = false;
347
-			foreach ($priorityTypes as $type) {
348
-				if(!isset($stacks[$type])) {
349
-					$stacks[$type] = array();
350
-				}
351
-				if (\OC_App::isType($appId, $type)) {
352
-					$stacks[$type][] = $appId;
353
-					$priorityType = true;
354
-					break;
355
-				}
356
-			}
357
-			if (!$priorityType) {
358
-				$stacks[$pseudoOtherType][] = $appId;
359
-			}
360
-		}
361
-		foreach ($stacks as $type => $stack) {
362
-			foreach ($stack as $appId) {
363
-				if (\OC_App::shouldUpgrade($appId)) {
364
-					$this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
365
-					\OC_App::updateApp($appId);
366
-					$this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
367
-				}
368
-				if($type !== $pseudoOtherType) {
369
-					// load authentication, filesystem and logging apps after
370
-					// upgrading them. Other apps my need to rely on modifying
371
-					// user and/or filesystem aspects.
372
-					\OC_App::loadApp($appId);
373
-				}
374
-			}
375
-		}
376
-	}
377
-
378
-	/**
379
-	 * check if the current enabled apps are compatible with the current
380
-	 * ownCloud version. disable them if not.
381
-	 * This is important if you upgrade ownCloud and have non ported 3rd
382
-	 * party apps installed.
383
-	 *
384
-	 * @return array
385
-	 * @throws \Exception
386
-	 */
387
-	private function checkAppsRequirements() {
388
-		$isCoreUpgrade = $this->isCodeUpgrade();
389
-		$apps = OC_App::getEnabledApps();
390
-		$version = Util::getVersion();
391
-		$disabledApps = [];
392
-		foreach ($apps as $app) {
393
-			// check if the app is compatible with this version of ownCloud
394
-			$info = OC_App::getAppInfo($app);
395
-			if(!OC_App::isAppCompatible($version, $info)) {
396
-				if (OC_App::isShipped($app)) {
397
-					throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
398
-				}
399
-				OC_App::disable($app);
400
-				$this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
401
-			}
402
-			// no need to disable any app in case this is a non-core upgrade
403
-			if (!$isCoreUpgrade) {
404
-				continue;
405
-			}
406
-			// shipped apps will remain enabled
407
-			if (OC_App::isShipped($app)) {
408
-				continue;
409
-			}
410
-			// authentication and session apps will remain enabled as well
411
-			if (OC_App::isType($app, ['session', 'authentication'])) {
412
-				continue;
413
-			}
414
-
415
-			// disable any other 3rd party apps if not overriden
416
-			if(!$this->skip3rdPartyAppsDisable) {
417
-				\OC_App::disable($app);
418
-				$disabledApps[]= $app;
419
-				$this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app));
420
-			};
421
-		}
422
-		return $disabledApps;
423
-	}
424
-
425
-	/**
426
-	 * @return bool
427
-	 */
428
-	private function isCodeUpgrade() {
429
-		$installedVersion = $this->config->getSystemValue('version', '0.0.0');
430
-		$currentVersion = implode('.', Util::getVersion());
431
-		if (version_compare($currentVersion, $installedVersion, '>')) {
432
-			return true;
433
-		}
434
-		return false;
435
-	}
436
-
437
-	/**
438
-	 * @param array $disabledApps
439
-	 * @throws \Exception
440
-	 */
441
-	private function upgradeAppStoreApps(array $disabledApps) {
442
-		foreach($disabledApps as $app) {
443
-			try {
444
-				$installer = new Installer(
445
-					\OC::$server->getAppFetcher(),
446
-					\OC::$server->getHTTPClientService(),
447
-					\OC::$server->getTempManager(),
448
-					$this->log,
449
-					\OC::$server->getConfig()
450
-				);
451
-				if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) {
452
-					$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
453
-					$installer->updateAppstoreApp($app);
454
-				}
455
-			} catch (\Exception $ex) {
456
-				$this->log->logException($ex, ['app' => 'core']);
457
-			}
458
-		}
459
-	}
460
-
461
-	/**
462
-	 * Forward messages emitted by the repair routine
463
-	 */
464
-	private function emitRepairEvents() {
465
-		$dispatcher = \OC::$server->getEventDispatcher();
466
-		$dispatcher->addListener('\OC\Repair::warning', function ($event) {
467
-			if ($event instanceof GenericEvent) {
468
-				$this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
469
-			}
470
-		});
471
-		$dispatcher->addListener('\OC\Repair::error', function ($event) {
472
-			if ($event instanceof GenericEvent) {
473
-				$this->emit('\OC\Updater', 'repairError', $event->getArguments());
474
-			}
475
-		});
476
-		$dispatcher->addListener('\OC\Repair::info', function ($event) {
477
-			if ($event instanceof GenericEvent) {
478
-				$this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
479
-			}
480
-		});
481
-		$dispatcher->addListener('\OC\Repair::step', function ($event) {
482
-			if ($event instanceof GenericEvent) {
483
-				$this->emit('\OC\Updater', 'repairStep', $event->getArguments());
484
-			}
485
-		});
486
-	}
487
-
488
-	private function logAllEvents() {
489
-		$log = $this->log;
490
-
491
-		$dispatcher = \OC::$server->getEventDispatcher();
492
-		$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
493
-			if (!$event instanceof GenericEvent) {
494
-				return;
495
-			}
496
-			$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
497
-		});
498
-		$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
499
-			if (!$event instanceof GenericEvent) {
500
-				return;
501
-			}
502
-			$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
503
-		});
504
-
505
-		$repairListener = function($event) use ($log) {
506
-			if (!$event instanceof GenericEvent) {
507
-				return;
508
-			}
509
-			switch ($event->getSubject()) {
510
-				case '\OC\Repair::startProgress':
511
-					$log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) .  ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
512
-					break;
513
-				case '\OC\Repair::advance':
514
-					$desc = $event->getArgument(1);
515
-					if (empty($desc)) {
516
-						$desc = '';
517
-					}
518
-					$log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
519
-
520
-					break;
521
-				case '\OC\Repair::finishProgress':
522
-					$log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
523
-					break;
524
-				case '\OC\Repair::step':
525
-					$log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
526
-					break;
527
-				case '\OC\Repair::info':
528
-					$log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
529
-					break;
530
-				case '\OC\Repair::warning':
531
-					$log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
532
-					break;
533
-				case '\OC\Repair::error':
534
-					$log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
535
-					break;
536
-			}
537
-		};
538
-
539
-		$dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
540
-		$dispatcher->addListener('\OC\Repair::advance', $repairListener);
541
-		$dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
542
-		$dispatcher->addListener('\OC\Repair::step', $repairListener);
543
-		$dispatcher->addListener('\OC\Repair::info', $repairListener);
544
-		$dispatcher->addListener('\OC\Repair::warning', $repairListener);
545
-		$dispatcher->addListener('\OC\Repair::error', $repairListener);
546
-
547
-
548
-		$this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
549
-			$log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
550
-		});
551
-		$this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
552
-			$log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
553
-		});
554
-		$this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
555
-			$log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
556
-		});
557
-		$this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
558
-			if ($success) {
559
-				$log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
560
-			} else {
561
-				$log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
562
-			}
563
-		});
564
-		$this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
565
-			$log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
566
-		});
567
-		$this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
568
-			$log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
569
-		});
570
-		$this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
571
-			$log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
572
-		});
573
-		$this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
574
-			$log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
575
-		});
576
-		$this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
577
-			$log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
578
-		});
579
-		$this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) {
580
-			$log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']);
581
-		});
582
-		$this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
583
-			$log->info('\OC\Updater::upgradeAppStoreApp: Update 3rd-party app: ' . $app, ['app' => 'updater']);
584
-		});
585
-		$this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
586
-			$log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
587
-		});
588
-		$this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
589
-			$log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
590
-		});
591
-		$this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
592
-			$log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
593
-		});
594
-		$this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
595
-			$log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
596
-		});
597
-		$this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
598
-			$log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
599
-		});
600
-		$this->listen('\OC\Updater', 'failure', function ($message) use($log) {
601
-			$log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
602
-		});
603
-		$this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
604
-			$log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
605
-		});
606
-		$this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
607
-			$log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
608
-		});
609
-		$this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
610
-			$log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
611
-		});
612
-		$this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
613
-			$log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
614
-		});
615
-
616
-	}
55
+    /** @var ILogger $log */
56
+    private $log;
57
+
58
+    /** @var IConfig */
59
+    private $config;
60
+
61
+    /** @var Checker */
62
+    private $checker;
63
+
64
+    /** @var bool */
65
+    private $skip3rdPartyAppsDisable;
66
+
67
+    private $logLevelNames = [
68
+        0 => 'Debug',
69
+        1 => 'Info',
70
+        2 => 'Warning',
71
+        3 => 'Error',
72
+        4 => 'Fatal',
73
+    ];
74
+
75
+    /**
76
+     * @param IConfig $config
77
+     * @param Checker $checker
78
+     * @param ILogger $log
79
+     */
80
+    public function __construct(IConfig $config,
81
+                                Checker $checker,
82
+                                ILogger $log = null) {
83
+        $this->log = $log;
84
+        $this->config = $config;
85
+        $this->checker = $checker;
86
+
87
+        // If at least PHP 7.0.0 is used we don't need to disable apps as we catch
88
+        // fatal errors and exceptions and disable the app just instead.
89
+        if(version_compare(phpversion(), '7.0.0', '>=')) {
90
+            $this->skip3rdPartyAppsDisable = true;
91
+        }
92
+    }
93
+
94
+    /**
95
+     * Sets whether the update disables 3rd party apps.
96
+     * This can be set to true to skip the disable.
97
+     *
98
+     * @param bool $flag false to not disable, true otherwise
99
+     */
100
+    public function setSkip3rdPartyAppsDisable($flag) {
101
+        $this->skip3rdPartyAppsDisable = $flag;
102
+    }
103
+
104
+    /**
105
+     * runs the update actions in maintenance mode, does not upgrade the source files
106
+     * except the main .htaccess file
107
+     *
108
+     * @return bool true if the operation succeeded, false otherwise
109
+     */
110
+    public function upgrade() {
111
+        $this->emitRepairEvents();
112
+        $this->logAllEvents();
113
+
114
+        $logLevel = $this->config->getSystemValue('loglevel', Util::WARN);
115
+        $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
116
+        $this->config->setSystemValue('loglevel', Util::DEBUG);
117
+
118
+        $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
119
+
120
+        if(!$wasMaintenanceModeEnabled) {
121
+            $this->config->setSystemValue('maintenance', true);
122
+            $this->emit('\OC\Updater', 'maintenanceEnabled');
123
+        }
124
+
125
+        $installedVersion = $this->config->getSystemValue('version', '0.0.0');
126
+        $currentVersion = implode('.', \OCP\Util::getVersion());
127
+        $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
128
+
129
+        $success = true;
130
+        try {
131
+            $this->doUpgrade($currentVersion, $installedVersion);
132
+        } catch (HintException $exception) {
133
+            $this->log->logException($exception, ['app' => 'core']);
134
+            $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint()));
135
+            $success = false;
136
+        } catch (\Exception $exception) {
137
+            $this->log->logException($exception, ['app' => 'core']);
138
+            $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage()));
139
+            $success = false;
140
+        }
141
+
142
+        $this->emit('\OC\Updater', 'updateEnd', array($success));
143
+
144
+        if(!$wasMaintenanceModeEnabled && $success) {
145
+            $this->config->setSystemValue('maintenance', false);
146
+            $this->emit('\OC\Updater', 'maintenanceDisabled');
147
+        } else {
148
+            $this->emit('\OC\Updater', 'maintenanceActive');
149
+        }
150
+
151
+        $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
152
+        $this->config->setSystemValue('loglevel', $logLevel);
153
+        $this->config->setSystemValue('installed', true);
154
+
155
+        return $success;
156
+    }
157
+
158
+    /**
159
+     * Return version from which this version is allowed to upgrade from
160
+     *
161
+     * @return array allowed previous versions per vendor
162
+     */
163
+    private function getAllowedPreviousVersions() {
164
+        // this should really be a JSON file
165
+        require \OC::$SERVERROOT . '/version.php';
166
+        /** @var array $OC_VersionCanBeUpgradedFrom */
167
+        return $OC_VersionCanBeUpgradedFrom;
168
+    }
169
+
170
+    /**
171
+     * Return vendor from which this version was published
172
+     *
173
+     * @return string Get the vendor
174
+     */
175
+    private function getVendor() {
176
+        // this should really be a JSON file
177
+        require \OC::$SERVERROOT . '/version.php';
178
+        /** @var string $vendor */
179
+        return (string) $vendor;
180
+    }
181
+
182
+    /**
183
+     * Whether an upgrade to a specified version is possible
184
+     * @param string $oldVersion
185
+     * @param string $newVersion
186
+     * @param array $allowedPreviousVersions
187
+     * @return bool
188
+     */
189
+    public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) {
190
+        $version = explode('.', $oldVersion);
191
+        $majorMinor = $version[0] . '.' . $version[1];
192
+
193
+        $currentVendor = $this->config->getAppValue('core', 'vendor', '');
194
+        if ($currentVendor === 'nextcloud') {
195
+            return isset($allowedPreviousVersions[$currentVendor][$majorMinor])
196
+                && (version_compare($oldVersion, $newVersion, '<=') ||
197
+                    $this->config->getSystemValue('debug', false));
198
+        }
199
+
200
+        // Check if the instance can be migrated
201
+        return isset($allowedPreviousVersions[$currentVendor][$majorMinor]);
202
+    }
203
+
204
+    /**
205
+     * runs the update actions in maintenance mode, does not upgrade the source files
206
+     * except the main .htaccess file
207
+     *
208
+     * @param string $currentVersion current version to upgrade to
209
+     * @param string $installedVersion previous version from which to upgrade from
210
+     *
211
+     * @throws \Exception
212
+     */
213
+    private function doUpgrade($currentVersion, $installedVersion) {
214
+        // Stop update if the update is over several major versions
215
+        $allowedPreviousVersions = $this->getAllowedPreviousVersions();
216
+        if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) {
217
+            throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
218
+        }
219
+
220
+        // Update .htaccess files
221
+        try {
222
+            Setup::updateHtaccess();
223
+            Setup::protectDataDirectory();
224
+        } catch (\Exception $e) {
225
+            throw new \Exception($e->getMessage());
226
+        }
227
+
228
+        // create empty file in data dir, so we can later find
229
+        // out that this is indeed an ownCloud data directory
230
+        // (in case it didn't exist before)
231
+        file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
232
+
233
+        // pre-upgrade repairs
234
+        $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
235
+        $repair->run();
236
+
237
+        $this->doCoreUpgrade();
238
+
239
+        try {
240
+            // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378
241
+            Setup::installBackgroundJobs();
242
+        } catch (\Exception $e) {
243
+            throw new \Exception($e->getMessage());
244
+        }
245
+
246
+        // update all shipped apps
247
+        $this->checkAppsRequirements();
248
+        $this->doAppUpgrade();
249
+
250
+        // Update the appfetchers version so it downloads the correct list from the appstore
251
+        \OC::$server->getAppFetcher()->setVersion($currentVersion);
252
+
253
+        // upgrade appstore apps
254
+        $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps());
255
+
256
+        // install new shipped apps on upgrade
257
+        OC_App::loadApps('authentication');
258
+        $errors = Installer::installShippedApps(true);
259
+        foreach ($errors as $appId => $exception) {
260
+            /** @var \Exception $exception */
261
+            $this->log->logException($exception, ['app' => $appId]);
262
+            $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
263
+        }
264
+
265
+        // post-upgrade repairs
266
+        $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
267
+        $repair->run();
268
+
269
+        //Invalidate update feed
270
+        $this->config->setAppValue('core', 'lastupdatedat', 0);
271
+
272
+        // Check for code integrity if not disabled
273
+        if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
274
+            $this->emit('\OC\Updater', 'startCheckCodeIntegrity');
275
+            $this->checker->runInstanceVerification();
276
+            $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity');
277
+        }
278
+
279
+        // only set the final version if everything went well
280
+        $this->config->setSystemValue('version', implode('.', Util::getVersion()));
281
+        $this->config->setAppValue('core', 'vendor', $this->getVendor());
282
+    }
283
+
284
+    protected function doCoreUpgrade() {
285
+        $this->emit('\OC\Updater', 'dbUpgradeBefore');
286
+
287
+        // do the real upgrade
288
+        \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
289
+
290
+        $this->emit('\OC\Updater', 'dbUpgrade');
291
+    }
292
+
293
+    /**
294
+     * @param string $version the oc version to check app compatibility with
295
+     */
296
+    protected function checkAppUpgrade($version) {
297
+        $apps = \OC_App::getEnabledApps();
298
+        $this->emit('\OC\Updater', 'appUpgradeCheckBefore');
299
+
300
+        foreach ($apps as $appId) {
301
+            $info = \OC_App::getAppInfo($appId);
302
+            $compatible = \OC_App::isAppCompatible($version, $info);
303
+            $isShipped = \OC_App::isShipped($appId);
304
+
305
+            if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) {
306
+                /**
307
+                 * FIXME: The preupdate check is performed before the database migration, otherwise database changes
308
+                 * are not possible anymore within it. - Consider this when touching the code.
309
+                 * @link https://github.com/owncloud/core/issues/10980
310
+                 * @see \OC_App::updateApp
311
+                 */
312
+                if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
313
+                    $this->includePreUpdate($appId);
314
+                }
315
+                if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
316
+                    $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId));
317
+                    \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
318
+                }
319
+            }
320
+        }
321
+
322
+        $this->emit('\OC\Updater', 'appUpgradeCheck');
323
+    }
324
+
325
+    /**
326
+     * Includes the pre-update file. Done here to prevent namespace mixups.
327
+     * @param string $appId
328
+     */
329
+    private function includePreUpdate($appId) {
330
+        include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php';
331
+    }
332
+
333
+    /**
334
+     * upgrades all apps within a major ownCloud upgrade. Also loads "priority"
335
+     * (types authentication, filesystem, logging, in that order) afterwards.
336
+     *
337
+     * @throws NeedsUpdateException
338
+     */
339
+    protected function doAppUpgrade() {
340
+        $apps = \OC_App::getEnabledApps();
341
+        $priorityTypes = array('authentication', 'filesystem', 'logging');
342
+        $pseudoOtherType = 'other';
343
+        $stacks = array($pseudoOtherType => array());
344
+
345
+        foreach ($apps as $appId) {
346
+            $priorityType = false;
347
+            foreach ($priorityTypes as $type) {
348
+                if(!isset($stacks[$type])) {
349
+                    $stacks[$type] = array();
350
+                }
351
+                if (\OC_App::isType($appId, $type)) {
352
+                    $stacks[$type][] = $appId;
353
+                    $priorityType = true;
354
+                    break;
355
+                }
356
+            }
357
+            if (!$priorityType) {
358
+                $stacks[$pseudoOtherType][] = $appId;
359
+            }
360
+        }
361
+        foreach ($stacks as $type => $stack) {
362
+            foreach ($stack as $appId) {
363
+                if (\OC_App::shouldUpgrade($appId)) {
364
+                    $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]);
365
+                    \OC_App::updateApp($appId);
366
+                    $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]);
367
+                }
368
+                if($type !== $pseudoOtherType) {
369
+                    // load authentication, filesystem and logging apps after
370
+                    // upgrading them. Other apps my need to rely on modifying
371
+                    // user and/or filesystem aspects.
372
+                    \OC_App::loadApp($appId);
373
+                }
374
+            }
375
+        }
376
+    }
377
+
378
+    /**
379
+     * check if the current enabled apps are compatible with the current
380
+     * ownCloud version. disable them if not.
381
+     * This is important if you upgrade ownCloud and have non ported 3rd
382
+     * party apps installed.
383
+     *
384
+     * @return array
385
+     * @throws \Exception
386
+     */
387
+    private function checkAppsRequirements() {
388
+        $isCoreUpgrade = $this->isCodeUpgrade();
389
+        $apps = OC_App::getEnabledApps();
390
+        $version = Util::getVersion();
391
+        $disabledApps = [];
392
+        foreach ($apps as $app) {
393
+            // check if the app is compatible with this version of ownCloud
394
+            $info = OC_App::getAppInfo($app);
395
+            if(!OC_App::isAppCompatible($version, $info)) {
396
+                if (OC_App::isShipped($app)) {
397
+                    throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
398
+                }
399
+                OC_App::disable($app);
400
+                $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app));
401
+            }
402
+            // no need to disable any app in case this is a non-core upgrade
403
+            if (!$isCoreUpgrade) {
404
+                continue;
405
+            }
406
+            // shipped apps will remain enabled
407
+            if (OC_App::isShipped($app)) {
408
+                continue;
409
+            }
410
+            // authentication and session apps will remain enabled as well
411
+            if (OC_App::isType($app, ['session', 'authentication'])) {
412
+                continue;
413
+            }
414
+
415
+            // disable any other 3rd party apps if not overriden
416
+            if(!$this->skip3rdPartyAppsDisable) {
417
+                \OC_App::disable($app);
418
+                $disabledApps[]= $app;
419
+                $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app));
420
+            };
421
+        }
422
+        return $disabledApps;
423
+    }
424
+
425
+    /**
426
+     * @return bool
427
+     */
428
+    private function isCodeUpgrade() {
429
+        $installedVersion = $this->config->getSystemValue('version', '0.0.0');
430
+        $currentVersion = implode('.', Util::getVersion());
431
+        if (version_compare($currentVersion, $installedVersion, '>')) {
432
+            return true;
433
+        }
434
+        return false;
435
+    }
436
+
437
+    /**
438
+     * @param array $disabledApps
439
+     * @throws \Exception
440
+     */
441
+    private function upgradeAppStoreApps(array $disabledApps) {
442
+        foreach($disabledApps as $app) {
443
+            try {
444
+                $installer = new Installer(
445
+                    \OC::$server->getAppFetcher(),
446
+                    \OC::$server->getHTTPClientService(),
447
+                    \OC::$server->getTempManager(),
448
+                    $this->log,
449
+                    \OC::$server->getConfig()
450
+                );
451
+                if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) {
452
+                    $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
453
+                    $installer->updateAppstoreApp($app);
454
+                }
455
+            } catch (\Exception $ex) {
456
+                $this->log->logException($ex, ['app' => 'core']);
457
+            }
458
+        }
459
+    }
460
+
461
+    /**
462
+     * Forward messages emitted by the repair routine
463
+     */
464
+    private function emitRepairEvents() {
465
+        $dispatcher = \OC::$server->getEventDispatcher();
466
+        $dispatcher->addListener('\OC\Repair::warning', function ($event) {
467
+            if ($event instanceof GenericEvent) {
468
+                $this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
469
+            }
470
+        });
471
+        $dispatcher->addListener('\OC\Repair::error', function ($event) {
472
+            if ($event instanceof GenericEvent) {
473
+                $this->emit('\OC\Updater', 'repairError', $event->getArguments());
474
+            }
475
+        });
476
+        $dispatcher->addListener('\OC\Repair::info', function ($event) {
477
+            if ($event instanceof GenericEvent) {
478
+                $this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
479
+            }
480
+        });
481
+        $dispatcher->addListener('\OC\Repair::step', function ($event) {
482
+            if ($event instanceof GenericEvent) {
483
+                $this->emit('\OC\Updater', 'repairStep', $event->getArguments());
484
+            }
485
+        });
486
+    }
487
+
488
+    private function logAllEvents() {
489
+        $log = $this->log;
490
+
491
+        $dispatcher = \OC::$server->getEventDispatcher();
492
+        $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
493
+            if (!$event instanceof GenericEvent) {
494
+                return;
495
+            }
496
+            $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
497
+        });
498
+        $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
499
+            if (!$event instanceof GenericEvent) {
500
+                return;
501
+            }
502
+            $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
503
+        });
504
+
505
+        $repairListener = function($event) use ($log) {
506
+            if (!$event instanceof GenericEvent) {
507
+                return;
508
+            }
509
+            switch ($event->getSubject()) {
510
+                case '\OC\Repair::startProgress':
511
+                    $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) .  ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
512
+                    break;
513
+                case '\OC\Repair::advance':
514
+                    $desc = $event->getArgument(1);
515
+                    if (empty($desc)) {
516
+                        $desc = '';
517
+                    }
518
+                    $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
519
+
520
+                    break;
521
+                case '\OC\Repair::finishProgress':
522
+                    $log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
523
+                    break;
524
+                case '\OC\Repair::step':
525
+                    $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
526
+                    break;
527
+                case '\OC\Repair::info':
528
+                    $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
529
+                    break;
530
+                case '\OC\Repair::warning':
531
+                    $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
532
+                    break;
533
+                case '\OC\Repair::error':
534
+                    $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
535
+                    break;
536
+            }
537
+        };
538
+
539
+        $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
540
+        $dispatcher->addListener('\OC\Repair::advance', $repairListener);
541
+        $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
542
+        $dispatcher->addListener('\OC\Repair::step', $repairListener);
543
+        $dispatcher->addListener('\OC\Repair::info', $repairListener);
544
+        $dispatcher->addListener('\OC\Repair::warning', $repairListener);
545
+        $dispatcher->addListener('\OC\Repair::error', $repairListener);
546
+
547
+
548
+        $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
549
+            $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
550
+        });
551
+        $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
552
+            $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
553
+        });
554
+        $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
555
+            $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
556
+        });
557
+        $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
558
+            if ($success) {
559
+                $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
560
+            } else {
561
+                $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
562
+            }
563
+        });
564
+        $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
565
+            $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
566
+        });
567
+        $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
568
+            $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
569
+        });
570
+        $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
571
+            $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
572
+        });
573
+        $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
574
+            $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
575
+        });
576
+        $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
577
+            $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
578
+        });
579
+        $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) {
580
+            $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']);
581
+        });
582
+        $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
583
+            $log->info('\OC\Updater::upgradeAppStoreApp: Update 3rd-party app: ' . $app, ['app' => 'updater']);
584
+        });
585
+        $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
586
+            $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
587
+        });
588
+        $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
589
+            $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
590
+        });
591
+        $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
592
+            $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
593
+        });
594
+        $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
595
+            $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
596
+        });
597
+        $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
598
+            $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
599
+        });
600
+        $this->listen('\OC\Updater', 'failure', function ($message) use($log) {
601
+            $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
602
+        });
603
+        $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
604
+            $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
605
+        });
606
+        $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
607
+            $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
608
+        });
609
+        $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
610
+            $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
611
+        });
612
+        $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
613
+            $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
614
+        });
615
+
616
+    }
617 617
 
618 618
 }
619 619
 
Please login to merge, or discard this patch.
lib/private/App/AppStore/Fetcher/AppFetcher.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -28,105 +28,105 @@
 block discarded – undo
28 28
 use OCP\IConfig;
29 29
 
30 30
 class AppFetcher extends Fetcher {
31
-	/**
32
-	 * @param IAppData $appData
33
-	 * @param IClientService $clientService
34
-	 * @param ITimeFactory $timeFactory
35
-	 * @param IConfig $config;
36
-	 */
37
-	public function __construct(IAppData $appData,
38
-								IClientService $clientService,
39
-								ITimeFactory $timeFactory,
40
-								IConfig $config) {
41
-		parent::__construct(
42
-			$appData,
43
-			$clientService,
44
-			$timeFactory,
45
-			$config
46
-		);
31
+    /**
32
+     * @param IAppData $appData
33
+     * @param IClientService $clientService
34
+     * @param ITimeFactory $timeFactory
35
+     * @param IConfig $config;
36
+     */
37
+    public function __construct(IAppData $appData,
38
+                                IClientService $clientService,
39
+                                ITimeFactory $timeFactory,
40
+                                IConfig $config) {
41
+        parent::__construct(
42
+            $appData,
43
+            $clientService,
44
+            $timeFactory,
45
+            $config
46
+        );
47 47
 
48
-		$this->fileName = 'apps.json';
49
-		$this->setEndpoint();
50
-	}
48
+        $this->fileName = 'apps.json';
49
+        $this->setEndpoint();
50
+    }
51 51
 
52
-	/**
53
-	 * Only returns the latest compatible app release in the releases array
54
-	 *
55
-	 * @param string $ETag
56
-	 * @param string $content
57
-	 *
58
-	 * @return array
59
-	 */
60
-	protected function fetch($ETag, $content) {
61
-		/** @var mixed[] $response */
62
-		$response = parent::fetch($ETag, $content);
52
+    /**
53
+     * Only returns the latest compatible app release in the releases array
54
+     *
55
+     * @param string $ETag
56
+     * @param string $content
57
+     *
58
+     * @return array
59
+     */
60
+    protected function fetch($ETag, $content) {
61
+        /** @var mixed[] $response */
62
+        $response = parent::fetch($ETag, $content);
63 63
 
64
-		$ncVersion = $this->getVersion();
65
-		$ncMajorVersion = explode('.', $ncVersion)[0];
66
-		foreach($response['data'] as $dataKey => $app) {
67
-			$releases = [];
64
+        $ncVersion = $this->getVersion();
65
+        $ncMajorVersion = explode('.', $ncVersion)[0];
66
+        foreach($response['data'] as $dataKey => $app) {
67
+            $releases = [];
68 68
 
69
-			// Filter all compatible releases
70
-			foreach($app['releases'] as $release) {
71
-				// Exclude all nightly and pre-releases
72
-				if($release['isNightly'] === false
73
-					&& strpos($release['version'], '-') === false) {
74
-					// Exclude all versions not compatible with the current version
75
-					$versionParser = new VersionParser();
76
-					$version = $versionParser->getVersion($release['rawPlatformVersionSpec']);
77
-					if (
78
-						// Major version is bigger or equals to the minimum version of the app
79
-						version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=')
80
-						// Major version is smaller or equals to the maximum version of the app
81
-						&& version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=')
82
-					) {
83
-						$releases[] = $release;
84
-					}
85
-				}
86
-			}
69
+            // Filter all compatible releases
70
+            foreach($app['releases'] as $release) {
71
+                // Exclude all nightly and pre-releases
72
+                if($release['isNightly'] === false
73
+                    && strpos($release['version'], '-') === false) {
74
+                    // Exclude all versions not compatible with the current version
75
+                    $versionParser = new VersionParser();
76
+                    $version = $versionParser->getVersion($release['rawPlatformVersionSpec']);
77
+                    if (
78
+                        // Major version is bigger or equals to the minimum version of the app
79
+                        version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=')
80
+                        // Major version is smaller or equals to the maximum version of the app
81
+                        && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=')
82
+                    ) {
83
+                        $releases[] = $release;
84
+                    }
85
+                }
86
+            }
87 87
 
88
-			// Get the highest version
89
-			$versions = [];
90
-			foreach($releases as $release) {
91
-				$versions[] = $release['version'];
92
-			}
93
-			usort($versions, 'version_compare');
94
-			$versions = array_reverse($versions);
95
-			$compatible = false;
96
-			if(isset($versions[0])) {
97
-				$highestVersion = $versions[0];
98
-				foreach ($releases as $release) {
99
-					if ((string)$release['version'] === (string)$highestVersion) {
100
-						$compatible = true;
101
-						$response['data'][$dataKey]['releases'] = [$release];
102
-						break;
103
-					}
104
-				}
105
-			}
106
-			if(!$compatible) {
107
-				unset($response['data'][$dataKey]);
108
-			}
109
-		}
88
+            // Get the highest version
89
+            $versions = [];
90
+            foreach($releases as $release) {
91
+                $versions[] = $release['version'];
92
+            }
93
+            usort($versions, 'version_compare');
94
+            $versions = array_reverse($versions);
95
+            $compatible = false;
96
+            if(isset($versions[0])) {
97
+                $highestVersion = $versions[0];
98
+                foreach ($releases as $release) {
99
+                    if ((string)$release['version'] === (string)$highestVersion) {
100
+                        $compatible = true;
101
+                        $response['data'][$dataKey]['releases'] = [$release];
102
+                        break;
103
+                    }
104
+                }
105
+            }
106
+            if(!$compatible) {
107
+                unset($response['data'][$dataKey]);
108
+            }
109
+        }
110 110
 
111
-		$response['data'] = array_values($response['data']);
112
-		return $response;
113
-	}
111
+        $response['data'] = array_values($response['data']);
112
+        return $response;
113
+    }
114 114
 
115
-	private function setEndpoint() {
116
-		$versionArray = explode('.', $this->getVersion());
117
-		$this->endpointUrl = sprintf(
118
-			'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json',
119
-			$versionArray[0],
120
-			$versionArray[1],
121
-			$versionArray[2]
122
-		);
123
-	}
115
+    private function setEndpoint() {
116
+        $versionArray = explode('.', $this->getVersion());
117
+        $this->endpointUrl = sprintf(
118
+            'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json',
119
+            $versionArray[0],
120
+            $versionArray[1],
121
+            $versionArray[2]
122
+        );
123
+    }
124 124
 
125
-	/**
126
-	 * @param string $version
127
-	 */
128
-	public function setVersion($version) {
129
-		parent::setVersion($version);
130
-		$this->setEndpoint();
131
-	}
125
+    /**
126
+     * @param string $version
127
+     */
128
+    public function setVersion($version) {
129
+        parent::setVersion($version);
130
+        $this->setEndpoint();
131
+    }
132 132
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
 
64 64
 		$ncVersion = $this->getVersion();
65 65
 		$ncMajorVersion = explode('.', $ncVersion)[0];
66
-		foreach($response['data'] as $dataKey => $app) {
66
+		foreach ($response['data'] as $dataKey => $app) {
67 67
 			$releases = [];
68 68
 
69 69
 			// Filter all compatible releases
70
-			foreach($app['releases'] as $release) {
70
+			foreach ($app['releases'] as $release) {
71 71
 				// Exclude all nightly and pre-releases
72
-				if($release['isNightly'] === false
72
+				if ($release['isNightly'] === false
73 73
 					&& strpos($release['version'], '-') === false) {
74 74
 					// Exclude all versions not compatible with the current version
75 75
 					$versionParser = new VersionParser();
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 
88 88
 			// Get the highest version
89 89
 			$versions = [];
90
-			foreach($releases as $release) {
90
+			foreach ($releases as $release) {
91 91
 				$versions[] = $release['version'];
92 92
 			}
93 93
 			usort($versions, 'version_compare');
94 94
 			$versions = array_reverse($versions);
95 95
 			$compatible = false;
96
-			if(isset($versions[0])) {
96
+			if (isset($versions[0])) {
97 97
 				$highestVersion = $versions[0];
98 98
 				foreach ($releases as $release) {
99
-					if ((string)$release['version'] === (string)$highestVersion) {
99
+					if ((string) $release['version'] === (string) $highestVersion) {
100 100
 						$compatible = true;
101 101
 						$response['data'][$dataKey]['releases'] = [$release];
102 102
 						break;
103 103
 					}
104 104
 				}
105 105
 			}
106
-			if(!$compatible) {
106
+			if (!$compatible) {
107 107
 				unset($response['data'][$dataKey]);
108 108
 			}
109 109
 		}
Please login to merge, or discard this patch.
lib/private/App/AppStore/Fetcher/Fetcher.php 2 patches
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -29,150 +29,150 @@
 block discarded – undo
29 29
 use OCP\IConfig;
30 30
 
31 31
 abstract class Fetcher {
32
-	const INVALIDATE_AFTER_SECONDS = 300;
33
-
34
-	/** @var IAppData */
35
-	protected $appData;
36
-	/** @var IClientService */
37
-	protected $clientService;
38
-	/** @var ITimeFactory */
39
-	protected $timeFactory;
40
-	/** @var IConfig */
41
-	protected $config;
42
-	/** @var string */
43
-	protected $fileName;
44
-	/** @var string */
45
-	protected $endpointUrl;
46
-	/** @var string */
47
-	protected $version;
48
-
49
-	/**
50
-	 * @param IAppData $appData
51
-	 * @param IClientService $clientService
52
-	 * @param ITimeFactory $timeFactory
53
-	 * @param IConfig $config
54
-	 */
55
-	public function __construct(IAppData $appData,
56
-								IClientService $clientService,
57
-								ITimeFactory $timeFactory,
58
-								IConfig $config) {
59
-		$this->appData = $appData;
60
-		$this->clientService = $clientService;
61
-		$this->timeFactory = $timeFactory;
62
-		$this->config = $config;
63
-	}
64
-
65
-	/**
66
-	 * Fetches the response from the server
67
-	 *
68
-	 * @param string $ETag
69
-	 * @param string $content
70
-	 *
71
-	 * @return array
72
-	 */
73
-	protected function fetch($ETag, $content) {
74
-		$appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
75
-
76
-		if (!$appstoreenabled) {
77
-			return [];
78
-		}
79
-
80
-		$options = [];
81
-
82
-		if ($ETag !== '') {
83
-			$options['headers'] = [
84
-				'If-None-Match' => $ETag,
85
-			];
86
-		}
87
-
88
-		$client = $this->clientService->newClient();
89
-		$response = $client->get($this->endpointUrl, $options);
90
-
91
-		$responseJson = [];
92
-		if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) {
93
-			$responseJson['data'] = json_decode($content, true);
94
-		} else {
95
-			$responseJson['data'] = json_decode($response->getBody(), true);
96
-			$ETag = $response->getHeader('ETag');
97
-		}
98
-
99
-		$responseJson['timestamp'] = $this->timeFactory->getTime();
100
-		$responseJson['ncversion'] = $this->getVersion();
101
-		if ($ETag !== '') {
102
-			$responseJson['ETag'] = $ETag;
103
-		}
104
-
105
-		return $responseJson;
106
-	}
107
-
108
-	/**
109
-	 * Returns the array with the categories on the appstore server
110
-	 *
111
-	 * @return array
112
-	 */
113
-	public function get() {
114
-		$appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
115
-
116
-		if (!$appstoreenabled) {
117
-			return [];
118
-		}
119
-
120
-		$rootFolder = $this->appData->getFolder('/');
121
-
122
-		$ETag = '';
123
-		$content = '';
124
-
125
-		try {
126
-			// File does already exists
127
-			$file = $rootFolder->getFile($this->fileName);
128
-			$jsonBlob = json_decode($file->getContent(), true);
129
-			if (is_array($jsonBlob)) {
130
-
131
-				// No caching when the version has been updated
132
-				if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
133
-
134
-					// If the timestamp is older than 300 seconds request the files new
135
-					if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
136
-						return $jsonBlob['data'];
137
-					}
138
-
139
-					if (isset($jsonBlob['ETag'])) {
140
-						$ETag = $jsonBlob['ETag'];
141
-						$content = json_encode($jsonBlob['data']);
142
-					}
143
-				}
144
-			}
145
-		} catch (NotFoundException $e) {
146
-			// File does not already exists
147
-			$file = $rootFolder->newFile($this->fileName);
148
-		}
149
-
150
-		// Refresh the file content
151
-		try {
152
-			$responseJson = $this->fetch($ETag, $content);
153
-			$file->putContent(json_encode($responseJson));
154
-			return json_decode($file->getContent(), true)['data'];
155
-		} catch (\Exception $e) {
156
-			return [];
157
-		}
158
-	}
159
-
160
-	/**
161
-	 * Get the currently Nextcloud version
162
-	 * @return string
163
-	 */
164
-	protected function getVersion() {
165
-		if ($this->version === null) {
166
-			$this->version = $this->config->getSystemValue('version', '0.0.0');
167
-		}
168
-		return $this->version;
169
-	}
170
-
171
-	/**
172
-	 * Set the current Nextcloud version
173
-	 * @param string $version
174
-	 */
175
-	public function setVersion($version) {
176
-		$this->version = $version;
177
-	}
32
+    const INVALIDATE_AFTER_SECONDS = 300;
33
+
34
+    /** @var IAppData */
35
+    protected $appData;
36
+    /** @var IClientService */
37
+    protected $clientService;
38
+    /** @var ITimeFactory */
39
+    protected $timeFactory;
40
+    /** @var IConfig */
41
+    protected $config;
42
+    /** @var string */
43
+    protected $fileName;
44
+    /** @var string */
45
+    protected $endpointUrl;
46
+    /** @var string */
47
+    protected $version;
48
+
49
+    /**
50
+     * @param IAppData $appData
51
+     * @param IClientService $clientService
52
+     * @param ITimeFactory $timeFactory
53
+     * @param IConfig $config
54
+     */
55
+    public function __construct(IAppData $appData,
56
+                                IClientService $clientService,
57
+                                ITimeFactory $timeFactory,
58
+                                IConfig $config) {
59
+        $this->appData = $appData;
60
+        $this->clientService = $clientService;
61
+        $this->timeFactory = $timeFactory;
62
+        $this->config = $config;
63
+    }
64
+
65
+    /**
66
+     * Fetches the response from the server
67
+     *
68
+     * @param string $ETag
69
+     * @param string $content
70
+     *
71
+     * @return array
72
+     */
73
+    protected function fetch($ETag, $content) {
74
+        $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
75
+
76
+        if (!$appstoreenabled) {
77
+            return [];
78
+        }
79
+
80
+        $options = [];
81
+
82
+        if ($ETag !== '') {
83
+            $options['headers'] = [
84
+                'If-None-Match' => $ETag,
85
+            ];
86
+        }
87
+
88
+        $client = $this->clientService->newClient();
89
+        $response = $client->get($this->endpointUrl, $options);
90
+
91
+        $responseJson = [];
92
+        if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) {
93
+            $responseJson['data'] = json_decode($content, true);
94
+        } else {
95
+            $responseJson['data'] = json_decode($response->getBody(), true);
96
+            $ETag = $response->getHeader('ETag');
97
+        }
98
+
99
+        $responseJson['timestamp'] = $this->timeFactory->getTime();
100
+        $responseJson['ncversion'] = $this->getVersion();
101
+        if ($ETag !== '') {
102
+            $responseJson['ETag'] = $ETag;
103
+        }
104
+
105
+        return $responseJson;
106
+    }
107
+
108
+    /**
109
+     * Returns the array with the categories on the appstore server
110
+     *
111
+     * @return array
112
+     */
113
+    public function get() {
114
+        $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
115
+
116
+        if (!$appstoreenabled) {
117
+            return [];
118
+        }
119
+
120
+        $rootFolder = $this->appData->getFolder('/');
121
+
122
+        $ETag = '';
123
+        $content = '';
124
+
125
+        try {
126
+            // File does already exists
127
+            $file = $rootFolder->getFile($this->fileName);
128
+            $jsonBlob = json_decode($file->getContent(), true);
129
+            if (is_array($jsonBlob)) {
130
+
131
+                // No caching when the version has been updated
132
+                if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
133
+
134
+                    // If the timestamp is older than 300 seconds request the files new
135
+                    if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
136
+                        return $jsonBlob['data'];
137
+                    }
138
+
139
+                    if (isset($jsonBlob['ETag'])) {
140
+                        $ETag = $jsonBlob['ETag'];
141
+                        $content = json_encode($jsonBlob['data']);
142
+                    }
143
+                }
144
+            }
145
+        } catch (NotFoundException $e) {
146
+            // File does not already exists
147
+            $file = $rootFolder->newFile($this->fileName);
148
+        }
149
+
150
+        // Refresh the file content
151
+        try {
152
+            $responseJson = $this->fetch($ETag, $content);
153
+            $file->putContent(json_encode($responseJson));
154
+            return json_decode($file->getContent(), true)['data'];
155
+        } catch (\Exception $e) {
156
+            return [];
157
+        }
158
+    }
159
+
160
+    /**
161
+     * Get the currently Nextcloud version
162
+     * @return string
163
+     */
164
+    protected function getVersion() {
165
+        if ($this->version === null) {
166
+            $this->version = $this->config->getSystemValue('version', '0.0.0');
167
+        }
168
+        return $this->version;
169
+    }
170
+
171
+    /**
172
+     * Set the current Nextcloud version
173
+     * @param string $version
174
+     */
175
+    public function setVersion($version) {
176
+        $this->version = $version;
177
+    }
178 178
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
 				if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
133 133
 
134 134
 					// If the timestamp is older than 300 seconds request the files new
135
-					if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
135
+					if ((int) $jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
136 136
 						return $jsonBlob['data'];
137 137
 					}
138 138
 
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +1645 added lines, -1645 removed lines patch added patch discarded remove patch
@@ -126,1654 +126,1654 @@
 block discarded – undo
126 126
  * TODO: hookup all manager classes
127 127
  */
128 128
 class Server extends ServerContainer implements IServerContainer {
129
-	/** @var string */
130
-	private $webRoot;
131
-
132
-	/**
133
-	 * @param string $webRoot
134
-	 * @param \OC\Config $config
135
-	 */
136
-	public function __construct($webRoot, \OC\Config $config) {
137
-		parent::__construct();
138
-		$this->webRoot = $webRoot;
139
-
140
-		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
141
-			return $c;
142
-		});
143
-
144
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
145
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
146
-
147
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
148
-
149
-
150
-
151
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
152
-			return new PreviewManager(
153
-				$c->getConfig(),
154
-				$c->getRootFolder(),
155
-				$c->getAppDataDir('preview'),
156
-				$c->getEventDispatcher(),
157
-				$c->getSession()->get('user_id')
158
-			);
159
-		});
160
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
161
-
162
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
163
-			return new \OC\Preview\Watcher(
164
-				$c->getAppDataDir('preview')
165
-			);
166
-		});
167
-
168
-		$this->registerService('EncryptionManager', function (Server $c) {
169
-			$view = new View();
170
-			$util = new Encryption\Util(
171
-				$view,
172
-				$c->getUserManager(),
173
-				$c->getGroupManager(),
174
-				$c->getConfig()
175
-			);
176
-			return new Encryption\Manager(
177
-				$c->getConfig(),
178
-				$c->getLogger(),
179
-				$c->getL10N('core'),
180
-				new View(),
181
-				$util,
182
-				new ArrayCache()
183
-			);
184
-		});
185
-
186
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
187
-			$util = new Encryption\Util(
188
-				new View(),
189
-				$c->getUserManager(),
190
-				$c->getGroupManager(),
191
-				$c->getConfig()
192
-			);
193
-			return new Encryption\File(
194
-				$util,
195
-				$c->getRootFolder(),
196
-				$c->getShareManager()
197
-			);
198
-		});
199
-
200
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
201
-			$view = new View();
202
-			$util = new Encryption\Util(
203
-				$view,
204
-				$c->getUserManager(),
205
-				$c->getGroupManager(),
206
-				$c->getConfig()
207
-			);
208
-
209
-			return new Encryption\Keys\Storage($view, $util);
210
-		});
211
-		$this->registerService('TagMapper', function (Server $c) {
212
-			return new TagMapper($c->getDatabaseConnection());
213
-		});
214
-
215
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
216
-			$tagMapper = $c->query('TagMapper');
217
-			return new TagManager($tagMapper, $c->getUserSession());
218
-		});
219
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
220
-
221
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
222
-			$config = $c->getConfig();
223
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
224
-			/** @var \OC\SystemTag\ManagerFactory $factory */
225
-			$factory = new $factoryClass($this);
226
-			return $factory;
227
-		});
228
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
229
-			return $c->query('SystemTagManagerFactory')->getManager();
230
-		});
231
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
232
-
233
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
234
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
235
-		});
236
-		$this->registerService('RootFolder', function (Server $c) {
237
-			$manager = \OC\Files\Filesystem::getMountManager(null);
238
-			$view = new View();
239
-			$root = new Root(
240
-				$manager,
241
-				$view,
242
-				null,
243
-				$c->getUserMountCache(),
244
-				$this->getLogger(),
245
-				$this->getUserManager()
246
-			);
247
-			$connector = new HookConnector($root, $view);
248
-			$connector->viewToNode();
249
-
250
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
251
-			$previewConnector->connectWatcher();
252
-
253
-			return $root;
254
-		});
255
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
256
-
257
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
258
-			return new LazyRoot(function() use ($c) {
259
-				return $c->query('RootFolder');
260
-			});
261
-		});
262
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
263
-
264
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
265
-			$config = $c->getConfig();
266
-			return new \OC\User\Manager($config);
267
-		});
268
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
269
-
270
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
271
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
272
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
273
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
274
-			});
275
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
276
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
277
-			});
278
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
279
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
280
-			});
281
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
282
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
283
-			});
284
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
285
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
286
-			});
287
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
289
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
-			});
292
-			return $groupManager;
293
-		});
294
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
295
-
296
-		$this->registerService(Store::class, function(Server $c) {
297
-			$session = $c->getSession();
298
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
299
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
300
-			} else {
301
-				$tokenProvider = null;
302
-			}
303
-			$logger = $c->getLogger();
304
-			return new Store($session, $logger, $tokenProvider);
305
-		});
306
-		$this->registerAlias(IStore::class, Store::class);
307
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
308
-			$dbConnection = $c->getDatabaseConnection();
309
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
310
-		});
311
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
312
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
313
-			$crypto = $c->getCrypto();
314
-			$config = $c->getConfig();
315
-			$logger = $c->getLogger();
316
-			$timeFactory = new TimeFactory();
317
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
318
-		});
319
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
320
-
321
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
322
-			$manager = $c->getUserManager();
323
-			$session = new \OC\Session\Memory('');
324
-			$timeFactory = new TimeFactory();
325
-			// Token providers might require a working database. This code
326
-			// might however be called when ownCloud is not yet setup.
327
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
328
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
329
-			} else {
330
-				$defaultTokenProvider = null;
331
-			}
332
-
333
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
334
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
335
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
336
-			});
337
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
338
-				/** @var $user \OC\User\User */
339
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
340
-			});
341
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
342
-				/** @var $user \OC\User\User */
343
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
344
-			});
345
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
346
-				/** @var $user \OC\User\User */
347
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
348
-			});
349
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
350
-				/** @var $user \OC\User\User */
351
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
352
-			});
353
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
354
-				/** @var $user \OC\User\User */
355
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
356
-			});
357
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
358
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
359
-			});
360
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
361
-				/** @var $user \OC\User\User */
362
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
363
-			});
364
-			$userSession->listen('\OC\User', 'logout', function () {
365
-				\OC_Hook::emit('OC_User', 'logout', array());
366
-			});
367
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
368
-				/** @var $user \OC\User\User */
369
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
370
-			});
371
-			return $userSession;
372
-		});
373
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
374
-
375
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
376
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
377
-		});
378
-
379
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
380
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
381
-
382
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
383
-			return new \OC\AllConfig(
384
-				$c->getSystemConfig()
385
-			);
386
-		});
387
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
388
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
389
-
390
-		$this->registerService('SystemConfig', function ($c) use ($config) {
391
-			return new \OC\SystemConfig($config);
392
-		});
393
-
394
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
395
-			return new \OC\AppConfig($c->getDatabaseConnection());
396
-		});
397
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
398
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
399
-
400
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
401
-			return new \OC\L10N\Factory(
402
-				$c->getConfig(),
403
-				$c->getRequest(),
404
-				$c->getUserSession(),
405
-				\OC::$SERVERROOT
406
-			);
407
-		});
408
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
409
-
410
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
411
-			$config = $c->getConfig();
412
-			$cacheFactory = $c->getMemCacheFactory();
413
-			return new \OC\URLGenerator(
414
-				$config,
415
-				$cacheFactory
416
-			);
417
-		});
418
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
419
-
420
-		$this->registerService('AppHelper', function ($c) {
421
-			return new \OC\AppHelper();
422
-		});
423
-		$this->registerService(AppFetcher::class, function ($c) {
424
-			return new AppFetcher(
425
-				$this->getAppDataDir('appstore'),
426
-				$this->getHTTPClientService(),
427
-				$this->query(TimeFactory::class),
428
-				$this->getConfig()
429
-			);
430
-		});
431
-		$this->registerAlias('AppFetcher', AppFetcher::class);
432
-
433
-		$this->registerService('CategoryFetcher', function ($c) {
434
-			return new CategoryFetcher(
435
-				$this->getAppDataDir('appstore'),
436
-				$this->getHTTPClientService(),
437
-				$this->query(TimeFactory::class),
438
-				$this->getConfig()
439
-			);
440
-		});
441
-
442
-		$this->registerService(\OCP\ICache::class, function ($c) {
443
-			return new Cache\File();
444
-		});
445
-		$this->registerAlias('UserCache', \OCP\ICache::class);
446
-
447
-		$this->registerService(Factory::class, function (Server $c) {
448
-			$config = $c->getConfig();
449
-
450
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
-				$v = \OC_App::getAppVersions();
452
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
453
-				$version = implode(',', $v);
454
-				$instanceId = \OC_Util::getInstanceId();
455
-				$path = \OC::$SERVERROOT;
456
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
457
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
-					$config->getSystemValue('memcache.local', null),
459
-					$config->getSystemValue('memcache.distributed', null),
460
-					$config->getSystemValue('memcache.locking', null)
461
-				);
462
-			}
463
-
464
-			return new \OC\Memcache\Factory('', $c->getLogger(),
465
-				'\\OC\\Memcache\\ArrayCache',
466
-				'\\OC\\Memcache\\ArrayCache',
467
-				'\\OC\\Memcache\\ArrayCache'
468
-			);
469
-		});
470
-		$this->registerAlias('MemCacheFactory', Factory::class);
471
-		$this->registerAlias(ICacheFactory::class, Factory::class);
472
-
473
-		$this->registerService('RedisFactory', function (Server $c) {
474
-			$systemConfig = $c->getSystemConfig();
475
-			return new RedisFactory($systemConfig);
476
-		});
477
-
478
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
479
-			return new \OC\Activity\Manager(
480
-				$c->getRequest(),
481
-				$c->getUserSession(),
482
-				$c->getConfig(),
483
-				$c->query(IValidator::class)
484
-			);
485
-		});
486
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
487
-
488
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
489
-			return new \OC\Activity\EventMerger(
490
-				$c->getL10N('lib')
491
-			);
492
-		});
493
-		$this->registerAlias(IValidator::class, Validator::class);
494
-
495
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
496
-			return new AvatarManager(
497
-				$c->getUserManager(),
498
-				$c->getAppDataDir('avatar'),
499
-				$c->getL10N('lib'),
500
-				$c->getLogger(),
501
-				$c->getConfig()
502
-			);
503
-		});
504
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
505
-
506
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
507
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
508
-			$logger = Log::getLogClass($logType);
509
-			call_user_func(array($logger, 'init'));
510
-
511
-			return new Log($logger);
512
-		});
513
-		$this->registerAlias('Logger', \OCP\ILogger::class);
514
-
515
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
516
-			$config = $c->getConfig();
517
-			return new \OC\BackgroundJob\JobList(
518
-				$c->getDatabaseConnection(),
519
-				$config,
520
-				new TimeFactory()
521
-			);
522
-		});
523
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
524
-
525
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
526
-			$cacheFactory = $c->getMemCacheFactory();
527
-			$logger = $c->getLogger();
528
-			if ($cacheFactory->isAvailable()) {
529
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
530
-			} else {
531
-				$router = new \OC\Route\Router($logger);
532
-			}
533
-			return $router;
534
-		});
535
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
536
-
537
-		$this->registerService(\OCP\ISearch::class, function ($c) {
538
-			return new Search();
539
-		});
540
-		$this->registerAlias('Search', \OCP\ISearch::class);
541
-
542
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
543
-			return new \OC\Security\RateLimiting\Limiter(
544
-				$this->getUserSession(),
545
-				$this->getRequest(),
546
-				new \OC\AppFramework\Utility\TimeFactory(),
547
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
548
-			);
549
-		});
550
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
551
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
552
-				$this->getMemCacheFactory(),
553
-				new \OC\AppFramework\Utility\TimeFactory()
554
-			);
555
-		});
556
-
557
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
558
-			return new SecureRandom();
559
-		});
560
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
561
-
562
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
563
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
564
-		});
565
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
566
-
567
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
568
-			return new Hasher($c->getConfig());
569
-		});
570
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
571
-
572
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
573
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
574
-		});
575
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
576
-
577
-		$this->registerService(IDBConnection::class, function (Server $c) {
578
-			$systemConfig = $c->getSystemConfig();
579
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
580
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
581
-			if (!$factory->isValidType($type)) {
582
-				throw new \OC\DatabaseException('Invalid database type');
583
-			}
584
-			$connectionParams = $factory->createConnectionParams();
585
-			$connection = $factory->getConnection($type, $connectionParams);
586
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
587
-			return $connection;
588
-		});
589
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
590
-
591
-		$this->registerService('HTTPHelper', function (Server $c) {
592
-			$config = $c->getConfig();
593
-			return new HTTPHelper(
594
-				$config,
595
-				$c->getHTTPClientService()
596
-			);
597
-		});
598
-
599
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
600
-			$user = \OC_User::getUser();
601
-			$uid = $user ? $user : null;
602
-			return new ClientService(
603
-				$c->getConfig(),
604
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
605
-			);
606
-		});
607
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
608
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
609
-			$eventLogger = new EventLogger();
610
-			if ($c->getSystemConfig()->getValue('debug', false)) {
611
-				// In debug mode, module is being activated by default
612
-				$eventLogger->activate();
613
-			}
614
-			return $eventLogger;
615
-		});
616
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
617
-
618
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
619
-			$queryLogger = new QueryLogger();
620
-			if ($c->getSystemConfig()->getValue('debug', false)) {
621
-				// In debug mode, module is being activated by default
622
-				$queryLogger->activate();
623
-			}
624
-			return $queryLogger;
625
-		});
626
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
627
-
628
-		$this->registerService(TempManager::class, function (Server $c) {
629
-			return new TempManager(
630
-				$c->getLogger(),
631
-				$c->getConfig()
632
-			);
633
-		});
634
-		$this->registerAlias('TempManager', TempManager::class);
635
-		$this->registerAlias(ITempManager::class, TempManager::class);
636
-
637
-		$this->registerService(AppManager::class, function (Server $c) {
638
-			return new \OC\App\AppManager(
639
-				$c->getUserSession(),
640
-				$c->getAppConfig(),
641
-				$c->getGroupManager(),
642
-				$c->getMemCacheFactory(),
643
-				$c->getEventDispatcher()
644
-			);
645
-		});
646
-		$this->registerAlias('AppManager', AppManager::class);
647
-		$this->registerAlias(IAppManager::class, AppManager::class);
648
-
649
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
650
-			return new DateTimeZone(
651
-				$c->getConfig(),
652
-				$c->getSession()
653
-			);
654
-		});
655
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
656
-
657
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
658
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
659
-
660
-			return new DateTimeFormatter(
661
-				$c->getDateTimeZone()->getTimeZone(),
662
-				$c->getL10N('lib', $language)
663
-			);
664
-		});
665
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
666
-
667
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
668
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
669
-			$listener = new UserMountCacheListener($mountCache);
670
-			$listener->listen($c->getUserManager());
671
-			return $mountCache;
672
-		});
673
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
674
-
675
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
676
-			$loader = \OC\Files\Filesystem::getLoader();
677
-			$mountCache = $c->query('UserMountCache');
678
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
679
-
680
-			// builtin providers
681
-
682
-			$config = $c->getConfig();
683
-			$manager->registerProvider(new CacheMountProvider($config));
684
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
685
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
686
-
687
-			return $manager;
688
-		});
689
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
690
-
691
-		$this->registerService('IniWrapper', function ($c) {
692
-			return new IniGetWrapper();
693
-		});
694
-		$this->registerService('AsyncCommandBus', function (Server $c) {
695
-			$jobList = $c->getJobList();
696
-			return new AsyncBus($jobList);
697
-		});
698
-		$this->registerService('TrustedDomainHelper', function ($c) {
699
-			return new TrustedDomainHelper($this->getConfig());
700
-		});
701
-		$this->registerService('Throttler', function(Server $c) {
702
-			return new Throttler(
703
-				$c->getDatabaseConnection(),
704
-				new TimeFactory(),
705
-				$c->getLogger(),
706
-				$c->getConfig()
707
-			);
708
-		});
709
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
710
-			// IConfig and IAppManager requires a working database. This code
711
-			// might however be called when ownCloud is not yet setup.
712
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
713
-				$config = $c->getConfig();
714
-				$appManager = $c->getAppManager();
715
-			} else {
716
-				$config = null;
717
-				$appManager = null;
718
-			}
719
-
720
-			return new Checker(
721
-					new EnvironmentHelper(),
722
-					new FileAccessHelper(),
723
-					new AppLocator(),
724
-					$config,
725
-					$c->getMemCacheFactory(),
726
-					$appManager,
727
-					$c->getTempManager()
728
-			);
729
-		});
730
-		$this->registerService(\OCP\IRequest::class, function ($c) {
731
-			if (isset($this['urlParams'])) {
732
-				$urlParams = $this['urlParams'];
733
-			} else {
734
-				$urlParams = [];
735
-			}
736
-
737
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
738
-				&& in_array('fakeinput', stream_get_wrappers())
739
-			) {
740
-				$stream = 'fakeinput://data';
741
-			} else {
742
-				$stream = 'php://input';
743
-			}
744
-
745
-			return new Request(
746
-				[
747
-					'get' => $_GET,
748
-					'post' => $_POST,
749
-					'files' => $_FILES,
750
-					'server' => $_SERVER,
751
-					'env' => $_ENV,
752
-					'cookies' => $_COOKIE,
753
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
754
-						? $_SERVER['REQUEST_METHOD']
755
-						: null,
756
-					'urlParams' => $urlParams,
757
-				],
758
-				$this->getSecureRandom(),
759
-				$this->getConfig(),
760
-				$this->getCsrfTokenManager(),
761
-				$stream
762
-			);
763
-		});
764
-		$this->registerAlias('Request', \OCP\IRequest::class);
765
-
766
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
767
-			return new Mailer(
768
-				$c->getConfig(),
769
-				$c->getLogger(),
770
-				$c->query(Defaults::class),
771
-				$c->getURLGenerator(),
772
-				$c->getL10N('lib')
773
-			);
774
-		});
775
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
776
-
777
-		$this->registerService('LDAPProvider', function(Server $c) {
778
-			$config = $c->getConfig();
779
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
780
-			if(is_null($factoryClass)) {
781
-				throw new \Exception('ldapProviderFactory not set');
782
-			}
783
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
784
-			$factory = new $factoryClass($this);
785
-			return $factory->getLDAPProvider();
786
-		});
787
-		$this->registerService('LockingProvider', function (Server $c) {
788
-			$ini = $c->getIniWrapper();
789
-			$config = $c->getConfig();
790
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
791
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
792
-				/** @var \OC\Memcache\Factory $memcacheFactory */
793
-				$memcacheFactory = $c->getMemCacheFactory();
794
-				$memcache = $memcacheFactory->createLocking('lock');
795
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
796
-					return new MemcacheLockingProvider($memcache, $ttl);
797
-				}
798
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
799
-			}
800
-			return new NoopLockingProvider();
801
-		});
802
-
803
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
804
-			return new \OC\Files\Mount\Manager();
805
-		});
806
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
807
-
808
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
809
-			return new \OC\Files\Type\Detection(
810
-				$c->getURLGenerator(),
811
-				\OC::$configDir,
812
-				\OC::$SERVERROOT . '/resources/config/'
813
-			);
814
-		});
815
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
816
-
817
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
818
-			return new \OC\Files\Type\Loader(
819
-				$c->getDatabaseConnection()
820
-			);
821
-		});
822
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
823
-		$this->registerService(BundleFetcher::class, function () {
824
-			return new BundleFetcher($this->getL10N('lib'));
825
-		});
826
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
827
-			return new Manager(
828
-				$c->query(IValidator::class)
829
-			);
830
-		});
831
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
832
-
833
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
834
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
835
-			$manager->registerCapability(function () use ($c) {
836
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
837
-			});
838
-			return $manager;
839
-		});
840
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
841
-
842
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
843
-			$config = $c->getConfig();
844
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
845
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
846
-			$factory = new $factoryClass($this);
847
-			return $factory->getManager();
848
-		});
849
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
850
-
851
-		$this->registerService('ThemingDefaults', function(Server $c) {
852
-			/*
129
+    /** @var string */
130
+    private $webRoot;
131
+
132
+    /**
133
+     * @param string $webRoot
134
+     * @param \OC\Config $config
135
+     */
136
+    public function __construct($webRoot, \OC\Config $config) {
137
+        parent::__construct();
138
+        $this->webRoot = $webRoot;
139
+
140
+        $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
141
+            return $c;
142
+        });
143
+
144
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
145
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
146
+
147
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
148
+
149
+
150
+
151
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
152
+            return new PreviewManager(
153
+                $c->getConfig(),
154
+                $c->getRootFolder(),
155
+                $c->getAppDataDir('preview'),
156
+                $c->getEventDispatcher(),
157
+                $c->getSession()->get('user_id')
158
+            );
159
+        });
160
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
161
+
162
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
163
+            return new \OC\Preview\Watcher(
164
+                $c->getAppDataDir('preview')
165
+            );
166
+        });
167
+
168
+        $this->registerService('EncryptionManager', function (Server $c) {
169
+            $view = new View();
170
+            $util = new Encryption\Util(
171
+                $view,
172
+                $c->getUserManager(),
173
+                $c->getGroupManager(),
174
+                $c->getConfig()
175
+            );
176
+            return new Encryption\Manager(
177
+                $c->getConfig(),
178
+                $c->getLogger(),
179
+                $c->getL10N('core'),
180
+                new View(),
181
+                $util,
182
+                new ArrayCache()
183
+            );
184
+        });
185
+
186
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
187
+            $util = new Encryption\Util(
188
+                new View(),
189
+                $c->getUserManager(),
190
+                $c->getGroupManager(),
191
+                $c->getConfig()
192
+            );
193
+            return new Encryption\File(
194
+                $util,
195
+                $c->getRootFolder(),
196
+                $c->getShareManager()
197
+            );
198
+        });
199
+
200
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
201
+            $view = new View();
202
+            $util = new Encryption\Util(
203
+                $view,
204
+                $c->getUserManager(),
205
+                $c->getGroupManager(),
206
+                $c->getConfig()
207
+            );
208
+
209
+            return new Encryption\Keys\Storage($view, $util);
210
+        });
211
+        $this->registerService('TagMapper', function (Server $c) {
212
+            return new TagMapper($c->getDatabaseConnection());
213
+        });
214
+
215
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
216
+            $tagMapper = $c->query('TagMapper');
217
+            return new TagManager($tagMapper, $c->getUserSession());
218
+        });
219
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
220
+
221
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
222
+            $config = $c->getConfig();
223
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
224
+            /** @var \OC\SystemTag\ManagerFactory $factory */
225
+            $factory = new $factoryClass($this);
226
+            return $factory;
227
+        });
228
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
229
+            return $c->query('SystemTagManagerFactory')->getManager();
230
+        });
231
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
232
+
233
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
234
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
235
+        });
236
+        $this->registerService('RootFolder', function (Server $c) {
237
+            $manager = \OC\Files\Filesystem::getMountManager(null);
238
+            $view = new View();
239
+            $root = new Root(
240
+                $manager,
241
+                $view,
242
+                null,
243
+                $c->getUserMountCache(),
244
+                $this->getLogger(),
245
+                $this->getUserManager()
246
+            );
247
+            $connector = new HookConnector($root, $view);
248
+            $connector->viewToNode();
249
+
250
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
251
+            $previewConnector->connectWatcher();
252
+
253
+            return $root;
254
+        });
255
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
256
+
257
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
258
+            return new LazyRoot(function() use ($c) {
259
+                return $c->query('RootFolder');
260
+            });
261
+        });
262
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
263
+
264
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
265
+            $config = $c->getConfig();
266
+            return new \OC\User\Manager($config);
267
+        });
268
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
269
+
270
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
271
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
272
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
273
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
274
+            });
275
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
276
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
277
+            });
278
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
279
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
280
+            });
281
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
282
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
283
+            });
284
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
285
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
286
+            });
287
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
289
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
+            });
292
+            return $groupManager;
293
+        });
294
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
295
+
296
+        $this->registerService(Store::class, function(Server $c) {
297
+            $session = $c->getSession();
298
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
299
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
300
+            } else {
301
+                $tokenProvider = null;
302
+            }
303
+            $logger = $c->getLogger();
304
+            return new Store($session, $logger, $tokenProvider);
305
+        });
306
+        $this->registerAlias(IStore::class, Store::class);
307
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
308
+            $dbConnection = $c->getDatabaseConnection();
309
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
310
+        });
311
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
312
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
313
+            $crypto = $c->getCrypto();
314
+            $config = $c->getConfig();
315
+            $logger = $c->getLogger();
316
+            $timeFactory = new TimeFactory();
317
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
318
+        });
319
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
320
+
321
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
322
+            $manager = $c->getUserManager();
323
+            $session = new \OC\Session\Memory('');
324
+            $timeFactory = new TimeFactory();
325
+            // Token providers might require a working database. This code
326
+            // might however be called when ownCloud is not yet setup.
327
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
328
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
329
+            } else {
330
+                $defaultTokenProvider = null;
331
+            }
332
+
333
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
334
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
335
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
336
+            });
337
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
338
+                /** @var $user \OC\User\User */
339
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
340
+            });
341
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
342
+                /** @var $user \OC\User\User */
343
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
344
+            });
345
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
346
+                /** @var $user \OC\User\User */
347
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
348
+            });
349
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
350
+                /** @var $user \OC\User\User */
351
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
352
+            });
353
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
354
+                /** @var $user \OC\User\User */
355
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
356
+            });
357
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
358
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
359
+            });
360
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
361
+                /** @var $user \OC\User\User */
362
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
363
+            });
364
+            $userSession->listen('\OC\User', 'logout', function () {
365
+                \OC_Hook::emit('OC_User', 'logout', array());
366
+            });
367
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
368
+                /** @var $user \OC\User\User */
369
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
370
+            });
371
+            return $userSession;
372
+        });
373
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
374
+
375
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
376
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
377
+        });
378
+
379
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
380
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
381
+
382
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
383
+            return new \OC\AllConfig(
384
+                $c->getSystemConfig()
385
+            );
386
+        });
387
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
388
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
389
+
390
+        $this->registerService('SystemConfig', function ($c) use ($config) {
391
+            return new \OC\SystemConfig($config);
392
+        });
393
+
394
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
395
+            return new \OC\AppConfig($c->getDatabaseConnection());
396
+        });
397
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
398
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
399
+
400
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
401
+            return new \OC\L10N\Factory(
402
+                $c->getConfig(),
403
+                $c->getRequest(),
404
+                $c->getUserSession(),
405
+                \OC::$SERVERROOT
406
+            );
407
+        });
408
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
409
+
410
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
411
+            $config = $c->getConfig();
412
+            $cacheFactory = $c->getMemCacheFactory();
413
+            return new \OC\URLGenerator(
414
+                $config,
415
+                $cacheFactory
416
+            );
417
+        });
418
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
419
+
420
+        $this->registerService('AppHelper', function ($c) {
421
+            return new \OC\AppHelper();
422
+        });
423
+        $this->registerService(AppFetcher::class, function ($c) {
424
+            return new AppFetcher(
425
+                $this->getAppDataDir('appstore'),
426
+                $this->getHTTPClientService(),
427
+                $this->query(TimeFactory::class),
428
+                $this->getConfig()
429
+            );
430
+        });
431
+        $this->registerAlias('AppFetcher', AppFetcher::class);
432
+
433
+        $this->registerService('CategoryFetcher', function ($c) {
434
+            return new CategoryFetcher(
435
+                $this->getAppDataDir('appstore'),
436
+                $this->getHTTPClientService(),
437
+                $this->query(TimeFactory::class),
438
+                $this->getConfig()
439
+            );
440
+        });
441
+
442
+        $this->registerService(\OCP\ICache::class, function ($c) {
443
+            return new Cache\File();
444
+        });
445
+        $this->registerAlias('UserCache', \OCP\ICache::class);
446
+
447
+        $this->registerService(Factory::class, function (Server $c) {
448
+            $config = $c->getConfig();
449
+
450
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
+                $v = \OC_App::getAppVersions();
452
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
453
+                $version = implode(',', $v);
454
+                $instanceId = \OC_Util::getInstanceId();
455
+                $path = \OC::$SERVERROOT;
456
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
457
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
+                    $config->getSystemValue('memcache.local', null),
459
+                    $config->getSystemValue('memcache.distributed', null),
460
+                    $config->getSystemValue('memcache.locking', null)
461
+                );
462
+            }
463
+
464
+            return new \OC\Memcache\Factory('', $c->getLogger(),
465
+                '\\OC\\Memcache\\ArrayCache',
466
+                '\\OC\\Memcache\\ArrayCache',
467
+                '\\OC\\Memcache\\ArrayCache'
468
+            );
469
+        });
470
+        $this->registerAlias('MemCacheFactory', Factory::class);
471
+        $this->registerAlias(ICacheFactory::class, Factory::class);
472
+
473
+        $this->registerService('RedisFactory', function (Server $c) {
474
+            $systemConfig = $c->getSystemConfig();
475
+            return new RedisFactory($systemConfig);
476
+        });
477
+
478
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
479
+            return new \OC\Activity\Manager(
480
+                $c->getRequest(),
481
+                $c->getUserSession(),
482
+                $c->getConfig(),
483
+                $c->query(IValidator::class)
484
+            );
485
+        });
486
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
487
+
488
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
489
+            return new \OC\Activity\EventMerger(
490
+                $c->getL10N('lib')
491
+            );
492
+        });
493
+        $this->registerAlias(IValidator::class, Validator::class);
494
+
495
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
496
+            return new AvatarManager(
497
+                $c->getUserManager(),
498
+                $c->getAppDataDir('avatar'),
499
+                $c->getL10N('lib'),
500
+                $c->getLogger(),
501
+                $c->getConfig()
502
+            );
503
+        });
504
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
505
+
506
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
507
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
508
+            $logger = Log::getLogClass($logType);
509
+            call_user_func(array($logger, 'init'));
510
+
511
+            return new Log($logger);
512
+        });
513
+        $this->registerAlias('Logger', \OCP\ILogger::class);
514
+
515
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
516
+            $config = $c->getConfig();
517
+            return new \OC\BackgroundJob\JobList(
518
+                $c->getDatabaseConnection(),
519
+                $config,
520
+                new TimeFactory()
521
+            );
522
+        });
523
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
524
+
525
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
526
+            $cacheFactory = $c->getMemCacheFactory();
527
+            $logger = $c->getLogger();
528
+            if ($cacheFactory->isAvailable()) {
529
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
530
+            } else {
531
+                $router = new \OC\Route\Router($logger);
532
+            }
533
+            return $router;
534
+        });
535
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
536
+
537
+        $this->registerService(\OCP\ISearch::class, function ($c) {
538
+            return new Search();
539
+        });
540
+        $this->registerAlias('Search', \OCP\ISearch::class);
541
+
542
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
543
+            return new \OC\Security\RateLimiting\Limiter(
544
+                $this->getUserSession(),
545
+                $this->getRequest(),
546
+                new \OC\AppFramework\Utility\TimeFactory(),
547
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
548
+            );
549
+        });
550
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
551
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
552
+                $this->getMemCacheFactory(),
553
+                new \OC\AppFramework\Utility\TimeFactory()
554
+            );
555
+        });
556
+
557
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
558
+            return new SecureRandom();
559
+        });
560
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
561
+
562
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
563
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
564
+        });
565
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
566
+
567
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
568
+            return new Hasher($c->getConfig());
569
+        });
570
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
571
+
572
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
573
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
574
+        });
575
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
576
+
577
+        $this->registerService(IDBConnection::class, function (Server $c) {
578
+            $systemConfig = $c->getSystemConfig();
579
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
580
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
581
+            if (!$factory->isValidType($type)) {
582
+                throw new \OC\DatabaseException('Invalid database type');
583
+            }
584
+            $connectionParams = $factory->createConnectionParams();
585
+            $connection = $factory->getConnection($type, $connectionParams);
586
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
587
+            return $connection;
588
+        });
589
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
590
+
591
+        $this->registerService('HTTPHelper', function (Server $c) {
592
+            $config = $c->getConfig();
593
+            return new HTTPHelper(
594
+                $config,
595
+                $c->getHTTPClientService()
596
+            );
597
+        });
598
+
599
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
600
+            $user = \OC_User::getUser();
601
+            $uid = $user ? $user : null;
602
+            return new ClientService(
603
+                $c->getConfig(),
604
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
605
+            );
606
+        });
607
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
608
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
609
+            $eventLogger = new EventLogger();
610
+            if ($c->getSystemConfig()->getValue('debug', false)) {
611
+                // In debug mode, module is being activated by default
612
+                $eventLogger->activate();
613
+            }
614
+            return $eventLogger;
615
+        });
616
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
617
+
618
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
619
+            $queryLogger = new QueryLogger();
620
+            if ($c->getSystemConfig()->getValue('debug', false)) {
621
+                // In debug mode, module is being activated by default
622
+                $queryLogger->activate();
623
+            }
624
+            return $queryLogger;
625
+        });
626
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
627
+
628
+        $this->registerService(TempManager::class, function (Server $c) {
629
+            return new TempManager(
630
+                $c->getLogger(),
631
+                $c->getConfig()
632
+            );
633
+        });
634
+        $this->registerAlias('TempManager', TempManager::class);
635
+        $this->registerAlias(ITempManager::class, TempManager::class);
636
+
637
+        $this->registerService(AppManager::class, function (Server $c) {
638
+            return new \OC\App\AppManager(
639
+                $c->getUserSession(),
640
+                $c->getAppConfig(),
641
+                $c->getGroupManager(),
642
+                $c->getMemCacheFactory(),
643
+                $c->getEventDispatcher()
644
+            );
645
+        });
646
+        $this->registerAlias('AppManager', AppManager::class);
647
+        $this->registerAlias(IAppManager::class, AppManager::class);
648
+
649
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
650
+            return new DateTimeZone(
651
+                $c->getConfig(),
652
+                $c->getSession()
653
+            );
654
+        });
655
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
656
+
657
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
658
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
659
+
660
+            return new DateTimeFormatter(
661
+                $c->getDateTimeZone()->getTimeZone(),
662
+                $c->getL10N('lib', $language)
663
+            );
664
+        });
665
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
666
+
667
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
668
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
669
+            $listener = new UserMountCacheListener($mountCache);
670
+            $listener->listen($c->getUserManager());
671
+            return $mountCache;
672
+        });
673
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
674
+
675
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
676
+            $loader = \OC\Files\Filesystem::getLoader();
677
+            $mountCache = $c->query('UserMountCache');
678
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
679
+
680
+            // builtin providers
681
+
682
+            $config = $c->getConfig();
683
+            $manager->registerProvider(new CacheMountProvider($config));
684
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
685
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
686
+
687
+            return $manager;
688
+        });
689
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
690
+
691
+        $this->registerService('IniWrapper', function ($c) {
692
+            return new IniGetWrapper();
693
+        });
694
+        $this->registerService('AsyncCommandBus', function (Server $c) {
695
+            $jobList = $c->getJobList();
696
+            return new AsyncBus($jobList);
697
+        });
698
+        $this->registerService('TrustedDomainHelper', function ($c) {
699
+            return new TrustedDomainHelper($this->getConfig());
700
+        });
701
+        $this->registerService('Throttler', function(Server $c) {
702
+            return new Throttler(
703
+                $c->getDatabaseConnection(),
704
+                new TimeFactory(),
705
+                $c->getLogger(),
706
+                $c->getConfig()
707
+            );
708
+        });
709
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
710
+            // IConfig and IAppManager requires a working database. This code
711
+            // might however be called when ownCloud is not yet setup.
712
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
713
+                $config = $c->getConfig();
714
+                $appManager = $c->getAppManager();
715
+            } else {
716
+                $config = null;
717
+                $appManager = null;
718
+            }
719
+
720
+            return new Checker(
721
+                    new EnvironmentHelper(),
722
+                    new FileAccessHelper(),
723
+                    new AppLocator(),
724
+                    $config,
725
+                    $c->getMemCacheFactory(),
726
+                    $appManager,
727
+                    $c->getTempManager()
728
+            );
729
+        });
730
+        $this->registerService(\OCP\IRequest::class, function ($c) {
731
+            if (isset($this['urlParams'])) {
732
+                $urlParams = $this['urlParams'];
733
+            } else {
734
+                $urlParams = [];
735
+            }
736
+
737
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
738
+                && in_array('fakeinput', stream_get_wrappers())
739
+            ) {
740
+                $stream = 'fakeinput://data';
741
+            } else {
742
+                $stream = 'php://input';
743
+            }
744
+
745
+            return new Request(
746
+                [
747
+                    'get' => $_GET,
748
+                    'post' => $_POST,
749
+                    'files' => $_FILES,
750
+                    'server' => $_SERVER,
751
+                    'env' => $_ENV,
752
+                    'cookies' => $_COOKIE,
753
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
754
+                        ? $_SERVER['REQUEST_METHOD']
755
+                        : null,
756
+                    'urlParams' => $urlParams,
757
+                ],
758
+                $this->getSecureRandom(),
759
+                $this->getConfig(),
760
+                $this->getCsrfTokenManager(),
761
+                $stream
762
+            );
763
+        });
764
+        $this->registerAlias('Request', \OCP\IRequest::class);
765
+
766
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
767
+            return new Mailer(
768
+                $c->getConfig(),
769
+                $c->getLogger(),
770
+                $c->query(Defaults::class),
771
+                $c->getURLGenerator(),
772
+                $c->getL10N('lib')
773
+            );
774
+        });
775
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
776
+
777
+        $this->registerService('LDAPProvider', function(Server $c) {
778
+            $config = $c->getConfig();
779
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
780
+            if(is_null($factoryClass)) {
781
+                throw new \Exception('ldapProviderFactory not set');
782
+            }
783
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
784
+            $factory = new $factoryClass($this);
785
+            return $factory->getLDAPProvider();
786
+        });
787
+        $this->registerService('LockingProvider', function (Server $c) {
788
+            $ini = $c->getIniWrapper();
789
+            $config = $c->getConfig();
790
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
791
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
792
+                /** @var \OC\Memcache\Factory $memcacheFactory */
793
+                $memcacheFactory = $c->getMemCacheFactory();
794
+                $memcache = $memcacheFactory->createLocking('lock');
795
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
796
+                    return new MemcacheLockingProvider($memcache, $ttl);
797
+                }
798
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
799
+            }
800
+            return new NoopLockingProvider();
801
+        });
802
+
803
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
804
+            return new \OC\Files\Mount\Manager();
805
+        });
806
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
807
+
808
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
809
+            return new \OC\Files\Type\Detection(
810
+                $c->getURLGenerator(),
811
+                \OC::$configDir,
812
+                \OC::$SERVERROOT . '/resources/config/'
813
+            );
814
+        });
815
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
816
+
817
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
818
+            return new \OC\Files\Type\Loader(
819
+                $c->getDatabaseConnection()
820
+            );
821
+        });
822
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
823
+        $this->registerService(BundleFetcher::class, function () {
824
+            return new BundleFetcher($this->getL10N('lib'));
825
+        });
826
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
827
+            return new Manager(
828
+                $c->query(IValidator::class)
829
+            );
830
+        });
831
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
832
+
833
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
834
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
835
+            $manager->registerCapability(function () use ($c) {
836
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
837
+            });
838
+            return $manager;
839
+        });
840
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
841
+
842
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
843
+            $config = $c->getConfig();
844
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
845
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
846
+            $factory = new $factoryClass($this);
847
+            return $factory->getManager();
848
+        });
849
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
850
+
851
+        $this->registerService('ThemingDefaults', function(Server $c) {
852
+            /*
853 853
 			 * Dark magic for autoloader.
854 854
 			 * If we do a class_exists it will try to load the class which will
855 855
 			 * make composer cache the result. Resulting in errors when enabling
856 856
 			 * the theming app.
857 857
 			 */
858
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
859
-			if (isset($prefixes['OCA\\Theming\\'])) {
860
-				$classExists = true;
861
-			} else {
862
-				$classExists = false;
863
-			}
864
-
865
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
866
-				return new ThemingDefaults(
867
-					$c->getConfig(),
868
-					$c->getL10N('theming'),
869
-					$c->getURLGenerator(),
870
-					$c->getAppDataDir('theming'),
871
-					$c->getMemCacheFactory(),
872
-					new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
873
-				);
874
-			}
875
-			return new \OC_Defaults();
876
-		});
877
-		$this->registerService(SCSSCacher::class, function(Server $c) {
878
-			/** @var Factory $cacheFactory */
879
-			$cacheFactory = $c->query(Factory::class);
880
-			return new SCSSCacher(
881
-				$c->getLogger(),
882
-				$c->query(\OC\Files\AppData\Factory::class),
883
-				$c->getURLGenerator(),
884
-				$c->getConfig(),
885
-				$c->getThemingDefaults(),
886
-				\OC::$SERVERROOT,
887
-				$cacheFactory->createLocal('SCSS')
888
-			);
889
-		});
890
-		$this->registerService(EventDispatcher::class, function () {
891
-			return new EventDispatcher();
892
-		});
893
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
894
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
895
-
896
-		$this->registerService('CryptoWrapper', function (Server $c) {
897
-			// FIXME: Instantiiated here due to cyclic dependency
898
-			$request = new Request(
899
-				[
900
-					'get' => $_GET,
901
-					'post' => $_POST,
902
-					'files' => $_FILES,
903
-					'server' => $_SERVER,
904
-					'env' => $_ENV,
905
-					'cookies' => $_COOKIE,
906
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
907
-						? $_SERVER['REQUEST_METHOD']
908
-						: null,
909
-				],
910
-				$c->getSecureRandom(),
911
-				$c->getConfig()
912
-			);
913
-
914
-			return new CryptoWrapper(
915
-				$c->getConfig(),
916
-				$c->getCrypto(),
917
-				$c->getSecureRandom(),
918
-				$request
919
-			);
920
-		});
921
-		$this->registerService('CsrfTokenManager', function (Server $c) {
922
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
923
-
924
-			return new CsrfTokenManager(
925
-				$tokenGenerator,
926
-				$c->query(SessionStorage::class)
927
-			);
928
-		});
929
-		$this->registerService(SessionStorage::class, function (Server $c) {
930
-			return new SessionStorage($c->getSession());
931
-		});
932
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
933
-			return new ContentSecurityPolicyManager();
934
-		});
935
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
936
-
937
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
938
-			return new ContentSecurityPolicyNonceManager(
939
-				$c->getCsrfTokenManager(),
940
-				$c->getRequest()
941
-			);
942
-		});
943
-
944
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
945
-			$config = $c->getConfig();
946
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
947
-			/** @var \OCP\Share\IProviderFactory $factory */
948
-			$factory = new $factoryClass($this);
949
-
950
-			$manager = new \OC\Share20\Manager(
951
-				$c->getLogger(),
952
-				$c->getConfig(),
953
-				$c->getSecureRandom(),
954
-				$c->getHasher(),
955
-				$c->getMountManager(),
956
-				$c->getGroupManager(),
957
-				$c->getL10N('core'),
958
-				$factory,
959
-				$c->getUserManager(),
960
-				$c->getLazyRootFolder(),
961
-				$c->getEventDispatcher()
962
-			);
963
-
964
-			return $manager;
965
-		});
966
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
967
-
968
-		$this->registerService('SettingsManager', function(Server $c) {
969
-			$manager = new \OC\Settings\Manager(
970
-				$c->getLogger(),
971
-				$c->getDatabaseConnection(),
972
-				$c->getL10N('lib'),
973
-				$c->getConfig(),
974
-				$c->getEncryptionManager(),
975
-				$c->getUserManager(),
976
-				$c->getLockingProvider(),
977
-				$c->getRequest(),
978
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
979
-				$c->getURLGenerator()
980
-			);
981
-			return $manager;
982
-		});
983
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
984
-			return new \OC\Files\AppData\Factory(
985
-				$c->getRootFolder(),
986
-				$c->getSystemConfig()
987
-			);
988
-		});
989
-
990
-		$this->registerService('LockdownManager', function (Server $c) {
991
-			return new LockdownManager(function() use ($c) {
992
-				return $c->getSession();
993
-			});
994
-		});
995
-
996
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
997
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
998
-		});
999
-
1000
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1001
-			return new CloudIdManager();
1002
-		});
1003
-
1004
-		/* To trick DI since we don't extend the DIContainer here */
1005
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1006
-			return new CleanPreviewsBackgroundJob(
1007
-				$c->getRootFolder(),
1008
-				$c->getLogger(),
1009
-				$c->getJobList(),
1010
-				new TimeFactory()
1011
-			);
1012
-		});
1013
-
1014
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1015
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1016
-
1017
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1018
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1019
-
1020
-		$this->registerService(Defaults::class, function (Server $c) {
1021
-			return new Defaults(
1022
-				$c->getThemingDefaults()
1023
-			);
1024
-		});
1025
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1026
-
1027
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1028
-			return $c->query(\OCP\IUserSession::class)->getSession();
1029
-		});
1030
-
1031
-		$this->registerService(IShareHelper::class, function(Server $c) {
1032
-			return new ShareHelper(
1033
-				$c->query(\OCP\Share\IManager::class)
1034
-			);
1035
-		});
1036
-	}
1037
-
1038
-	/**
1039
-	 * @return \OCP\Contacts\IManager
1040
-	 */
1041
-	public function getContactsManager() {
1042
-		return $this->query('ContactsManager');
1043
-	}
1044
-
1045
-	/**
1046
-	 * @return \OC\Encryption\Manager
1047
-	 */
1048
-	public function getEncryptionManager() {
1049
-		return $this->query('EncryptionManager');
1050
-	}
1051
-
1052
-	/**
1053
-	 * @return \OC\Encryption\File
1054
-	 */
1055
-	public function getEncryptionFilesHelper() {
1056
-		return $this->query('EncryptionFileHelper');
1057
-	}
1058
-
1059
-	/**
1060
-	 * @return \OCP\Encryption\Keys\IStorage
1061
-	 */
1062
-	public function getEncryptionKeyStorage() {
1063
-		return $this->query('EncryptionKeyStorage');
1064
-	}
1065
-
1066
-	/**
1067
-	 * The current request object holding all information about the request
1068
-	 * currently being processed is returned from this method.
1069
-	 * In case the current execution was not initiated by a web request null is returned
1070
-	 *
1071
-	 * @return \OCP\IRequest
1072
-	 */
1073
-	public function getRequest() {
1074
-		return $this->query('Request');
1075
-	}
1076
-
1077
-	/**
1078
-	 * Returns the preview manager which can create preview images for a given file
1079
-	 *
1080
-	 * @return \OCP\IPreview
1081
-	 */
1082
-	public function getPreviewManager() {
1083
-		return $this->query('PreviewManager');
1084
-	}
1085
-
1086
-	/**
1087
-	 * Returns the tag manager which can get and set tags for different object types
1088
-	 *
1089
-	 * @see \OCP\ITagManager::load()
1090
-	 * @return \OCP\ITagManager
1091
-	 */
1092
-	public function getTagManager() {
1093
-		return $this->query('TagManager');
1094
-	}
1095
-
1096
-	/**
1097
-	 * Returns the system-tag manager
1098
-	 *
1099
-	 * @return \OCP\SystemTag\ISystemTagManager
1100
-	 *
1101
-	 * @since 9.0.0
1102
-	 */
1103
-	public function getSystemTagManager() {
1104
-		return $this->query('SystemTagManager');
1105
-	}
1106
-
1107
-	/**
1108
-	 * Returns the system-tag object mapper
1109
-	 *
1110
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1111
-	 *
1112
-	 * @since 9.0.0
1113
-	 */
1114
-	public function getSystemTagObjectMapper() {
1115
-		return $this->query('SystemTagObjectMapper');
1116
-	}
1117
-
1118
-	/**
1119
-	 * Returns the avatar manager, used for avatar functionality
1120
-	 *
1121
-	 * @return \OCP\IAvatarManager
1122
-	 */
1123
-	public function getAvatarManager() {
1124
-		return $this->query('AvatarManager');
1125
-	}
1126
-
1127
-	/**
1128
-	 * Returns the root folder of ownCloud's data directory
1129
-	 *
1130
-	 * @return \OCP\Files\IRootFolder
1131
-	 */
1132
-	public function getRootFolder() {
1133
-		return $this->query('LazyRootFolder');
1134
-	}
1135
-
1136
-	/**
1137
-	 * Returns the root folder of ownCloud's data directory
1138
-	 * This is the lazy variant so this gets only initialized once it
1139
-	 * is actually used.
1140
-	 *
1141
-	 * @return \OCP\Files\IRootFolder
1142
-	 */
1143
-	public function getLazyRootFolder() {
1144
-		return $this->query('LazyRootFolder');
1145
-	}
1146
-
1147
-	/**
1148
-	 * Returns a view to ownCloud's files folder
1149
-	 *
1150
-	 * @param string $userId user ID
1151
-	 * @return \OCP\Files\Folder|null
1152
-	 */
1153
-	public function getUserFolder($userId = null) {
1154
-		if ($userId === null) {
1155
-			$user = $this->getUserSession()->getUser();
1156
-			if (!$user) {
1157
-				return null;
1158
-			}
1159
-			$userId = $user->getUID();
1160
-		}
1161
-		$root = $this->getRootFolder();
1162
-		return $root->getUserFolder($userId);
1163
-	}
1164
-
1165
-	/**
1166
-	 * Returns an app-specific view in ownClouds data directory
1167
-	 *
1168
-	 * @return \OCP\Files\Folder
1169
-	 * @deprecated since 9.2.0 use IAppData
1170
-	 */
1171
-	public function getAppFolder() {
1172
-		$dir = '/' . \OC_App::getCurrentApp();
1173
-		$root = $this->getRootFolder();
1174
-		if (!$root->nodeExists($dir)) {
1175
-			$folder = $root->newFolder($dir);
1176
-		} else {
1177
-			$folder = $root->get($dir);
1178
-		}
1179
-		return $folder;
1180
-	}
1181
-
1182
-	/**
1183
-	 * @return \OC\User\Manager
1184
-	 */
1185
-	public function getUserManager() {
1186
-		return $this->query('UserManager');
1187
-	}
1188
-
1189
-	/**
1190
-	 * @return \OC\Group\Manager
1191
-	 */
1192
-	public function getGroupManager() {
1193
-		return $this->query('GroupManager');
1194
-	}
1195
-
1196
-	/**
1197
-	 * @return \OC\User\Session
1198
-	 */
1199
-	public function getUserSession() {
1200
-		return $this->query('UserSession');
1201
-	}
1202
-
1203
-	/**
1204
-	 * @return \OCP\ISession
1205
-	 */
1206
-	public function getSession() {
1207
-		return $this->query('UserSession')->getSession();
1208
-	}
1209
-
1210
-	/**
1211
-	 * @param \OCP\ISession $session
1212
-	 */
1213
-	public function setSession(\OCP\ISession $session) {
1214
-		$this->query(SessionStorage::class)->setSession($session);
1215
-		$this->query('UserSession')->setSession($session);
1216
-		$this->query(Store::class)->setSession($session);
1217
-	}
1218
-
1219
-	/**
1220
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1221
-	 */
1222
-	public function getTwoFactorAuthManager() {
1223
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1224
-	}
1225
-
1226
-	/**
1227
-	 * @return \OC\NavigationManager
1228
-	 */
1229
-	public function getNavigationManager() {
1230
-		return $this->query('NavigationManager');
1231
-	}
1232
-
1233
-	/**
1234
-	 * @return \OCP\IConfig
1235
-	 */
1236
-	public function getConfig() {
1237
-		return $this->query('AllConfig');
1238
-	}
1239
-
1240
-	/**
1241
-	 * @internal For internal use only
1242
-	 * @return \OC\SystemConfig
1243
-	 */
1244
-	public function getSystemConfig() {
1245
-		return $this->query('SystemConfig');
1246
-	}
1247
-
1248
-	/**
1249
-	 * Returns the app config manager
1250
-	 *
1251
-	 * @return \OCP\IAppConfig
1252
-	 */
1253
-	public function getAppConfig() {
1254
-		return $this->query('AppConfig');
1255
-	}
1256
-
1257
-	/**
1258
-	 * @return \OCP\L10N\IFactory
1259
-	 */
1260
-	public function getL10NFactory() {
1261
-		return $this->query('L10NFactory');
1262
-	}
1263
-
1264
-	/**
1265
-	 * get an L10N instance
1266
-	 *
1267
-	 * @param string $app appid
1268
-	 * @param string $lang
1269
-	 * @return IL10N
1270
-	 */
1271
-	public function getL10N($app, $lang = null) {
1272
-		return $this->getL10NFactory()->get($app, $lang);
1273
-	}
1274
-
1275
-	/**
1276
-	 * @return \OCP\IURLGenerator
1277
-	 */
1278
-	public function getURLGenerator() {
1279
-		return $this->query('URLGenerator');
1280
-	}
1281
-
1282
-	/**
1283
-	 * @return \OCP\IHelper
1284
-	 */
1285
-	public function getHelper() {
1286
-		return $this->query('AppHelper');
1287
-	}
1288
-
1289
-	/**
1290
-	 * @return AppFetcher
1291
-	 */
1292
-	public function getAppFetcher() {
1293
-		return $this->query('AppFetcher');
1294
-	}
1295
-
1296
-	/**
1297
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1298
-	 * getMemCacheFactory() instead.
1299
-	 *
1300
-	 * @return \OCP\ICache
1301
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1302
-	 */
1303
-	public function getCache() {
1304
-		return $this->query('UserCache');
1305
-	}
1306
-
1307
-	/**
1308
-	 * Returns an \OCP\CacheFactory instance
1309
-	 *
1310
-	 * @return \OCP\ICacheFactory
1311
-	 */
1312
-	public function getMemCacheFactory() {
1313
-		return $this->query('MemCacheFactory');
1314
-	}
1315
-
1316
-	/**
1317
-	 * Returns an \OC\RedisFactory instance
1318
-	 *
1319
-	 * @return \OC\RedisFactory
1320
-	 */
1321
-	public function getGetRedisFactory() {
1322
-		return $this->query('RedisFactory');
1323
-	}
1324
-
1325
-
1326
-	/**
1327
-	 * Returns the current session
1328
-	 *
1329
-	 * @return \OCP\IDBConnection
1330
-	 */
1331
-	public function getDatabaseConnection() {
1332
-		return $this->query('DatabaseConnection');
1333
-	}
1334
-
1335
-	/**
1336
-	 * Returns the activity manager
1337
-	 *
1338
-	 * @return \OCP\Activity\IManager
1339
-	 */
1340
-	public function getActivityManager() {
1341
-		return $this->query('ActivityManager');
1342
-	}
1343
-
1344
-	/**
1345
-	 * Returns an job list for controlling background jobs
1346
-	 *
1347
-	 * @return \OCP\BackgroundJob\IJobList
1348
-	 */
1349
-	public function getJobList() {
1350
-		return $this->query('JobList');
1351
-	}
1352
-
1353
-	/**
1354
-	 * Returns a logger instance
1355
-	 *
1356
-	 * @return \OCP\ILogger
1357
-	 */
1358
-	public function getLogger() {
1359
-		return $this->query('Logger');
1360
-	}
1361
-
1362
-	/**
1363
-	 * Returns a router for generating and matching urls
1364
-	 *
1365
-	 * @return \OCP\Route\IRouter
1366
-	 */
1367
-	public function getRouter() {
1368
-		return $this->query('Router');
1369
-	}
1370
-
1371
-	/**
1372
-	 * Returns a search instance
1373
-	 *
1374
-	 * @return \OCP\ISearch
1375
-	 */
1376
-	public function getSearch() {
1377
-		return $this->query('Search');
1378
-	}
1379
-
1380
-	/**
1381
-	 * Returns a SecureRandom instance
1382
-	 *
1383
-	 * @return \OCP\Security\ISecureRandom
1384
-	 */
1385
-	public function getSecureRandom() {
1386
-		return $this->query('SecureRandom');
1387
-	}
1388
-
1389
-	/**
1390
-	 * Returns a Crypto instance
1391
-	 *
1392
-	 * @return \OCP\Security\ICrypto
1393
-	 */
1394
-	public function getCrypto() {
1395
-		return $this->query('Crypto');
1396
-	}
1397
-
1398
-	/**
1399
-	 * Returns a Hasher instance
1400
-	 *
1401
-	 * @return \OCP\Security\IHasher
1402
-	 */
1403
-	public function getHasher() {
1404
-		return $this->query('Hasher');
1405
-	}
1406
-
1407
-	/**
1408
-	 * Returns a CredentialsManager instance
1409
-	 *
1410
-	 * @return \OCP\Security\ICredentialsManager
1411
-	 */
1412
-	public function getCredentialsManager() {
1413
-		return $this->query('CredentialsManager');
1414
-	}
1415
-
1416
-	/**
1417
-	 * Returns an instance of the HTTP helper class
1418
-	 *
1419
-	 * @deprecated Use getHTTPClientService()
1420
-	 * @return \OC\HTTPHelper
1421
-	 */
1422
-	public function getHTTPHelper() {
1423
-		return $this->query('HTTPHelper');
1424
-	}
1425
-
1426
-	/**
1427
-	 * Get the certificate manager for the user
1428
-	 *
1429
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1430
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1431
-	 */
1432
-	public function getCertificateManager($userId = '') {
1433
-		if ($userId === '') {
1434
-			$userSession = $this->getUserSession();
1435
-			$user = $userSession->getUser();
1436
-			if (is_null($user)) {
1437
-				return null;
1438
-			}
1439
-			$userId = $user->getUID();
1440
-		}
1441
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1442
-	}
1443
-
1444
-	/**
1445
-	 * Returns an instance of the HTTP client service
1446
-	 *
1447
-	 * @return \OCP\Http\Client\IClientService
1448
-	 */
1449
-	public function getHTTPClientService() {
1450
-		return $this->query('HttpClientService');
1451
-	}
1452
-
1453
-	/**
1454
-	 * Create a new event source
1455
-	 *
1456
-	 * @return \OCP\IEventSource
1457
-	 */
1458
-	public function createEventSource() {
1459
-		return new \OC_EventSource();
1460
-	}
1461
-
1462
-	/**
1463
-	 * Get the active event logger
1464
-	 *
1465
-	 * The returned logger only logs data when debug mode is enabled
1466
-	 *
1467
-	 * @return \OCP\Diagnostics\IEventLogger
1468
-	 */
1469
-	public function getEventLogger() {
1470
-		return $this->query('EventLogger');
1471
-	}
1472
-
1473
-	/**
1474
-	 * Get the active query logger
1475
-	 *
1476
-	 * The returned logger only logs data when debug mode is enabled
1477
-	 *
1478
-	 * @return \OCP\Diagnostics\IQueryLogger
1479
-	 */
1480
-	public function getQueryLogger() {
1481
-		return $this->query('QueryLogger');
1482
-	}
1483
-
1484
-	/**
1485
-	 * Get the manager for temporary files and folders
1486
-	 *
1487
-	 * @return \OCP\ITempManager
1488
-	 */
1489
-	public function getTempManager() {
1490
-		return $this->query('TempManager');
1491
-	}
1492
-
1493
-	/**
1494
-	 * Get the app manager
1495
-	 *
1496
-	 * @return \OCP\App\IAppManager
1497
-	 */
1498
-	public function getAppManager() {
1499
-		return $this->query('AppManager');
1500
-	}
1501
-
1502
-	/**
1503
-	 * Creates a new mailer
1504
-	 *
1505
-	 * @return \OCP\Mail\IMailer
1506
-	 */
1507
-	public function getMailer() {
1508
-		return $this->query('Mailer');
1509
-	}
1510
-
1511
-	/**
1512
-	 * Get the webroot
1513
-	 *
1514
-	 * @return string
1515
-	 */
1516
-	public function getWebRoot() {
1517
-		return $this->webRoot;
1518
-	}
1519
-
1520
-	/**
1521
-	 * @return \OC\OCSClient
1522
-	 */
1523
-	public function getOcsClient() {
1524
-		return $this->query('OcsClient');
1525
-	}
1526
-
1527
-	/**
1528
-	 * @return \OCP\IDateTimeZone
1529
-	 */
1530
-	public function getDateTimeZone() {
1531
-		return $this->query('DateTimeZone');
1532
-	}
1533
-
1534
-	/**
1535
-	 * @return \OCP\IDateTimeFormatter
1536
-	 */
1537
-	public function getDateTimeFormatter() {
1538
-		return $this->query('DateTimeFormatter');
1539
-	}
1540
-
1541
-	/**
1542
-	 * @return \OCP\Files\Config\IMountProviderCollection
1543
-	 */
1544
-	public function getMountProviderCollection() {
1545
-		return $this->query('MountConfigManager');
1546
-	}
1547
-
1548
-	/**
1549
-	 * Get the IniWrapper
1550
-	 *
1551
-	 * @return IniGetWrapper
1552
-	 */
1553
-	public function getIniWrapper() {
1554
-		return $this->query('IniWrapper');
1555
-	}
1556
-
1557
-	/**
1558
-	 * @return \OCP\Command\IBus
1559
-	 */
1560
-	public function getCommandBus() {
1561
-		return $this->query('AsyncCommandBus');
1562
-	}
1563
-
1564
-	/**
1565
-	 * Get the trusted domain helper
1566
-	 *
1567
-	 * @return TrustedDomainHelper
1568
-	 */
1569
-	public function getTrustedDomainHelper() {
1570
-		return $this->query('TrustedDomainHelper');
1571
-	}
1572
-
1573
-	/**
1574
-	 * Get the locking provider
1575
-	 *
1576
-	 * @return \OCP\Lock\ILockingProvider
1577
-	 * @since 8.1.0
1578
-	 */
1579
-	public function getLockingProvider() {
1580
-		return $this->query('LockingProvider');
1581
-	}
1582
-
1583
-	/**
1584
-	 * @return \OCP\Files\Mount\IMountManager
1585
-	 **/
1586
-	function getMountManager() {
1587
-		return $this->query('MountManager');
1588
-	}
1589
-
1590
-	/** @return \OCP\Files\Config\IUserMountCache */
1591
-	function getUserMountCache() {
1592
-		return $this->query('UserMountCache');
1593
-	}
1594
-
1595
-	/**
1596
-	 * Get the MimeTypeDetector
1597
-	 *
1598
-	 * @return \OCP\Files\IMimeTypeDetector
1599
-	 */
1600
-	public function getMimeTypeDetector() {
1601
-		return $this->query('MimeTypeDetector');
1602
-	}
1603
-
1604
-	/**
1605
-	 * Get the MimeTypeLoader
1606
-	 *
1607
-	 * @return \OCP\Files\IMimeTypeLoader
1608
-	 */
1609
-	public function getMimeTypeLoader() {
1610
-		return $this->query('MimeTypeLoader');
1611
-	}
1612
-
1613
-	/**
1614
-	 * Get the manager of all the capabilities
1615
-	 *
1616
-	 * @return \OC\CapabilitiesManager
1617
-	 */
1618
-	public function getCapabilitiesManager() {
1619
-		return $this->query('CapabilitiesManager');
1620
-	}
1621
-
1622
-	/**
1623
-	 * Get the EventDispatcher
1624
-	 *
1625
-	 * @return EventDispatcherInterface
1626
-	 * @since 8.2.0
1627
-	 */
1628
-	public function getEventDispatcher() {
1629
-		return $this->query('EventDispatcher');
1630
-	}
1631
-
1632
-	/**
1633
-	 * Get the Notification Manager
1634
-	 *
1635
-	 * @return \OCP\Notification\IManager
1636
-	 * @since 8.2.0
1637
-	 */
1638
-	public function getNotificationManager() {
1639
-		return $this->query('NotificationManager');
1640
-	}
1641
-
1642
-	/**
1643
-	 * @return \OCP\Comments\ICommentsManager
1644
-	 */
1645
-	public function getCommentsManager() {
1646
-		return $this->query('CommentsManager');
1647
-	}
1648
-
1649
-	/**
1650
-	 * @return \OCA\Theming\ThemingDefaults
1651
-	 */
1652
-	public function getThemingDefaults() {
1653
-		return $this->query('ThemingDefaults');
1654
-	}
1655
-
1656
-	/**
1657
-	 * @return \OC\IntegrityCheck\Checker
1658
-	 */
1659
-	public function getIntegrityCodeChecker() {
1660
-		return $this->query('IntegrityCodeChecker');
1661
-	}
1662
-
1663
-	/**
1664
-	 * @return \OC\Session\CryptoWrapper
1665
-	 */
1666
-	public function getSessionCryptoWrapper() {
1667
-		return $this->query('CryptoWrapper');
1668
-	}
1669
-
1670
-	/**
1671
-	 * @return CsrfTokenManager
1672
-	 */
1673
-	public function getCsrfTokenManager() {
1674
-		return $this->query('CsrfTokenManager');
1675
-	}
1676
-
1677
-	/**
1678
-	 * @return Throttler
1679
-	 */
1680
-	public function getBruteForceThrottler() {
1681
-		return $this->query('Throttler');
1682
-	}
1683
-
1684
-	/**
1685
-	 * @return IContentSecurityPolicyManager
1686
-	 */
1687
-	public function getContentSecurityPolicyManager() {
1688
-		return $this->query('ContentSecurityPolicyManager');
1689
-	}
1690
-
1691
-	/**
1692
-	 * @return ContentSecurityPolicyNonceManager
1693
-	 */
1694
-	public function getContentSecurityPolicyNonceManager() {
1695
-		return $this->query('ContentSecurityPolicyNonceManager');
1696
-	}
1697
-
1698
-	/**
1699
-	 * Not a public API as of 8.2, wait for 9.0
1700
-	 *
1701
-	 * @return \OCA\Files_External\Service\BackendService
1702
-	 */
1703
-	public function getStoragesBackendService() {
1704
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1705
-	}
1706
-
1707
-	/**
1708
-	 * Not a public API as of 8.2, wait for 9.0
1709
-	 *
1710
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1711
-	 */
1712
-	public function getGlobalStoragesService() {
1713
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1714
-	}
1715
-
1716
-	/**
1717
-	 * Not a public API as of 8.2, wait for 9.0
1718
-	 *
1719
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1720
-	 */
1721
-	public function getUserGlobalStoragesService() {
1722
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1723
-	}
1724
-
1725
-	/**
1726
-	 * Not a public API as of 8.2, wait for 9.0
1727
-	 *
1728
-	 * @return \OCA\Files_External\Service\UserStoragesService
1729
-	 */
1730
-	public function getUserStoragesService() {
1731
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1732
-	}
1733
-
1734
-	/**
1735
-	 * @return \OCP\Share\IManager
1736
-	 */
1737
-	public function getShareManager() {
1738
-		return $this->query('ShareManager');
1739
-	}
1740
-
1741
-	/**
1742
-	 * Returns the LDAP Provider
1743
-	 *
1744
-	 * @return \OCP\LDAP\ILDAPProvider
1745
-	 */
1746
-	public function getLDAPProvider() {
1747
-		return $this->query('LDAPProvider');
1748
-	}
1749
-
1750
-	/**
1751
-	 * @return \OCP\Settings\IManager
1752
-	 */
1753
-	public function getSettingsManager() {
1754
-		return $this->query('SettingsManager');
1755
-	}
1756
-
1757
-	/**
1758
-	 * @return \OCP\Files\IAppData
1759
-	 */
1760
-	public function getAppDataDir($app) {
1761
-		/** @var \OC\Files\AppData\Factory $factory */
1762
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1763
-		return $factory->get($app);
1764
-	}
1765
-
1766
-	/**
1767
-	 * @return \OCP\Lockdown\ILockdownManager
1768
-	 */
1769
-	public function getLockdownManager() {
1770
-		return $this->query('LockdownManager');
1771
-	}
1772
-
1773
-	/**
1774
-	 * @return \OCP\Federation\ICloudIdManager
1775
-	 */
1776
-	public function getCloudIdManager() {
1777
-		return $this->query(ICloudIdManager::class);
1778
-	}
858
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
859
+            if (isset($prefixes['OCA\\Theming\\'])) {
860
+                $classExists = true;
861
+            } else {
862
+                $classExists = false;
863
+            }
864
+
865
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
866
+                return new ThemingDefaults(
867
+                    $c->getConfig(),
868
+                    $c->getL10N('theming'),
869
+                    $c->getURLGenerator(),
870
+                    $c->getAppDataDir('theming'),
871
+                    $c->getMemCacheFactory(),
872
+                    new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
873
+                );
874
+            }
875
+            return new \OC_Defaults();
876
+        });
877
+        $this->registerService(SCSSCacher::class, function(Server $c) {
878
+            /** @var Factory $cacheFactory */
879
+            $cacheFactory = $c->query(Factory::class);
880
+            return new SCSSCacher(
881
+                $c->getLogger(),
882
+                $c->query(\OC\Files\AppData\Factory::class),
883
+                $c->getURLGenerator(),
884
+                $c->getConfig(),
885
+                $c->getThemingDefaults(),
886
+                \OC::$SERVERROOT,
887
+                $cacheFactory->createLocal('SCSS')
888
+            );
889
+        });
890
+        $this->registerService(EventDispatcher::class, function () {
891
+            return new EventDispatcher();
892
+        });
893
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
894
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
895
+
896
+        $this->registerService('CryptoWrapper', function (Server $c) {
897
+            // FIXME: Instantiiated here due to cyclic dependency
898
+            $request = new Request(
899
+                [
900
+                    'get' => $_GET,
901
+                    'post' => $_POST,
902
+                    'files' => $_FILES,
903
+                    'server' => $_SERVER,
904
+                    'env' => $_ENV,
905
+                    'cookies' => $_COOKIE,
906
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
907
+                        ? $_SERVER['REQUEST_METHOD']
908
+                        : null,
909
+                ],
910
+                $c->getSecureRandom(),
911
+                $c->getConfig()
912
+            );
913
+
914
+            return new CryptoWrapper(
915
+                $c->getConfig(),
916
+                $c->getCrypto(),
917
+                $c->getSecureRandom(),
918
+                $request
919
+            );
920
+        });
921
+        $this->registerService('CsrfTokenManager', function (Server $c) {
922
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
923
+
924
+            return new CsrfTokenManager(
925
+                $tokenGenerator,
926
+                $c->query(SessionStorage::class)
927
+            );
928
+        });
929
+        $this->registerService(SessionStorage::class, function (Server $c) {
930
+            return new SessionStorage($c->getSession());
931
+        });
932
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
933
+            return new ContentSecurityPolicyManager();
934
+        });
935
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
936
+
937
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
938
+            return new ContentSecurityPolicyNonceManager(
939
+                $c->getCsrfTokenManager(),
940
+                $c->getRequest()
941
+            );
942
+        });
943
+
944
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
945
+            $config = $c->getConfig();
946
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
947
+            /** @var \OCP\Share\IProviderFactory $factory */
948
+            $factory = new $factoryClass($this);
949
+
950
+            $manager = new \OC\Share20\Manager(
951
+                $c->getLogger(),
952
+                $c->getConfig(),
953
+                $c->getSecureRandom(),
954
+                $c->getHasher(),
955
+                $c->getMountManager(),
956
+                $c->getGroupManager(),
957
+                $c->getL10N('core'),
958
+                $factory,
959
+                $c->getUserManager(),
960
+                $c->getLazyRootFolder(),
961
+                $c->getEventDispatcher()
962
+            );
963
+
964
+            return $manager;
965
+        });
966
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
967
+
968
+        $this->registerService('SettingsManager', function(Server $c) {
969
+            $manager = new \OC\Settings\Manager(
970
+                $c->getLogger(),
971
+                $c->getDatabaseConnection(),
972
+                $c->getL10N('lib'),
973
+                $c->getConfig(),
974
+                $c->getEncryptionManager(),
975
+                $c->getUserManager(),
976
+                $c->getLockingProvider(),
977
+                $c->getRequest(),
978
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
979
+                $c->getURLGenerator()
980
+            );
981
+            return $manager;
982
+        });
983
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
984
+            return new \OC\Files\AppData\Factory(
985
+                $c->getRootFolder(),
986
+                $c->getSystemConfig()
987
+            );
988
+        });
989
+
990
+        $this->registerService('LockdownManager', function (Server $c) {
991
+            return new LockdownManager(function() use ($c) {
992
+                return $c->getSession();
993
+            });
994
+        });
995
+
996
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
997
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
998
+        });
999
+
1000
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1001
+            return new CloudIdManager();
1002
+        });
1003
+
1004
+        /* To trick DI since we don't extend the DIContainer here */
1005
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1006
+            return new CleanPreviewsBackgroundJob(
1007
+                $c->getRootFolder(),
1008
+                $c->getLogger(),
1009
+                $c->getJobList(),
1010
+                new TimeFactory()
1011
+            );
1012
+        });
1013
+
1014
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1015
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1016
+
1017
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1018
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1019
+
1020
+        $this->registerService(Defaults::class, function (Server $c) {
1021
+            return new Defaults(
1022
+                $c->getThemingDefaults()
1023
+            );
1024
+        });
1025
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1026
+
1027
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1028
+            return $c->query(\OCP\IUserSession::class)->getSession();
1029
+        });
1030
+
1031
+        $this->registerService(IShareHelper::class, function(Server $c) {
1032
+            return new ShareHelper(
1033
+                $c->query(\OCP\Share\IManager::class)
1034
+            );
1035
+        });
1036
+    }
1037
+
1038
+    /**
1039
+     * @return \OCP\Contacts\IManager
1040
+     */
1041
+    public function getContactsManager() {
1042
+        return $this->query('ContactsManager');
1043
+    }
1044
+
1045
+    /**
1046
+     * @return \OC\Encryption\Manager
1047
+     */
1048
+    public function getEncryptionManager() {
1049
+        return $this->query('EncryptionManager');
1050
+    }
1051
+
1052
+    /**
1053
+     * @return \OC\Encryption\File
1054
+     */
1055
+    public function getEncryptionFilesHelper() {
1056
+        return $this->query('EncryptionFileHelper');
1057
+    }
1058
+
1059
+    /**
1060
+     * @return \OCP\Encryption\Keys\IStorage
1061
+     */
1062
+    public function getEncryptionKeyStorage() {
1063
+        return $this->query('EncryptionKeyStorage');
1064
+    }
1065
+
1066
+    /**
1067
+     * The current request object holding all information about the request
1068
+     * currently being processed is returned from this method.
1069
+     * In case the current execution was not initiated by a web request null is returned
1070
+     *
1071
+     * @return \OCP\IRequest
1072
+     */
1073
+    public function getRequest() {
1074
+        return $this->query('Request');
1075
+    }
1076
+
1077
+    /**
1078
+     * Returns the preview manager which can create preview images for a given file
1079
+     *
1080
+     * @return \OCP\IPreview
1081
+     */
1082
+    public function getPreviewManager() {
1083
+        return $this->query('PreviewManager');
1084
+    }
1085
+
1086
+    /**
1087
+     * Returns the tag manager which can get and set tags for different object types
1088
+     *
1089
+     * @see \OCP\ITagManager::load()
1090
+     * @return \OCP\ITagManager
1091
+     */
1092
+    public function getTagManager() {
1093
+        return $this->query('TagManager');
1094
+    }
1095
+
1096
+    /**
1097
+     * Returns the system-tag manager
1098
+     *
1099
+     * @return \OCP\SystemTag\ISystemTagManager
1100
+     *
1101
+     * @since 9.0.0
1102
+     */
1103
+    public function getSystemTagManager() {
1104
+        return $this->query('SystemTagManager');
1105
+    }
1106
+
1107
+    /**
1108
+     * Returns the system-tag object mapper
1109
+     *
1110
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1111
+     *
1112
+     * @since 9.0.0
1113
+     */
1114
+    public function getSystemTagObjectMapper() {
1115
+        return $this->query('SystemTagObjectMapper');
1116
+    }
1117
+
1118
+    /**
1119
+     * Returns the avatar manager, used for avatar functionality
1120
+     *
1121
+     * @return \OCP\IAvatarManager
1122
+     */
1123
+    public function getAvatarManager() {
1124
+        return $this->query('AvatarManager');
1125
+    }
1126
+
1127
+    /**
1128
+     * Returns the root folder of ownCloud's data directory
1129
+     *
1130
+     * @return \OCP\Files\IRootFolder
1131
+     */
1132
+    public function getRootFolder() {
1133
+        return $this->query('LazyRootFolder');
1134
+    }
1135
+
1136
+    /**
1137
+     * Returns the root folder of ownCloud's data directory
1138
+     * This is the lazy variant so this gets only initialized once it
1139
+     * is actually used.
1140
+     *
1141
+     * @return \OCP\Files\IRootFolder
1142
+     */
1143
+    public function getLazyRootFolder() {
1144
+        return $this->query('LazyRootFolder');
1145
+    }
1146
+
1147
+    /**
1148
+     * Returns a view to ownCloud's files folder
1149
+     *
1150
+     * @param string $userId user ID
1151
+     * @return \OCP\Files\Folder|null
1152
+     */
1153
+    public function getUserFolder($userId = null) {
1154
+        if ($userId === null) {
1155
+            $user = $this->getUserSession()->getUser();
1156
+            if (!$user) {
1157
+                return null;
1158
+            }
1159
+            $userId = $user->getUID();
1160
+        }
1161
+        $root = $this->getRootFolder();
1162
+        return $root->getUserFolder($userId);
1163
+    }
1164
+
1165
+    /**
1166
+     * Returns an app-specific view in ownClouds data directory
1167
+     *
1168
+     * @return \OCP\Files\Folder
1169
+     * @deprecated since 9.2.0 use IAppData
1170
+     */
1171
+    public function getAppFolder() {
1172
+        $dir = '/' . \OC_App::getCurrentApp();
1173
+        $root = $this->getRootFolder();
1174
+        if (!$root->nodeExists($dir)) {
1175
+            $folder = $root->newFolder($dir);
1176
+        } else {
1177
+            $folder = $root->get($dir);
1178
+        }
1179
+        return $folder;
1180
+    }
1181
+
1182
+    /**
1183
+     * @return \OC\User\Manager
1184
+     */
1185
+    public function getUserManager() {
1186
+        return $this->query('UserManager');
1187
+    }
1188
+
1189
+    /**
1190
+     * @return \OC\Group\Manager
1191
+     */
1192
+    public function getGroupManager() {
1193
+        return $this->query('GroupManager');
1194
+    }
1195
+
1196
+    /**
1197
+     * @return \OC\User\Session
1198
+     */
1199
+    public function getUserSession() {
1200
+        return $this->query('UserSession');
1201
+    }
1202
+
1203
+    /**
1204
+     * @return \OCP\ISession
1205
+     */
1206
+    public function getSession() {
1207
+        return $this->query('UserSession')->getSession();
1208
+    }
1209
+
1210
+    /**
1211
+     * @param \OCP\ISession $session
1212
+     */
1213
+    public function setSession(\OCP\ISession $session) {
1214
+        $this->query(SessionStorage::class)->setSession($session);
1215
+        $this->query('UserSession')->setSession($session);
1216
+        $this->query(Store::class)->setSession($session);
1217
+    }
1218
+
1219
+    /**
1220
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1221
+     */
1222
+    public function getTwoFactorAuthManager() {
1223
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1224
+    }
1225
+
1226
+    /**
1227
+     * @return \OC\NavigationManager
1228
+     */
1229
+    public function getNavigationManager() {
1230
+        return $this->query('NavigationManager');
1231
+    }
1232
+
1233
+    /**
1234
+     * @return \OCP\IConfig
1235
+     */
1236
+    public function getConfig() {
1237
+        return $this->query('AllConfig');
1238
+    }
1239
+
1240
+    /**
1241
+     * @internal For internal use only
1242
+     * @return \OC\SystemConfig
1243
+     */
1244
+    public function getSystemConfig() {
1245
+        return $this->query('SystemConfig');
1246
+    }
1247
+
1248
+    /**
1249
+     * Returns the app config manager
1250
+     *
1251
+     * @return \OCP\IAppConfig
1252
+     */
1253
+    public function getAppConfig() {
1254
+        return $this->query('AppConfig');
1255
+    }
1256
+
1257
+    /**
1258
+     * @return \OCP\L10N\IFactory
1259
+     */
1260
+    public function getL10NFactory() {
1261
+        return $this->query('L10NFactory');
1262
+    }
1263
+
1264
+    /**
1265
+     * get an L10N instance
1266
+     *
1267
+     * @param string $app appid
1268
+     * @param string $lang
1269
+     * @return IL10N
1270
+     */
1271
+    public function getL10N($app, $lang = null) {
1272
+        return $this->getL10NFactory()->get($app, $lang);
1273
+    }
1274
+
1275
+    /**
1276
+     * @return \OCP\IURLGenerator
1277
+     */
1278
+    public function getURLGenerator() {
1279
+        return $this->query('URLGenerator');
1280
+    }
1281
+
1282
+    /**
1283
+     * @return \OCP\IHelper
1284
+     */
1285
+    public function getHelper() {
1286
+        return $this->query('AppHelper');
1287
+    }
1288
+
1289
+    /**
1290
+     * @return AppFetcher
1291
+     */
1292
+    public function getAppFetcher() {
1293
+        return $this->query('AppFetcher');
1294
+    }
1295
+
1296
+    /**
1297
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1298
+     * getMemCacheFactory() instead.
1299
+     *
1300
+     * @return \OCP\ICache
1301
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1302
+     */
1303
+    public function getCache() {
1304
+        return $this->query('UserCache');
1305
+    }
1306
+
1307
+    /**
1308
+     * Returns an \OCP\CacheFactory instance
1309
+     *
1310
+     * @return \OCP\ICacheFactory
1311
+     */
1312
+    public function getMemCacheFactory() {
1313
+        return $this->query('MemCacheFactory');
1314
+    }
1315
+
1316
+    /**
1317
+     * Returns an \OC\RedisFactory instance
1318
+     *
1319
+     * @return \OC\RedisFactory
1320
+     */
1321
+    public function getGetRedisFactory() {
1322
+        return $this->query('RedisFactory');
1323
+    }
1324
+
1325
+
1326
+    /**
1327
+     * Returns the current session
1328
+     *
1329
+     * @return \OCP\IDBConnection
1330
+     */
1331
+    public function getDatabaseConnection() {
1332
+        return $this->query('DatabaseConnection');
1333
+    }
1334
+
1335
+    /**
1336
+     * Returns the activity manager
1337
+     *
1338
+     * @return \OCP\Activity\IManager
1339
+     */
1340
+    public function getActivityManager() {
1341
+        return $this->query('ActivityManager');
1342
+    }
1343
+
1344
+    /**
1345
+     * Returns an job list for controlling background jobs
1346
+     *
1347
+     * @return \OCP\BackgroundJob\IJobList
1348
+     */
1349
+    public function getJobList() {
1350
+        return $this->query('JobList');
1351
+    }
1352
+
1353
+    /**
1354
+     * Returns a logger instance
1355
+     *
1356
+     * @return \OCP\ILogger
1357
+     */
1358
+    public function getLogger() {
1359
+        return $this->query('Logger');
1360
+    }
1361
+
1362
+    /**
1363
+     * Returns a router for generating and matching urls
1364
+     *
1365
+     * @return \OCP\Route\IRouter
1366
+     */
1367
+    public function getRouter() {
1368
+        return $this->query('Router');
1369
+    }
1370
+
1371
+    /**
1372
+     * Returns a search instance
1373
+     *
1374
+     * @return \OCP\ISearch
1375
+     */
1376
+    public function getSearch() {
1377
+        return $this->query('Search');
1378
+    }
1379
+
1380
+    /**
1381
+     * Returns a SecureRandom instance
1382
+     *
1383
+     * @return \OCP\Security\ISecureRandom
1384
+     */
1385
+    public function getSecureRandom() {
1386
+        return $this->query('SecureRandom');
1387
+    }
1388
+
1389
+    /**
1390
+     * Returns a Crypto instance
1391
+     *
1392
+     * @return \OCP\Security\ICrypto
1393
+     */
1394
+    public function getCrypto() {
1395
+        return $this->query('Crypto');
1396
+    }
1397
+
1398
+    /**
1399
+     * Returns a Hasher instance
1400
+     *
1401
+     * @return \OCP\Security\IHasher
1402
+     */
1403
+    public function getHasher() {
1404
+        return $this->query('Hasher');
1405
+    }
1406
+
1407
+    /**
1408
+     * Returns a CredentialsManager instance
1409
+     *
1410
+     * @return \OCP\Security\ICredentialsManager
1411
+     */
1412
+    public function getCredentialsManager() {
1413
+        return $this->query('CredentialsManager');
1414
+    }
1415
+
1416
+    /**
1417
+     * Returns an instance of the HTTP helper class
1418
+     *
1419
+     * @deprecated Use getHTTPClientService()
1420
+     * @return \OC\HTTPHelper
1421
+     */
1422
+    public function getHTTPHelper() {
1423
+        return $this->query('HTTPHelper');
1424
+    }
1425
+
1426
+    /**
1427
+     * Get the certificate manager for the user
1428
+     *
1429
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1430
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1431
+     */
1432
+    public function getCertificateManager($userId = '') {
1433
+        if ($userId === '') {
1434
+            $userSession = $this->getUserSession();
1435
+            $user = $userSession->getUser();
1436
+            if (is_null($user)) {
1437
+                return null;
1438
+            }
1439
+            $userId = $user->getUID();
1440
+        }
1441
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1442
+    }
1443
+
1444
+    /**
1445
+     * Returns an instance of the HTTP client service
1446
+     *
1447
+     * @return \OCP\Http\Client\IClientService
1448
+     */
1449
+    public function getHTTPClientService() {
1450
+        return $this->query('HttpClientService');
1451
+    }
1452
+
1453
+    /**
1454
+     * Create a new event source
1455
+     *
1456
+     * @return \OCP\IEventSource
1457
+     */
1458
+    public function createEventSource() {
1459
+        return new \OC_EventSource();
1460
+    }
1461
+
1462
+    /**
1463
+     * Get the active event logger
1464
+     *
1465
+     * The returned logger only logs data when debug mode is enabled
1466
+     *
1467
+     * @return \OCP\Diagnostics\IEventLogger
1468
+     */
1469
+    public function getEventLogger() {
1470
+        return $this->query('EventLogger');
1471
+    }
1472
+
1473
+    /**
1474
+     * Get the active query logger
1475
+     *
1476
+     * The returned logger only logs data when debug mode is enabled
1477
+     *
1478
+     * @return \OCP\Diagnostics\IQueryLogger
1479
+     */
1480
+    public function getQueryLogger() {
1481
+        return $this->query('QueryLogger');
1482
+    }
1483
+
1484
+    /**
1485
+     * Get the manager for temporary files and folders
1486
+     *
1487
+     * @return \OCP\ITempManager
1488
+     */
1489
+    public function getTempManager() {
1490
+        return $this->query('TempManager');
1491
+    }
1492
+
1493
+    /**
1494
+     * Get the app manager
1495
+     *
1496
+     * @return \OCP\App\IAppManager
1497
+     */
1498
+    public function getAppManager() {
1499
+        return $this->query('AppManager');
1500
+    }
1501
+
1502
+    /**
1503
+     * Creates a new mailer
1504
+     *
1505
+     * @return \OCP\Mail\IMailer
1506
+     */
1507
+    public function getMailer() {
1508
+        return $this->query('Mailer');
1509
+    }
1510
+
1511
+    /**
1512
+     * Get the webroot
1513
+     *
1514
+     * @return string
1515
+     */
1516
+    public function getWebRoot() {
1517
+        return $this->webRoot;
1518
+    }
1519
+
1520
+    /**
1521
+     * @return \OC\OCSClient
1522
+     */
1523
+    public function getOcsClient() {
1524
+        return $this->query('OcsClient');
1525
+    }
1526
+
1527
+    /**
1528
+     * @return \OCP\IDateTimeZone
1529
+     */
1530
+    public function getDateTimeZone() {
1531
+        return $this->query('DateTimeZone');
1532
+    }
1533
+
1534
+    /**
1535
+     * @return \OCP\IDateTimeFormatter
1536
+     */
1537
+    public function getDateTimeFormatter() {
1538
+        return $this->query('DateTimeFormatter');
1539
+    }
1540
+
1541
+    /**
1542
+     * @return \OCP\Files\Config\IMountProviderCollection
1543
+     */
1544
+    public function getMountProviderCollection() {
1545
+        return $this->query('MountConfigManager');
1546
+    }
1547
+
1548
+    /**
1549
+     * Get the IniWrapper
1550
+     *
1551
+     * @return IniGetWrapper
1552
+     */
1553
+    public function getIniWrapper() {
1554
+        return $this->query('IniWrapper');
1555
+    }
1556
+
1557
+    /**
1558
+     * @return \OCP\Command\IBus
1559
+     */
1560
+    public function getCommandBus() {
1561
+        return $this->query('AsyncCommandBus');
1562
+    }
1563
+
1564
+    /**
1565
+     * Get the trusted domain helper
1566
+     *
1567
+     * @return TrustedDomainHelper
1568
+     */
1569
+    public function getTrustedDomainHelper() {
1570
+        return $this->query('TrustedDomainHelper');
1571
+    }
1572
+
1573
+    /**
1574
+     * Get the locking provider
1575
+     *
1576
+     * @return \OCP\Lock\ILockingProvider
1577
+     * @since 8.1.0
1578
+     */
1579
+    public function getLockingProvider() {
1580
+        return $this->query('LockingProvider');
1581
+    }
1582
+
1583
+    /**
1584
+     * @return \OCP\Files\Mount\IMountManager
1585
+     **/
1586
+    function getMountManager() {
1587
+        return $this->query('MountManager');
1588
+    }
1589
+
1590
+    /** @return \OCP\Files\Config\IUserMountCache */
1591
+    function getUserMountCache() {
1592
+        return $this->query('UserMountCache');
1593
+    }
1594
+
1595
+    /**
1596
+     * Get the MimeTypeDetector
1597
+     *
1598
+     * @return \OCP\Files\IMimeTypeDetector
1599
+     */
1600
+    public function getMimeTypeDetector() {
1601
+        return $this->query('MimeTypeDetector');
1602
+    }
1603
+
1604
+    /**
1605
+     * Get the MimeTypeLoader
1606
+     *
1607
+     * @return \OCP\Files\IMimeTypeLoader
1608
+     */
1609
+    public function getMimeTypeLoader() {
1610
+        return $this->query('MimeTypeLoader');
1611
+    }
1612
+
1613
+    /**
1614
+     * Get the manager of all the capabilities
1615
+     *
1616
+     * @return \OC\CapabilitiesManager
1617
+     */
1618
+    public function getCapabilitiesManager() {
1619
+        return $this->query('CapabilitiesManager');
1620
+    }
1621
+
1622
+    /**
1623
+     * Get the EventDispatcher
1624
+     *
1625
+     * @return EventDispatcherInterface
1626
+     * @since 8.2.0
1627
+     */
1628
+    public function getEventDispatcher() {
1629
+        return $this->query('EventDispatcher');
1630
+    }
1631
+
1632
+    /**
1633
+     * Get the Notification Manager
1634
+     *
1635
+     * @return \OCP\Notification\IManager
1636
+     * @since 8.2.0
1637
+     */
1638
+    public function getNotificationManager() {
1639
+        return $this->query('NotificationManager');
1640
+    }
1641
+
1642
+    /**
1643
+     * @return \OCP\Comments\ICommentsManager
1644
+     */
1645
+    public function getCommentsManager() {
1646
+        return $this->query('CommentsManager');
1647
+    }
1648
+
1649
+    /**
1650
+     * @return \OCA\Theming\ThemingDefaults
1651
+     */
1652
+    public function getThemingDefaults() {
1653
+        return $this->query('ThemingDefaults');
1654
+    }
1655
+
1656
+    /**
1657
+     * @return \OC\IntegrityCheck\Checker
1658
+     */
1659
+    public function getIntegrityCodeChecker() {
1660
+        return $this->query('IntegrityCodeChecker');
1661
+    }
1662
+
1663
+    /**
1664
+     * @return \OC\Session\CryptoWrapper
1665
+     */
1666
+    public function getSessionCryptoWrapper() {
1667
+        return $this->query('CryptoWrapper');
1668
+    }
1669
+
1670
+    /**
1671
+     * @return CsrfTokenManager
1672
+     */
1673
+    public function getCsrfTokenManager() {
1674
+        return $this->query('CsrfTokenManager');
1675
+    }
1676
+
1677
+    /**
1678
+     * @return Throttler
1679
+     */
1680
+    public function getBruteForceThrottler() {
1681
+        return $this->query('Throttler');
1682
+    }
1683
+
1684
+    /**
1685
+     * @return IContentSecurityPolicyManager
1686
+     */
1687
+    public function getContentSecurityPolicyManager() {
1688
+        return $this->query('ContentSecurityPolicyManager');
1689
+    }
1690
+
1691
+    /**
1692
+     * @return ContentSecurityPolicyNonceManager
1693
+     */
1694
+    public function getContentSecurityPolicyNonceManager() {
1695
+        return $this->query('ContentSecurityPolicyNonceManager');
1696
+    }
1697
+
1698
+    /**
1699
+     * Not a public API as of 8.2, wait for 9.0
1700
+     *
1701
+     * @return \OCA\Files_External\Service\BackendService
1702
+     */
1703
+    public function getStoragesBackendService() {
1704
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1705
+    }
1706
+
1707
+    /**
1708
+     * Not a public API as of 8.2, wait for 9.0
1709
+     *
1710
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1711
+     */
1712
+    public function getGlobalStoragesService() {
1713
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1714
+    }
1715
+
1716
+    /**
1717
+     * Not a public API as of 8.2, wait for 9.0
1718
+     *
1719
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1720
+     */
1721
+    public function getUserGlobalStoragesService() {
1722
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1723
+    }
1724
+
1725
+    /**
1726
+     * Not a public API as of 8.2, wait for 9.0
1727
+     *
1728
+     * @return \OCA\Files_External\Service\UserStoragesService
1729
+     */
1730
+    public function getUserStoragesService() {
1731
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1732
+    }
1733
+
1734
+    /**
1735
+     * @return \OCP\Share\IManager
1736
+     */
1737
+    public function getShareManager() {
1738
+        return $this->query('ShareManager');
1739
+    }
1740
+
1741
+    /**
1742
+     * Returns the LDAP Provider
1743
+     *
1744
+     * @return \OCP\LDAP\ILDAPProvider
1745
+     */
1746
+    public function getLDAPProvider() {
1747
+        return $this->query('LDAPProvider');
1748
+    }
1749
+
1750
+    /**
1751
+     * @return \OCP\Settings\IManager
1752
+     */
1753
+    public function getSettingsManager() {
1754
+        return $this->query('SettingsManager');
1755
+    }
1756
+
1757
+    /**
1758
+     * @return \OCP\Files\IAppData
1759
+     */
1760
+    public function getAppDataDir($app) {
1761
+        /** @var \OC\Files\AppData\Factory $factory */
1762
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1763
+        return $factory->get($app);
1764
+    }
1765
+
1766
+    /**
1767
+     * @return \OCP\Lockdown\ILockdownManager
1768
+     */
1769
+    public function getLockdownManager() {
1770
+        return $this->query('LockdownManager');
1771
+    }
1772
+
1773
+    /**
1774
+     * @return \OCP\Federation\ICloudIdManager
1775
+     */
1776
+    public function getCloudIdManager() {
1777
+        return $this->query(ICloudIdManager::class);
1778
+    }
1779 1779
 }
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 
150 150
 
151
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
151
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
152 152
 			return new PreviewManager(
153 153
 				$c->getConfig(),
154 154
 				$c->getRootFolder(),
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
 		});
160 160
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
161 161
 
162
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
162
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
163 163
 			return new \OC\Preview\Watcher(
164 164
 				$c->getAppDataDir('preview')
165 165
 			);
166 166
 		});
167 167
 
168
-		$this->registerService('EncryptionManager', function (Server $c) {
168
+		$this->registerService('EncryptionManager', function(Server $c) {
169 169
 			$view = new View();
170 170
 			$util = new Encryption\Util(
171 171
 				$view,
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 			);
184 184
 		});
185 185
 
186
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
186
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
187 187
 			$util = new Encryption\Util(
188 188
 				new View(),
189 189
 				$c->getUserManager(),
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 			);
198 198
 		});
199 199
 
200
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
200
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
201 201
 			$view = new View();
202 202
 			$util = new Encryption\Util(
203 203
 				$view,
@@ -208,32 +208,32 @@  discard block
 block discarded – undo
208 208
 
209 209
 			return new Encryption\Keys\Storage($view, $util);
210 210
 		});
211
-		$this->registerService('TagMapper', function (Server $c) {
211
+		$this->registerService('TagMapper', function(Server $c) {
212 212
 			return new TagMapper($c->getDatabaseConnection());
213 213
 		});
214 214
 
215
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
215
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
216 216
 			$tagMapper = $c->query('TagMapper');
217 217
 			return new TagManager($tagMapper, $c->getUserSession());
218 218
 		});
219 219
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
220 220
 
221
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
221
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
222 222
 			$config = $c->getConfig();
223 223
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
224 224
 			/** @var \OC\SystemTag\ManagerFactory $factory */
225 225
 			$factory = new $factoryClass($this);
226 226
 			return $factory;
227 227
 		});
228
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
228
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
229 229
 			return $c->query('SystemTagManagerFactory')->getManager();
230 230
 		});
231 231
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
232 232
 
233
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
233
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
234 234
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
235 235
 		});
236
-		$this->registerService('RootFolder', function (Server $c) {
236
+		$this->registerService('RootFolder', function(Server $c) {
237 237
 			$manager = \OC\Files\Filesystem::getMountManager(null);
238 238
 			$view = new View();
239 239
 			$root = new Root(
@@ -261,30 +261,30 @@  discard block
 block discarded – undo
261 261
 		});
262 262
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
263 263
 
264
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
264
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
265 265
 			$config = $c->getConfig();
266 266
 			return new \OC\User\Manager($config);
267 267
 		});
268 268
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
269 269
 
270
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
270
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
271 271
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
272
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
272
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
273 273
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
274 274
 			});
275
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
275
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
276 276
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
277 277
 			});
278
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
278
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
279 279
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
280 280
 			});
281
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
281
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
282 282
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
283 283
 			});
284
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
284
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
285 285
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
286 286
 			});
287
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
288 288
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
289 289
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290 290
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
 			return new Store($session, $logger, $tokenProvider);
305 305
 		});
306 306
 		$this->registerAlias(IStore::class, Store::class);
307
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
307
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
308 308
 			$dbConnection = $c->getDatabaseConnection();
309 309
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
310 310
 		});
311
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
311
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
312 312
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
313 313
 			$crypto = $c->getCrypto();
314 314
 			$config = $c->getConfig();
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 		});
319 319
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
320 320
 
321
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
321
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
322 322
 			$manager = $c->getUserManager();
323 323
 			$session = new \OC\Session\Memory('');
324 324
 			$timeFactory = new TimeFactory();
@@ -331,40 +331,40 @@  discard block
 block discarded – undo
331 331
 			}
332 332
 
333 333
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
334
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
334
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
335 335
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
336 336
 			});
337
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
337
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
338 338
 				/** @var $user \OC\User\User */
339 339
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
340 340
 			});
341
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
341
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
342 342
 				/** @var $user \OC\User\User */
343 343
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
344 344
 			});
345
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
345
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
346 346
 				/** @var $user \OC\User\User */
347 347
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
348 348
 			});
349
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
349
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
350 350
 				/** @var $user \OC\User\User */
351 351
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
352 352
 			});
353
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
353
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
354 354
 				/** @var $user \OC\User\User */
355 355
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
356 356
 			});
357
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
357
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
358 358
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
359 359
 			});
360
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
360
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
361 361
 				/** @var $user \OC\User\User */
362 362
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
363 363
 			});
364
-			$userSession->listen('\OC\User', 'logout', function () {
364
+			$userSession->listen('\OC\User', 'logout', function() {
365 365
 				\OC_Hook::emit('OC_User', 'logout', array());
366 366
 			});
367
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
367
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
368 368
 				/** @var $user \OC\User\User */
369 369
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
370 370
 			});
@@ -372,14 +372,14 @@  discard block
 block discarded – undo
372 372
 		});
373 373
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
374 374
 
375
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
375
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
376 376
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
377 377
 		});
378 378
 
379 379
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
380 380
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
381 381
 
382
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
382
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
383 383
 			return new \OC\AllConfig(
384 384
 				$c->getSystemConfig()
385 385
 			);
@@ -387,17 +387,17 @@  discard block
 block discarded – undo
387 387
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
388 388
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
389 389
 
390
-		$this->registerService('SystemConfig', function ($c) use ($config) {
390
+		$this->registerService('SystemConfig', function($c) use ($config) {
391 391
 			return new \OC\SystemConfig($config);
392 392
 		});
393 393
 
394
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
394
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
395 395
 			return new \OC\AppConfig($c->getDatabaseConnection());
396 396
 		});
397 397
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
398 398
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
399 399
 
400
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
400
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
401 401
 			return new \OC\L10N\Factory(
402 402
 				$c->getConfig(),
403 403
 				$c->getRequest(),
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		});
408 408
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
409 409
 
410
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
410
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
411 411
 			$config = $c->getConfig();
412 412
 			$cacheFactory = $c->getMemCacheFactory();
413 413
 			return new \OC\URLGenerator(
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
 		});
418 418
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
419 419
 
420
-		$this->registerService('AppHelper', function ($c) {
420
+		$this->registerService('AppHelper', function($c) {
421 421
 			return new \OC\AppHelper();
422 422
 		});
423
-		$this->registerService(AppFetcher::class, function ($c) {
423
+		$this->registerService(AppFetcher::class, function($c) {
424 424
 			return new AppFetcher(
425 425
 				$this->getAppDataDir('appstore'),
426 426
 				$this->getHTTPClientService(),
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 		});
431 431
 		$this->registerAlias('AppFetcher', AppFetcher::class);
432 432
 
433
-		$this->registerService('CategoryFetcher', function ($c) {
433
+		$this->registerService('CategoryFetcher', function($c) {
434 434
 			return new CategoryFetcher(
435 435
 				$this->getAppDataDir('appstore'),
436 436
 				$this->getHTTPClientService(),
@@ -439,21 +439,21 @@  discard block
 block discarded – undo
439 439
 			);
440 440
 		});
441 441
 
442
-		$this->registerService(\OCP\ICache::class, function ($c) {
442
+		$this->registerService(\OCP\ICache::class, function($c) {
443 443
 			return new Cache\File();
444 444
 		});
445 445
 		$this->registerAlias('UserCache', \OCP\ICache::class);
446 446
 
447
-		$this->registerService(Factory::class, function (Server $c) {
447
+		$this->registerService(Factory::class, function(Server $c) {
448 448
 			$config = $c->getConfig();
449 449
 
450 450
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451 451
 				$v = \OC_App::getAppVersions();
452
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
452
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
453 453
 				$version = implode(',', $v);
454 454
 				$instanceId = \OC_Util::getInstanceId();
455 455
 				$path = \OC::$SERVERROOT;
456
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
456
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
457 457
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458 458
 					$config->getSystemValue('memcache.local', null),
459 459
 					$config->getSystemValue('memcache.distributed', null),
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
 		$this->registerAlias('MemCacheFactory', Factory::class);
471 471
 		$this->registerAlias(ICacheFactory::class, Factory::class);
472 472
 
473
-		$this->registerService('RedisFactory', function (Server $c) {
473
+		$this->registerService('RedisFactory', function(Server $c) {
474 474
 			$systemConfig = $c->getSystemConfig();
475 475
 			return new RedisFactory($systemConfig);
476 476
 		});
477 477
 
478
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
478
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
479 479
 			return new \OC\Activity\Manager(
480 480
 				$c->getRequest(),
481 481
 				$c->getUserSession(),
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 		});
486 486
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
487 487
 
488
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
488
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
489 489
 			return new \OC\Activity\EventMerger(
490 490
 				$c->getL10N('lib')
491 491
 			);
492 492
 		});
493 493
 		$this->registerAlias(IValidator::class, Validator::class);
494 494
 
495
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
495
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
496 496
 			return new AvatarManager(
497 497
 				$c->getUserManager(),
498 498
 				$c->getAppDataDir('avatar'),
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		});
504 504
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
505 505
 
506
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
506
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
507 507
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
508 508
 			$logger = Log::getLogClass($logType);
509 509
 			call_user_func(array($logger, 'init'));
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 		});
513 513
 		$this->registerAlias('Logger', \OCP\ILogger::class);
514 514
 
515
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
515
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
516 516
 			$config = $c->getConfig();
517 517
 			return new \OC\BackgroundJob\JobList(
518 518
 				$c->getDatabaseConnection(),
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		});
523 523
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
524 524
 
525
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
525
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
526 526
 			$cacheFactory = $c->getMemCacheFactory();
527 527
 			$logger = $c->getLogger();
528 528
 			if ($cacheFactory->isAvailable()) {
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 		});
535 535
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
536 536
 
537
-		$this->registerService(\OCP\ISearch::class, function ($c) {
537
+		$this->registerService(\OCP\ISearch::class, function($c) {
538 538
 			return new Search();
539 539
 		});
540 540
 		$this->registerAlias('Search', \OCP\ISearch::class);
@@ -554,27 +554,27 @@  discard block
 block discarded – undo
554 554
 			);
555 555
 		});
556 556
 
557
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
557
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
558 558
 			return new SecureRandom();
559 559
 		});
560 560
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
561 561
 
562
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
562
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
563 563
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
564 564
 		});
565 565
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
566 566
 
567
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
567
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
568 568
 			return new Hasher($c->getConfig());
569 569
 		});
570 570
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
571 571
 
572
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
572
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
573 573
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
574 574
 		});
575 575
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
576 576
 
577
-		$this->registerService(IDBConnection::class, function (Server $c) {
577
+		$this->registerService(IDBConnection::class, function(Server $c) {
578 578
 			$systemConfig = $c->getSystemConfig();
579 579
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
580 580
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		});
589 589
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
590 590
 
591
-		$this->registerService('HTTPHelper', function (Server $c) {
591
+		$this->registerService('HTTPHelper', function(Server $c) {
592 592
 			$config = $c->getConfig();
593 593
 			return new HTTPHelper(
594 594
 				$config,
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			);
597 597
 		});
598 598
 
599
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
599
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
600 600
 			$user = \OC_User::getUser();
601 601
 			$uid = $user ? $user : null;
602 602
 			return new ClientService(
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 			);
606 606
 		});
607 607
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
608
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
608
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
609 609
 			$eventLogger = new EventLogger();
610 610
 			if ($c->getSystemConfig()->getValue('debug', false)) {
611 611
 				// In debug mode, module is being activated by default
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 		});
616 616
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
617 617
 
618
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
618
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
619 619
 			$queryLogger = new QueryLogger();
620 620
 			if ($c->getSystemConfig()->getValue('debug', false)) {
621 621
 				// In debug mode, module is being activated by default
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 		});
626 626
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
627 627
 
628
-		$this->registerService(TempManager::class, function (Server $c) {
628
+		$this->registerService(TempManager::class, function(Server $c) {
629 629
 			return new TempManager(
630 630
 				$c->getLogger(),
631 631
 				$c->getConfig()
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 		$this->registerAlias('TempManager', TempManager::class);
635 635
 		$this->registerAlias(ITempManager::class, TempManager::class);
636 636
 
637
-		$this->registerService(AppManager::class, function (Server $c) {
637
+		$this->registerService(AppManager::class, function(Server $c) {
638 638
 			return new \OC\App\AppManager(
639 639
 				$c->getUserSession(),
640 640
 				$c->getAppConfig(),
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 		$this->registerAlias('AppManager', AppManager::class);
647 647
 		$this->registerAlias(IAppManager::class, AppManager::class);
648 648
 
649
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
649
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
650 650
 			return new DateTimeZone(
651 651
 				$c->getConfig(),
652 652
 				$c->getSession()
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 		});
655 655
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
656 656
 
657
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
657
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
658 658
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
659 659
 
660 660
 			return new DateTimeFormatter(
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 		});
665 665
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
666 666
 
667
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
667
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
668 668
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
669 669
 			$listener = new UserMountCacheListener($mountCache);
670 670
 			$listener->listen($c->getUserManager());
@@ -672,10 +672,10 @@  discard block
 block discarded – undo
672 672
 		});
673 673
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
674 674
 
675
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
675
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
676 676
 			$loader = \OC\Files\Filesystem::getLoader();
677 677
 			$mountCache = $c->query('UserMountCache');
678
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
678
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
679 679
 
680 680
 			// builtin providers
681 681
 
@@ -688,14 +688,14 @@  discard block
 block discarded – undo
688 688
 		});
689 689
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
690 690
 
691
-		$this->registerService('IniWrapper', function ($c) {
691
+		$this->registerService('IniWrapper', function($c) {
692 692
 			return new IniGetWrapper();
693 693
 		});
694
-		$this->registerService('AsyncCommandBus', function (Server $c) {
694
+		$this->registerService('AsyncCommandBus', function(Server $c) {
695 695
 			$jobList = $c->getJobList();
696 696
 			return new AsyncBus($jobList);
697 697
 		});
698
-		$this->registerService('TrustedDomainHelper', function ($c) {
698
+		$this->registerService('TrustedDomainHelper', function($c) {
699 699
 			return new TrustedDomainHelper($this->getConfig());
700 700
 		});
701 701
 		$this->registerService('Throttler', function(Server $c) {
@@ -706,10 +706,10 @@  discard block
 block discarded – undo
706 706
 				$c->getConfig()
707 707
 			);
708 708
 		});
709
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
709
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
710 710
 			// IConfig and IAppManager requires a working database. This code
711 711
 			// might however be called when ownCloud is not yet setup.
712
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
712
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
713 713
 				$config = $c->getConfig();
714 714
 				$appManager = $c->getAppManager();
715 715
 			} else {
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 					$c->getTempManager()
728 728
 			);
729 729
 		});
730
-		$this->registerService(\OCP\IRequest::class, function ($c) {
730
+		$this->registerService(\OCP\IRequest::class, function($c) {
731 731
 			if (isset($this['urlParams'])) {
732 732
 				$urlParams = $this['urlParams'];
733 733
 			} else {
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 		});
764 764
 		$this->registerAlias('Request', \OCP\IRequest::class);
765 765
 
766
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
766
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
767 767
 			return new Mailer(
768 768
 				$c->getConfig(),
769 769
 				$c->getLogger(),
@@ -777,14 +777,14 @@  discard block
 block discarded – undo
777 777
 		$this->registerService('LDAPProvider', function(Server $c) {
778 778
 			$config = $c->getConfig();
779 779
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
780
-			if(is_null($factoryClass)) {
780
+			if (is_null($factoryClass)) {
781 781
 				throw new \Exception('ldapProviderFactory not set');
782 782
 			}
783 783
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
784 784
 			$factory = new $factoryClass($this);
785 785
 			return $factory->getLDAPProvider();
786 786
 		});
787
-		$this->registerService('LockingProvider', function (Server $c) {
787
+		$this->registerService('LockingProvider', function(Server $c) {
788 788
 			$ini = $c->getIniWrapper();
789 789
 			$config = $c->getConfig();
790 790
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -800,39 +800,39 @@  discard block
 block discarded – undo
800 800
 			return new NoopLockingProvider();
801 801
 		});
802 802
 
803
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
803
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
804 804
 			return new \OC\Files\Mount\Manager();
805 805
 		});
806 806
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
807 807
 
808
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
808
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
809 809
 			return new \OC\Files\Type\Detection(
810 810
 				$c->getURLGenerator(),
811 811
 				\OC::$configDir,
812
-				\OC::$SERVERROOT . '/resources/config/'
812
+				\OC::$SERVERROOT.'/resources/config/'
813 813
 			);
814 814
 		});
815 815
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
816 816
 
817
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
817
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
818 818
 			return new \OC\Files\Type\Loader(
819 819
 				$c->getDatabaseConnection()
820 820
 			);
821 821
 		});
822 822
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
823
-		$this->registerService(BundleFetcher::class, function () {
823
+		$this->registerService(BundleFetcher::class, function() {
824 824
 			return new BundleFetcher($this->getL10N('lib'));
825 825
 		});
826
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
826
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
827 827
 			return new Manager(
828 828
 				$c->query(IValidator::class)
829 829
 			);
830 830
 		});
831 831
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
832 832
 
833
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
833
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
834 834
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
835
-			$manager->registerCapability(function () use ($c) {
835
+			$manager->registerCapability(function() use ($c) {
836 836
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
837 837
 			});
838 838
 			return $manager;
@@ -887,13 +887,13 @@  discard block
 block discarded – undo
887 887
 				$cacheFactory->createLocal('SCSS')
888 888
 			);
889 889
 		});
890
-		$this->registerService(EventDispatcher::class, function () {
890
+		$this->registerService(EventDispatcher::class, function() {
891 891
 			return new EventDispatcher();
892 892
 		});
893 893
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
894 894
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
895 895
 
896
-		$this->registerService('CryptoWrapper', function (Server $c) {
896
+		$this->registerService('CryptoWrapper', function(Server $c) {
897 897
 			// FIXME: Instantiiated here due to cyclic dependency
898 898
 			$request = new Request(
899 899
 				[
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 				$request
919 919
 			);
920 920
 		});
921
-		$this->registerService('CsrfTokenManager', function (Server $c) {
921
+		$this->registerService('CsrfTokenManager', function(Server $c) {
922 922
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
923 923
 
924 924
 			return new CsrfTokenManager(
@@ -926,10 +926,10 @@  discard block
 block discarded – undo
926 926
 				$c->query(SessionStorage::class)
927 927
 			);
928 928
 		});
929
-		$this->registerService(SessionStorage::class, function (Server $c) {
929
+		$this->registerService(SessionStorage::class, function(Server $c) {
930 930
 			return new SessionStorage($c->getSession());
931 931
 		});
932
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
932
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
933 933
 			return new ContentSecurityPolicyManager();
934 934
 		});
935 935
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -980,29 +980,29 @@  discard block
 block discarded – undo
980 980
 			);
981 981
 			return $manager;
982 982
 		});
983
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
983
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
984 984
 			return new \OC\Files\AppData\Factory(
985 985
 				$c->getRootFolder(),
986 986
 				$c->getSystemConfig()
987 987
 			);
988 988
 		});
989 989
 
990
-		$this->registerService('LockdownManager', function (Server $c) {
990
+		$this->registerService('LockdownManager', function(Server $c) {
991 991
 			return new LockdownManager(function() use ($c) {
992 992
 				return $c->getSession();
993 993
 			});
994 994
 		});
995 995
 
996
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
996
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
997 997
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
998 998
 		});
999 999
 
1000
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1000
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
1001 1001
 			return new CloudIdManager();
1002 1002
 		});
1003 1003
 
1004 1004
 		/* To trick DI since we don't extend the DIContainer here */
1005
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1005
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
1006 1006
 			return new CleanPreviewsBackgroundJob(
1007 1007
 				$c->getRootFolder(),
1008 1008
 				$c->getLogger(),
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1018 1018
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1019 1019
 
1020
-		$this->registerService(Defaults::class, function (Server $c) {
1020
+		$this->registerService(Defaults::class, function(Server $c) {
1021 1021
 			return new Defaults(
1022 1022
 				$c->getThemingDefaults()
1023 1023
 			);
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
 	 * @deprecated since 9.2.0 use IAppData
1170 1170
 	 */
1171 1171
 	public function getAppFolder() {
1172
-		$dir = '/' . \OC_App::getCurrentApp();
1172
+		$dir = '/'.\OC_App::getCurrentApp();
1173 1173
 		$root = $this->getRootFolder();
1174 1174
 		if (!$root->nodeExists($dir)) {
1175 1175
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.