Completed
Push — master ( 16d848...22dff1 )
by Lukas
29s
created
lib/private/Server.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
 	 * Get the certificate manager for the user
1144 1144
 	 *
1145 1145
 	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1146
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1146
+	 * @return null|CertificateManager | null if $uid is null and no user is logged in
1147 1147
 	 */
1148 1148
 	public function getCertificateManager($userId = '') {
1149 1149
 		if ($userId === '') {
@@ -1464,6 +1464,7 @@  discard block
 block discarded – undo
1464 1464
 	}
1465 1465
 
1466 1466
 	/**
1467
+	 * @param string $app
1467 1468
 	 * @return \OCP\Files\IAppData
1468 1469
 	 */
1469 1470
 	public function getAppDataDir($app) {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -52,8 +52,6 @@  discard block
 block discarded – undo
52 52
 use OC\Command\AsyncBus;
53 53
 use OC\Contacts\ContactsMenu\ActionFactory;
54 54
 use OC\Diagnostics\EventLogger;
55
-use OC\Diagnostics\NullEventLogger;
56
-use OC\Diagnostics\NullQueryLogger;
57 55
 use OC\Diagnostics\QueryLogger;
58 56
 use OC\Federation\CloudIdManager;
59 57
 use OC\Files\Config\UserMountCache;
@@ -98,7 +96,6 @@  discard block
 block discarded – undo
98 96
 use OC\Tagging\TagMapper;
99 97
 use OC\Template\SCSSCacher;
100 98
 use OCA\Theming\ThemingDefaults;
101
-
102 99
 use OCP\App\IAppManager;
103 100
 use OCP\Defaults;
104 101
 use OCA\Theming\Util;
Please login to merge, or discard this patch.
Indentation   +1629 added lines, -1629 removed lines patch added patch discarded remove patch
@@ -126,1638 +126,1638 @@
 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->registerAlias('AppFetcher', AppFetcher::class);
424
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
425
-
426
-		$this->registerService(\OCP\ICache::class, function ($c) {
427
-			return new Cache\File();
428
-		});
429
-		$this->registerAlias('UserCache', \OCP\ICache::class);
430
-
431
-		$this->registerService(Factory::class, function (Server $c) {
432
-			$config = $c->getConfig();
433
-
434
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
435
-				$v = \OC_App::getAppVersions();
436
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
437
-				$version = implode(',', $v);
438
-				$instanceId = \OC_Util::getInstanceId();
439
-				$path = \OC::$SERVERROOT;
440
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
441
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
442
-					$config->getSystemValue('memcache.local', null),
443
-					$config->getSystemValue('memcache.distributed', null),
444
-					$config->getSystemValue('memcache.locking', null)
445
-				);
446
-			}
447
-
448
-			return new \OC\Memcache\Factory('', $c->getLogger(),
449
-				'\\OC\\Memcache\\ArrayCache',
450
-				'\\OC\\Memcache\\ArrayCache',
451
-				'\\OC\\Memcache\\ArrayCache'
452
-			);
453
-		});
454
-		$this->registerAlias('MemCacheFactory', Factory::class);
455
-		$this->registerAlias(ICacheFactory::class, Factory::class);
456
-
457
-		$this->registerService('RedisFactory', function (Server $c) {
458
-			$systemConfig = $c->getSystemConfig();
459
-			return new RedisFactory($systemConfig);
460
-		});
461
-
462
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
463
-			return new \OC\Activity\Manager(
464
-				$c->getRequest(),
465
-				$c->getUserSession(),
466
-				$c->getConfig(),
467
-				$c->query(IValidator::class)
468
-			);
469
-		});
470
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
471
-
472
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
473
-			return new \OC\Activity\EventMerger(
474
-				$c->getL10N('lib')
475
-			);
476
-		});
477
-		$this->registerAlias(IValidator::class, Validator::class);
478
-
479
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
480
-			return new AvatarManager(
481
-				$c->getUserManager(),
482
-				$c->getAppDataDir('avatar'),
483
-				$c->getL10N('lib'),
484
-				$c->getLogger(),
485
-				$c->getConfig()
486
-			);
487
-		});
488
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
489
-
490
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
491
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
492
-			$logger = Log::getLogClass($logType);
493
-			call_user_func(array($logger, 'init'));
494
-
495
-			return new Log($logger);
496
-		});
497
-		$this->registerAlias('Logger', \OCP\ILogger::class);
498
-
499
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
500
-			$config = $c->getConfig();
501
-			return new \OC\BackgroundJob\JobList(
502
-				$c->getDatabaseConnection(),
503
-				$config,
504
-				new TimeFactory()
505
-			);
506
-		});
507
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
508
-
509
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
510
-			$cacheFactory = $c->getMemCacheFactory();
511
-			$logger = $c->getLogger();
512
-			if ($cacheFactory->isAvailable()) {
513
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
514
-			} else {
515
-				$router = new \OC\Route\Router($logger);
516
-			}
517
-			return $router;
518
-		});
519
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
520
-
521
-		$this->registerService(\OCP\ISearch::class, function ($c) {
522
-			return new Search();
523
-		});
524
-		$this->registerAlias('Search', \OCP\ISearch::class);
525
-
526
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
527
-			return new \OC\Security\RateLimiting\Limiter(
528
-				$this->getUserSession(),
529
-				$this->getRequest(),
530
-				new \OC\AppFramework\Utility\TimeFactory(),
531
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
532
-			);
533
-		});
534
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
535
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
536
-				$this->getMemCacheFactory(),
537
-				new \OC\AppFramework\Utility\TimeFactory()
538
-			);
539
-		});
540
-
541
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
542
-			return new SecureRandom();
543
-		});
544
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
545
-
546
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
547
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
548
-		});
549
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
550
-
551
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
552
-			return new Hasher($c->getConfig());
553
-		});
554
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
555
-
556
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
557
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
558
-		});
559
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
560
-
561
-		$this->registerService(IDBConnection::class, function (Server $c) {
562
-			$systemConfig = $c->getSystemConfig();
563
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
564
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
565
-			if (!$factory->isValidType($type)) {
566
-				throw new \OC\DatabaseException('Invalid database type');
567
-			}
568
-			$connectionParams = $factory->createConnectionParams();
569
-			$connection = $factory->getConnection($type, $connectionParams);
570
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
571
-			return $connection;
572
-		});
573
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
574
-
575
-		$this->registerService('HTTPHelper', function (Server $c) {
576
-			$config = $c->getConfig();
577
-			return new HTTPHelper(
578
-				$config,
579
-				$c->getHTTPClientService()
580
-			);
581
-		});
582
-
583
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
584
-			$user = \OC_User::getUser();
585
-			$uid = $user ? $user : null;
586
-			return new ClientService(
587
-				$c->getConfig(),
588
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
589
-			);
590
-		});
591
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
592
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
593
-			$eventLogger = new EventLogger();
594
-			if ($c->getSystemConfig()->getValue('debug', false)) {
595
-				// In debug mode, module is being activated by default
596
-				$eventLogger->activate();
597
-			}
598
-			return $eventLogger;
599
-		});
600
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
601
-
602
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
603
-			$queryLogger = new QueryLogger();
604
-			if ($c->getSystemConfig()->getValue('debug', false)) {
605
-				// In debug mode, module is being activated by default
606
-				$queryLogger->activate();
607
-			}
608
-			return $queryLogger;
609
-		});
610
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
611
-
612
-		$this->registerService(TempManager::class, function (Server $c) {
613
-			return new TempManager(
614
-				$c->getLogger(),
615
-				$c->getConfig()
616
-			);
617
-		});
618
-		$this->registerAlias('TempManager', TempManager::class);
619
-		$this->registerAlias(ITempManager::class, TempManager::class);
620
-
621
-		$this->registerService(AppManager::class, function (Server $c) {
622
-			return new \OC\App\AppManager(
623
-				$c->getUserSession(),
624
-				$c->getAppConfig(),
625
-				$c->getGroupManager(),
626
-				$c->getMemCacheFactory(),
627
-				$c->getEventDispatcher()
628
-			);
629
-		});
630
-		$this->registerAlias('AppManager', AppManager::class);
631
-		$this->registerAlias(IAppManager::class, AppManager::class);
632
-
633
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
634
-			return new DateTimeZone(
635
-				$c->getConfig(),
636
-				$c->getSession()
637
-			);
638
-		});
639
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
640
-
641
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
642
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
643
-
644
-			return new DateTimeFormatter(
645
-				$c->getDateTimeZone()->getTimeZone(),
646
-				$c->getL10N('lib', $language)
647
-			);
648
-		});
649
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
650
-
651
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
652
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
653
-			$listener = new UserMountCacheListener($mountCache);
654
-			$listener->listen($c->getUserManager());
655
-			return $mountCache;
656
-		});
657
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
658
-
659
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
660
-			$loader = \OC\Files\Filesystem::getLoader();
661
-			$mountCache = $c->query('UserMountCache');
662
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
663
-
664
-			// builtin providers
665
-
666
-			$config = $c->getConfig();
667
-			$manager->registerProvider(new CacheMountProvider($config));
668
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
669
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
670
-
671
-			return $manager;
672
-		});
673
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
674
-
675
-		$this->registerService('IniWrapper', function ($c) {
676
-			return new IniGetWrapper();
677
-		});
678
-		$this->registerService('AsyncCommandBus', function (Server $c) {
679
-			$jobList = $c->getJobList();
680
-			return new AsyncBus($jobList);
681
-		});
682
-		$this->registerService('TrustedDomainHelper', function ($c) {
683
-			return new TrustedDomainHelper($this->getConfig());
684
-		});
685
-		$this->registerService('Throttler', function(Server $c) {
686
-			return new Throttler(
687
-				$c->getDatabaseConnection(),
688
-				new TimeFactory(),
689
-				$c->getLogger(),
690
-				$c->getConfig()
691
-			);
692
-		});
693
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
694
-			// IConfig and IAppManager requires a working database. This code
695
-			// might however be called when ownCloud is not yet setup.
696
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
697
-				$config = $c->getConfig();
698
-				$appManager = $c->getAppManager();
699
-			} else {
700
-				$config = null;
701
-				$appManager = null;
702
-			}
703
-
704
-			return new Checker(
705
-					new EnvironmentHelper(),
706
-					new FileAccessHelper(),
707
-					new AppLocator(),
708
-					$config,
709
-					$c->getMemCacheFactory(),
710
-					$appManager,
711
-					$c->getTempManager()
712
-			);
713
-		});
714
-		$this->registerService(\OCP\IRequest::class, function ($c) {
715
-			if (isset($this['urlParams'])) {
716
-				$urlParams = $this['urlParams'];
717
-			} else {
718
-				$urlParams = [];
719
-			}
720
-
721
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
722
-				&& in_array('fakeinput', stream_get_wrappers())
723
-			) {
724
-				$stream = 'fakeinput://data';
725
-			} else {
726
-				$stream = 'php://input';
727
-			}
728
-
729
-			return new Request(
730
-				[
731
-					'get' => $_GET,
732
-					'post' => $_POST,
733
-					'files' => $_FILES,
734
-					'server' => $_SERVER,
735
-					'env' => $_ENV,
736
-					'cookies' => $_COOKIE,
737
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
738
-						? $_SERVER['REQUEST_METHOD']
739
-						: null,
740
-					'urlParams' => $urlParams,
741
-				],
742
-				$this->getSecureRandom(),
743
-				$this->getConfig(),
744
-				$this->getCsrfTokenManager(),
745
-				$stream
746
-			);
747
-		});
748
-		$this->registerAlias('Request', \OCP\IRequest::class);
749
-
750
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
751
-			return new Mailer(
752
-				$c->getConfig(),
753
-				$c->getLogger(),
754
-				$c->query(Defaults::class),
755
-				$c->getURLGenerator(),
756
-				$c->getL10N('lib')
757
-			);
758
-		});
759
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
760
-
761
-		$this->registerService('LDAPProvider', function(Server $c) {
762
-			$config = $c->getConfig();
763
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
764
-			if(is_null($factoryClass)) {
765
-				throw new \Exception('ldapProviderFactory not set');
766
-			}
767
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
768
-			$factory = new $factoryClass($this);
769
-			return $factory->getLDAPProvider();
770
-		});
771
-		$this->registerService('LockingProvider', function (Server $c) {
772
-			$ini = $c->getIniWrapper();
773
-			$config = $c->getConfig();
774
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
775
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
776
-				/** @var \OC\Memcache\Factory $memcacheFactory */
777
-				$memcacheFactory = $c->getMemCacheFactory();
778
-				$memcache = $memcacheFactory->createLocking('lock');
779
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
780
-					return new MemcacheLockingProvider($memcache, $ttl);
781
-				}
782
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
783
-			}
784
-			return new NoopLockingProvider();
785
-		});
786
-
787
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
788
-			return new \OC\Files\Mount\Manager();
789
-		});
790
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
791
-
792
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
793
-			return new \OC\Files\Type\Detection(
794
-				$c->getURLGenerator(),
795
-				\OC::$configDir,
796
-				\OC::$SERVERROOT . '/resources/config/'
797
-			);
798
-		});
799
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
800
-
801
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
802
-			return new \OC\Files\Type\Loader(
803
-				$c->getDatabaseConnection()
804
-			);
805
-		});
806
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
807
-		$this->registerService(BundleFetcher::class, function () {
808
-			return new BundleFetcher($this->getL10N('lib'));
809
-		});
810
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
811
-			return new Manager(
812
-				$c->query(IValidator::class)
813
-			);
814
-		});
815
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
816
-
817
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
818
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
819
-			$manager->registerCapability(function () use ($c) {
820
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
821
-			});
822
-			return $manager;
823
-		});
824
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
825
-
826
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
827
-			$config = $c->getConfig();
828
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
829
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
830
-			$factory = new $factoryClass($this);
831
-			return $factory->getManager();
832
-		});
833
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
834
-
835
-		$this->registerService('ThemingDefaults', function(Server $c) {
836
-			/*
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->registerAlias('AppFetcher', AppFetcher::class);
424
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
425
+
426
+        $this->registerService(\OCP\ICache::class, function ($c) {
427
+            return new Cache\File();
428
+        });
429
+        $this->registerAlias('UserCache', \OCP\ICache::class);
430
+
431
+        $this->registerService(Factory::class, function (Server $c) {
432
+            $config = $c->getConfig();
433
+
434
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
435
+                $v = \OC_App::getAppVersions();
436
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
437
+                $version = implode(',', $v);
438
+                $instanceId = \OC_Util::getInstanceId();
439
+                $path = \OC::$SERVERROOT;
440
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
441
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
442
+                    $config->getSystemValue('memcache.local', null),
443
+                    $config->getSystemValue('memcache.distributed', null),
444
+                    $config->getSystemValue('memcache.locking', null)
445
+                );
446
+            }
447
+
448
+            return new \OC\Memcache\Factory('', $c->getLogger(),
449
+                '\\OC\\Memcache\\ArrayCache',
450
+                '\\OC\\Memcache\\ArrayCache',
451
+                '\\OC\\Memcache\\ArrayCache'
452
+            );
453
+        });
454
+        $this->registerAlias('MemCacheFactory', Factory::class);
455
+        $this->registerAlias(ICacheFactory::class, Factory::class);
456
+
457
+        $this->registerService('RedisFactory', function (Server $c) {
458
+            $systemConfig = $c->getSystemConfig();
459
+            return new RedisFactory($systemConfig);
460
+        });
461
+
462
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
463
+            return new \OC\Activity\Manager(
464
+                $c->getRequest(),
465
+                $c->getUserSession(),
466
+                $c->getConfig(),
467
+                $c->query(IValidator::class)
468
+            );
469
+        });
470
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
471
+
472
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
473
+            return new \OC\Activity\EventMerger(
474
+                $c->getL10N('lib')
475
+            );
476
+        });
477
+        $this->registerAlias(IValidator::class, Validator::class);
478
+
479
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
480
+            return new AvatarManager(
481
+                $c->getUserManager(),
482
+                $c->getAppDataDir('avatar'),
483
+                $c->getL10N('lib'),
484
+                $c->getLogger(),
485
+                $c->getConfig()
486
+            );
487
+        });
488
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
489
+
490
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
491
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
492
+            $logger = Log::getLogClass($logType);
493
+            call_user_func(array($logger, 'init'));
494
+
495
+            return new Log($logger);
496
+        });
497
+        $this->registerAlias('Logger', \OCP\ILogger::class);
498
+
499
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
500
+            $config = $c->getConfig();
501
+            return new \OC\BackgroundJob\JobList(
502
+                $c->getDatabaseConnection(),
503
+                $config,
504
+                new TimeFactory()
505
+            );
506
+        });
507
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
508
+
509
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
510
+            $cacheFactory = $c->getMemCacheFactory();
511
+            $logger = $c->getLogger();
512
+            if ($cacheFactory->isAvailable()) {
513
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
514
+            } else {
515
+                $router = new \OC\Route\Router($logger);
516
+            }
517
+            return $router;
518
+        });
519
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
520
+
521
+        $this->registerService(\OCP\ISearch::class, function ($c) {
522
+            return new Search();
523
+        });
524
+        $this->registerAlias('Search', \OCP\ISearch::class);
525
+
526
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
527
+            return new \OC\Security\RateLimiting\Limiter(
528
+                $this->getUserSession(),
529
+                $this->getRequest(),
530
+                new \OC\AppFramework\Utility\TimeFactory(),
531
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
532
+            );
533
+        });
534
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
535
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
536
+                $this->getMemCacheFactory(),
537
+                new \OC\AppFramework\Utility\TimeFactory()
538
+            );
539
+        });
540
+
541
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
542
+            return new SecureRandom();
543
+        });
544
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
545
+
546
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
547
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
548
+        });
549
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
550
+
551
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
552
+            return new Hasher($c->getConfig());
553
+        });
554
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
555
+
556
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
557
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
558
+        });
559
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
560
+
561
+        $this->registerService(IDBConnection::class, function (Server $c) {
562
+            $systemConfig = $c->getSystemConfig();
563
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
564
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
565
+            if (!$factory->isValidType($type)) {
566
+                throw new \OC\DatabaseException('Invalid database type');
567
+            }
568
+            $connectionParams = $factory->createConnectionParams();
569
+            $connection = $factory->getConnection($type, $connectionParams);
570
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
571
+            return $connection;
572
+        });
573
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
574
+
575
+        $this->registerService('HTTPHelper', function (Server $c) {
576
+            $config = $c->getConfig();
577
+            return new HTTPHelper(
578
+                $config,
579
+                $c->getHTTPClientService()
580
+            );
581
+        });
582
+
583
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
584
+            $user = \OC_User::getUser();
585
+            $uid = $user ? $user : null;
586
+            return new ClientService(
587
+                $c->getConfig(),
588
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
589
+            );
590
+        });
591
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
592
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
593
+            $eventLogger = new EventLogger();
594
+            if ($c->getSystemConfig()->getValue('debug', false)) {
595
+                // In debug mode, module is being activated by default
596
+                $eventLogger->activate();
597
+            }
598
+            return $eventLogger;
599
+        });
600
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
601
+
602
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
603
+            $queryLogger = new QueryLogger();
604
+            if ($c->getSystemConfig()->getValue('debug', false)) {
605
+                // In debug mode, module is being activated by default
606
+                $queryLogger->activate();
607
+            }
608
+            return $queryLogger;
609
+        });
610
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
611
+
612
+        $this->registerService(TempManager::class, function (Server $c) {
613
+            return new TempManager(
614
+                $c->getLogger(),
615
+                $c->getConfig()
616
+            );
617
+        });
618
+        $this->registerAlias('TempManager', TempManager::class);
619
+        $this->registerAlias(ITempManager::class, TempManager::class);
620
+
621
+        $this->registerService(AppManager::class, function (Server $c) {
622
+            return new \OC\App\AppManager(
623
+                $c->getUserSession(),
624
+                $c->getAppConfig(),
625
+                $c->getGroupManager(),
626
+                $c->getMemCacheFactory(),
627
+                $c->getEventDispatcher()
628
+            );
629
+        });
630
+        $this->registerAlias('AppManager', AppManager::class);
631
+        $this->registerAlias(IAppManager::class, AppManager::class);
632
+
633
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
634
+            return new DateTimeZone(
635
+                $c->getConfig(),
636
+                $c->getSession()
637
+            );
638
+        });
639
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
640
+
641
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
642
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
643
+
644
+            return new DateTimeFormatter(
645
+                $c->getDateTimeZone()->getTimeZone(),
646
+                $c->getL10N('lib', $language)
647
+            );
648
+        });
649
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
650
+
651
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
652
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
653
+            $listener = new UserMountCacheListener($mountCache);
654
+            $listener->listen($c->getUserManager());
655
+            return $mountCache;
656
+        });
657
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
658
+
659
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
660
+            $loader = \OC\Files\Filesystem::getLoader();
661
+            $mountCache = $c->query('UserMountCache');
662
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
663
+
664
+            // builtin providers
665
+
666
+            $config = $c->getConfig();
667
+            $manager->registerProvider(new CacheMountProvider($config));
668
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
669
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
670
+
671
+            return $manager;
672
+        });
673
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
674
+
675
+        $this->registerService('IniWrapper', function ($c) {
676
+            return new IniGetWrapper();
677
+        });
678
+        $this->registerService('AsyncCommandBus', function (Server $c) {
679
+            $jobList = $c->getJobList();
680
+            return new AsyncBus($jobList);
681
+        });
682
+        $this->registerService('TrustedDomainHelper', function ($c) {
683
+            return new TrustedDomainHelper($this->getConfig());
684
+        });
685
+        $this->registerService('Throttler', function(Server $c) {
686
+            return new Throttler(
687
+                $c->getDatabaseConnection(),
688
+                new TimeFactory(),
689
+                $c->getLogger(),
690
+                $c->getConfig()
691
+            );
692
+        });
693
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
694
+            // IConfig and IAppManager requires a working database. This code
695
+            // might however be called when ownCloud is not yet setup.
696
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
697
+                $config = $c->getConfig();
698
+                $appManager = $c->getAppManager();
699
+            } else {
700
+                $config = null;
701
+                $appManager = null;
702
+            }
703
+
704
+            return new Checker(
705
+                    new EnvironmentHelper(),
706
+                    new FileAccessHelper(),
707
+                    new AppLocator(),
708
+                    $config,
709
+                    $c->getMemCacheFactory(),
710
+                    $appManager,
711
+                    $c->getTempManager()
712
+            );
713
+        });
714
+        $this->registerService(\OCP\IRequest::class, function ($c) {
715
+            if (isset($this['urlParams'])) {
716
+                $urlParams = $this['urlParams'];
717
+            } else {
718
+                $urlParams = [];
719
+            }
720
+
721
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
722
+                && in_array('fakeinput', stream_get_wrappers())
723
+            ) {
724
+                $stream = 'fakeinput://data';
725
+            } else {
726
+                $stream = 'php://input';
727
+            }
728
+
729
+            return new Request(
730
+                [
731
+                    'get' => $_GET,
732
+                    'post' => $_POST,
733
+                    'files' => $_FILES,
734
+                    'server' => $_SERVER,
735
+                    'env' => $_ENV,
736
+                    'cookies' => $_COOKIE,
737
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
738
+                        ? $_SERVER['REQUEST_METHOD']
739
+                        : null,
740
+                    'urlParams' => $urlParams,
741
+                ],
742
+                $this->getSecureRandom(),
743
+                $this->getConfig(),
744
+                $this->getCsrfTokenManager(),
745
+                $stream
746
+            );
747
+        });
748
+        $this->registerAlias('Request', \OCP\IRequest::class);
749
+
750
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
751
+            return new Mailer(
752
+                $c->getConfig(),
753
+                $c->getLogger(),
754
+                $c->query(Defaults::class),
755
+                $c->getURLGenerator(),
756
+                $c->getL10N('lib')
757
+            );
758
+        });
759
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
760
+
761
+        $this->registerService('LDAPProvider', function(Server $c) {
762
+            $config = $c->getConfig();
763
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
764
+            if(is_null($factoryClass)) {
765
+                throw new \Exception('ldapProviderFactory not set');
766
+            }
767
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
768
+            $factory = new $factoryClass($this);
769
+            return $factory->getLDAPProvider();
770
+        });
771
+        $this->registerService('LockingProvider', function (Server $c) {
772
+            $ini = $c->getIniWrapper();
773
+            $config = $c->getConfig();
774
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
775
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
776
+                /** @var \OC\Memcache\Factory $memcacheFactory */
777
+                $memcacheFactory = $c->getMemCacheFactory();
778
+                $memcache = $memcacheFactory->createLocking('lock');
779
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
780
+                    return new MemcacheLockingProvider($memcache, $ttl);
781
+                }
782
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
783
+            }
784
+            return new NoopLockingProvider();
785
+        });
786
+
787
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
788
+            return new \OC\Files\Mount\Manager();
789
+        });
790
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
791
+
792
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
793
+            return new \OC\Files\Type\Detection(
794
+                $c->getURLGenerator(),
795
+                \OC::$configDir,
796
+                \OC::$SERVERROOT . '/resources/config/'
797
+            );
798
+        });
799
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
800
+
801
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
802
+            return new \OC\Files\Type\Loader(
803
+                $c->getDatabaseConnection()
804
+            );
805
+        });
806
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
807
+        $this->registerService(BundleFetcher::class, function () {
808
+            return new BundleFetcher($this->getL10N('lib'));
809
+        });
810
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
811
+            return new Manager(
812
+                $c->query(IValidator::class)
813
+            );
814
+        });
815
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
816
+
817
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
818
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
819
+            $manager->registerCapability(function () use ($c) {
820
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
821
+            });
822
+            return $manager;
823
+        });
824
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
825
+
826
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
827
+            $config = $c->getConfig();
828
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
829
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
830
+            $factory = new $factoryClass($this);
831
+            return $factory->getManager();
832
+        });
833
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
834
+
835
+        $this->registerService('ThemingDefaults', function(Server $c) {
836
+            /*
837 837
 			 * Dark magic for autoloader.
838 838
 			 * If we do a class_exists it will try to load the class which will
839 839
 			 * make composer cache the result. Resulting in errors when enabling
840 840
 			 * the theming app.
841 841
 			 */
842
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
843
-			if (isset($prefixes['OCA\\Theming\\'])) {
844
-				$classExists = true;
845
-			} else {
846
-				$classExists = false;
847
-			}
848
-
849
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
850
-				return new ThemingDefaults(
851
-					$c->getConfig(),
852
-					$c->getL10N('theming'),
853
-					$c->getURLGenerator(),
854
-					$c->getAppDataDir('theming'),
855
-					$c->getMemCacheFactory(),
856
-					new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
857
-				);
858
-			}
859
-			return new \OC_Defaults();
860
-		});
861
-		$this->registerService(SCSSCacher::class, function(Server $c) {
862
-			/** @var Factory $cacheFactory */
863
-			$cacheFactory = $c->query(Factory::class);
864
-			return new SCSSCacher(
865
-				$c->getLogger(),
866
-				$c->query(\OC\Files\AppData\Factory::class),
867
-				$c->getURLGenerator(),
868
-				$c->getConfig(),
869
-				$c->getThemingDefaults(),
870
-				\OC::$SERVERROOT,
871
-				$cacheFactory->create('SCSS')
872
-			);
873
-		});
874
-		$this->registerService(EventDispatcher::class, function () {
875
-			return new EventDispatcher();
876
-		});
877
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
878
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
879
-
880
-		$this->registerService('CryptoWrapper', function (Server $c) {
881
-			// FIXME: Instantiiated here due to cyclic dependency
882
-			$request = new Request(
883
-				[
884
-					'get' => $_GET,
885
-					'post' => $_POST,
886
-					'files' => $_FILES,
887
-					'server' => $_SERVER,
888
-					'env' => $_ENV,
889
-					'cookies' => $_COOKIE,
890
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
891
-						? $_SERVER['REQUEST_METHOD']
892
-						: null,
893
-				],
894
-				$c->getSecureRandom(),
895
-				$c->getConfig()
896
-			);
897
-
898
-			return new CryptoWrapper(
899
-				$c->getConfig(),
900
-				$c->getCrypto(),
901
-				$c->getSecureRandom(),
902
-				$request
903
-			);
904
-		});
905
-		$this->registerService('CsrfTokenManager', function (Server $c) {
906
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
907
-
908
-			return new CsrfTokenManager(
909
-				$tokenGenerator,
910
-				$c->query(SessionStorage::class)
911
-			);
912
-		});
913
-		$this->registerService(SessionStorage::class, function (Server $c) {
914
-			return new SessionStorage($c->getSession());
915
-		});
916
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
917
-			return new ContentSecurityPolicyManager();
918
-		});
919
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
920
-
921
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
922
-			return new ContentSecurityPolicyNonceManager(
923
-				$c->getCsrfTokenManager(),
924
-				$c->getRequest()
925
-			);
926
-		});
927
-
928
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
929
-			$config = $c->getConfig();
930
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
931
-			/** @var \OCP\Share\IProviderFactory $factory */
932
-			$factory = new $factoryClass($this);
933
-
934
-			$manager = new \OC\Share20\Manager(
935
-				$c->getLogger(),
936
-				$c->getConfig(),
937
-				$c->getSecureRandom(),
938
-				$c->getHasher(),
939
-				$c->getMountManager(),
940
-				$c->getGroupManager(),
941
-				$c->getL10N('core'),
942
-				$factory,
943
-				$c->getUserManager(),
944
-				$c->getLazyRootFolder(),
945
-				$c->getEventDispatcher()
946
-			);
947
-
948
-			return $manager;
949
-		});
950
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
951
-
952
-		$this->registerService('SettingsManager', function(Server $c) {
953
-			$manager = new \OC\Settings\Manager(
954
-				$c->getLogger(),
955
-				$c->getDatabaseConnection(),
956
-				$c->getL10N('lib'),
957
-				$c->getConfig(),
958
-				$c->getEncryptionManager(),
959
-				$c->getUserManager(),
960
-				$c->getLockingProvider(),
961
-				$c->getRequest(),
962
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
963
-				$c->getURLGenerator()
964
-			);
965
-			return $manager;
966
-		});
967
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
968
-			return new \OC\Files\AppData\Factory(
969
-				$c->getRootFolder(),
970
-				$c->getSystemConfig()
971
-			);
972
-		});
973
-
974
-		$this->registerService('LockdownManager', function (Server $c) {
975
-			return new LockdownManager(function() use ($c) {
976
-				return $c->getSession();
977
-			});
978
-		});
979
-
980
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
981
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
982
-		});
983
-
984
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
985
-			return new CloudIdManager();
986
-		});
987
-
988
-		/* To trick DI since we don't extend the DIContainer here */
989
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
990
-			return new CleanPreviewsBackgroundJob(
991
-				$c->getRootFolder(),
992
-				$c->getLogger(),
993
-				$c->getJobList(),
994
-				new TimeFactory()
995
-			);
996
-		});
997
-
998
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
999
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1000
-
1001
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1002
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1003
-
1004
-		$this->registerService(Defaults::class, function (Server $c) {
1005
-			return new Defaults(
1006
-				$c->getThemingDefaults()
1007
-			);
1008
-		});
1009
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1010
-
1011
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1012
-			return $c->query(\OCP\IUserSession::class)->getSession();
1013
-		});
1014
-
1015
-		$this->registerService(IShareHelper::class, function(Server $c) {
1016
-			return new ShareHelper(
1017
-				$c->query(\OCP\Share\IManager::class)
1018
-			);
1019
-		});
1020
-	}
1021
-
1022
-	/**
1023
-	 * @return \OCP\Contacts\IManager
1024
-	 */
1025
-	public function getContactsManager() {
1026
-		return $this->query('ContactsManager');
1027
-	}
1028
-
1029
-	/**
1030
-	 * @return \OC\Encryption\Manager
1031
-	 */
1032
-	public function getEncryptionManager() {
1033
-		return $this->query('EncryptionManager');
1034
-	}
1035
-
1036
-	/**
1037
-	 * @return \OC\Encryption\File
1038
-	 */
1039
-	public function getEncryptionFilesHelper() {
1040
-		return $this->query('EncryptionFileHelper');
1041
-	}
1042
-
1043
-	/**
1044
-	 * @return \OCP\Encryption\Keys\IStorage
1045
-	 */
1046
-	public function getEncryptionKeyStorage() {
1047
-		return $this->query('EncryptionKeyStorage');
1048
-	}
1049
-
1050
-	/**
1051
-	 * The current request object holding all information about the request
1052
-	 * currently being processed is returned from this method.
1053
-	 * In case the current execution was not initiated by a web request null is returned
1054
-	 *
1055
-	 * @return \OCP\IRequest
1056
-	 */
1057
-	public function getRequest() {
1058
-		return $this->query('Request');
1059
-	}
1060
-
1061
-	/**
1062
-	 * Returns the preview manager which can create preview images for a given file
1063
-	 *
1064
-	 * @return \OCP\IPreview
1065
-	 */
1066
-	public function getPreviewManager() {
1067
-		return $this->query('PreviewManager');
1068
-	}
1069
-
1070
-	/**
1071
-	 * Returns the tag manager which can get and set tags for different object types
1072
-	 *
1073
-	 * @see \OCP\ITagManager::load()
1074
-	 * @return \OCP\ITagManager
1075
-	 */
1076
-	public function getTagManager() {
1077
-		return $this->query('TagManager');
1078
-	}
1079
-
1080
-	/**
1081
-	 * Returns the system-tag manager
1082
-	 *
1083
-	 * @return \OCP\SystemTag\ISystemTagManager
1084
-	 *
1085
-	 * @since 9.0.0
1086
-	 */
1087
-	public function getSystemTagManager() {
1088
-		return $this->query('SystemTagManager');
1089
-	}
1090
-
1091
-	/**
1092
-	 * Returns the system-tag object mapper
1093
-	 *
1094
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1095
-	 *
1096
-	 * @since 9.0.0
1097
-	 */
1098
-	public function getSystemTagObjectMapper() {
1099
-		return $this->query('SystemTagObjectMapper');
1100
-	}
1101
-
1102
-	/**
1103
-	 * Returns the avatar manager, used for avatar functionality
1104
-	 *
1105
-	 * @return \OCP\IAvatarManager
1106
-	 */
1107
-	public function getAvatarManager() {
1108
-		return $this->query('AvatarManager');
1109
-	}
1110
-
1111
-	/**
1112
-	 * Returns the root folder of ownCloud's data directory
1113
-	 *
1114
-	 * @return \OCP\Files\IRootFolder
1115
-	 */
1116
-	public function getRootFolder() {
1117
-		return $this->query('LazyRootFolder');
1118
-	}
1119
-
1120
-	/**
1121
-	 * Returns the root folder of ownCloud's data directory
1122
-	 * This is the lazy variant so this gets only initialized once it
1123
-	 * is actually used.
1124
-	 *
1125
-	 * @return \OCP\Files\IRootFolder
1126
-	 */
1127
-	public function getLazyRootFolder() {
1128
-		return $this->query('LazyRootFolder');
1129
-	}
1130
-
1131
-	/**
1132
-	 * Returns a view to ownCloud's files folder
1133
-	 *
1134
-	 * @param string $userId user ID
1135
-	 * @return \OCP\Files\Folder|null
1136
-	 */
1137
-	public function getUserFolder($userId = null) {
1138
-		if ($userId === null) {
1139
-			$user = $this->getUserSession()->getUser();
1140
-			if (!$user) {
1141
-				return null;
1142
-			}
1143
-			$userId = $user->getUID();
1144
-		}
1145
-		$root = $this->getRootFolder();
1146
-		return $root->getUserFolder($userId);
1147
-	}
1148
-
1149
-	/**
1150
-	 * Returns an app-specific view in ownClouds data directory
1151
-	 *
1152
-	 * @return \OCP\Files\Folder
1153
-	 * @deprecated since 9.2.0 use IAppData
1154
-	 */
1155
-	public function getAppFolder() {
1156
-		$dir = '/' . \OC_App::getCurrentApp();
1157
-		$root = $this->getRootFolder();
1158
-		if (!$root->nodeExists($dir)) {
1159
-			$folder = $root->newFolder($dir);
1160
-		} else {
1161
-			$folder = $root->get($dir);
1162
-		}
1163
-		return $folder;
1164
-	}
1165
-
1166
-	/**
1167
-	 * @return \OC\User\Manager
1168
-	 */
1169
-	public function getUserManager() {
1170
-		return $this->query('UserManager');
1171
-	}
1172
-
1173
-	/**
1174
-	 * @return \OC\Group\Manager
1175
-	 */
1176
-	public function getGroupManager() {
1177
-		return $this->query('GroupManager');
1178
-	}
1179
-
1180
-	/**
1181
-	 * @return \OC\User\Session
1182
-	 */
1183
-	public function getUserSession() {
1184
-		return $this->query('UserSession');
1185
-	}
1186
-
1187
-	/**
1188
-	 * @return \OCP\ISession
1189
-	 */
1190
-	public function getSession() {
1191
-		return $this->query('UserSession')->getSession();
1192
-	}
1193
-
1194
-	/**
1195
-	 * @param \OCP\ISession $session
1196
-	 */
1197
-	public function setSession(\OCP\ISession $session) {
1198
-		$this->query(SessionStorage::class)->setSession($session);
1199
-		$this->query('UserSession')->setSession($session);
1200
-		$this->query(Store::class)->setSession($session);
1201
-	}
1202
-
1203
-	/**
1204
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1205
-	 */
1206
-	public function getTwoFactorAuthManager() {
1207
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1208
-	}
1209
-
1210
-	/**
1211
-	 * @return \OC\NavigationManager
1212
-	 */
1213
-	public function getNavigationManager() {
1214
-		return $this->query('NavigationManager');
1215
-	}
1216
-
1217
-	/**
1218
-	 * @return \OCP\IConfig
1219
-	 */
1220
-	public function getConfig() {
1221
-		return $this->query('AllConfig');
1222
-	}
1223
-
1224
-	/**
1225
-	 * @internal For internal use only
1226
-	 * @return \OC\SystemConfig
1227
-	 */
1228
-	public function getSystemConfig() {
1229
-		return $this->query('SystemConfig');
1230
-	}
1231
-
1232
-	/**
1233
-	 * Returns the app config manager
1234
-	 *
1235
-	 * @return \OCP\IAppConfig
1236
-	 */
1237
-	public function getAppConfig() {
1238
-		return $this->query('AppConfig');
1239
-	}
1240
-
1241
-	/**
1242
-	 * @return \OCP\L10N\IFactory
1243
-	 */
1244
-	public function getL10NFactory() {
1245
-		return $this->query('L10NFactory');
1246
-	}
1247
-
1248
-	/**
1249
-	 * get an L10N instance
1250
-	 *
1251
-	 * @param string $app appid
1252
-	 * @param string $lang
1253
-	 * @return IL10N
1254
-	 */
1255
-	public function getL10N($app, $lang = null) {
1256
-		return $this->getL10NFactory()->get($app, $lang);
1257
-	}
1258
-
1259
-	/**
1260
-	 * @return \OCP\IURLGenerator
1261
-	 */
1262
-	public function getURLGenerator() {
1263
-		return $this->query('URLGenerator');
1264
-	}
1265
-
1266
-	/**
1267
-	 * @return \OCP\IHelper
1268
-	 */
1269
-	public function getHelper() {
1270
-		return $this->query('AppHelper');
1271
-	}
1272
-
1273
-	/**
1274
-	 * @return AppFetcher
1275
-	 */
1276
-	public function getAppFetcher() {
1277
-		return $this->query(AppFetcher::class);
1278
-	}
1279
-
1280
-	/**
1281
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1282
-	 * getMemCacheFactory() instead.
1283
-	 *
1284
-	 * @return \OCP\ICache
1285
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1286
-	 */
1287
-	public function getCache() {
1288
-		return $this->query('UserCache');
1289
-	}
1290
-
1291
-	/**
1292
-	 * Returns an \OCP\CacheFactory instance
1293
-	 *
1294
-	 * @return \OCP\ICacheFactory
1295
-	 */
1296
-	public function getMemCacheFactory() {
1297
-		return $this->query('MemCacheFactory');
1298
-	}
1299
-
1300
-	/**
1301
-	 * Returns an \OC\RedisFactory instance
1302
-	 *
1303
-	 * @return \OC\RedisFactory
1304
-	 */
1305
-	public function getGetRedisFactory() {
1306
-		return $this->query('RedisFactory');
1307
-	}
1308
-
1309
-
1310
-	/**
1311
-	 * Returns the current session
1312
-	 *
1313
-	 * @return \OCP\IDBConnection
1314
-	 */
1315
-	public function getDatabaseConnection() {
1316
-		return $this->query('DatabaseConnection');
1317
-	}
1318
-
1319
-	/**
1320
-	 * Returns the activity manager
1321
-	 *
1322
-	 * @return \OCP\Activity\IManager
1323
-	 */
1324
-	public function getActivityManager() {
1325
-		return $this->query('ActivityManager');
1326
-	}
1327
-
1328
-	/**
1329
-	 * Returns an job list for controlling background jobs
1330
-	 *
1331
-	 * @return \OCP\BackgroundJob\IJobList
1332
-	 */
1333
-	public function getJobList() {
1334
-		return $this->query('JobList');
1335
-	}
1336
-
1337
-	/**
1338
-	 * Returns a logger instance
1339
-	 *
1340
-	 * @return \OCP\ILogger
1341
-	 */
1342
-	public function getLogger() {
1343
-		return $this->query('Logger');
1344
-	}
1345
-
1346
-	/**
1347
-	 * Returns a router for generating and matching urls
1348
-	 *
1349
-	 * @return \OCP\Route\IRouter
1350
-	 */
1351
-	public function getRouter() {
1352
-		return $this->query('Router');
1353
-	}
1354
-
1355
-	/**
1356
-	 * Returns a search instance
1357
-	 *
1358
-	 * @return \OCP\ISearch
1359
-	 */
1360
-	public function getSearch() {
1361
-		return $this->query('Search');
1362
-	}
1363
-
1364
-	/**
1365
-	 * Returns a SecureRandom instance
1366
-	 *
1367
-	 * @return \OCP\Security\ISecureRandom
1368
-	 */
1369
-	public function getSecureRandom() {
1370
-		return $this->query('SecureRandom');
1371
-	}
1372
-
1373
-	/**
1374
-	 * Returns a Crypto instance
1375
-	 *
1376
-	 * @return \OCP\Security\ICrypto
1377
-	 */
1378
-	public function getCrypto() {
1379
-		return $this->query('Crypto');
1380
-	}
1381
-
1382
-	/**
1383
-	 * Returns a Hasher instance
1384
-	 *
1385
-	 * @return \OCP\Security\IHasher
1386
-	 */
1387
-	public function getHasher() {
1388
-		return $this->query('Hasher');
1389
-	}
1390
-
1391
-	/**
1392
-	 * Returns a CredentialsManager instance
1393
-	 *
1394
-	 * @return \OCP\Security\ICredentialsManager
1395
-	 */
1396
-	public function getCredentialsManager() {
1397
-		return $this->query('CredentialsManager');
1398
-	}
1399
-
1400
-	/**
1401
-	 * Returns an instance of the HTTP helper class
1402
-	 *
1403
-	 * @deprecated Use getHTTPClientService()
1404
-	 * @return \OC\HTTPHelper
1405
-	 */
1406
-	public function getHTTPHelper() {
1407
-		return $this->query('HTTPHelper');
1408
-	}
1409
-
1410
-	/**
1411
-	 * Get the certificate manager for the user
1412
-	 *
1413
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1414
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1415
-	 */
1416
-	public function getCertificateManager($userId = '') {
1417
-		if ($userId === '') {
1418
-			$userSession = $this->getUserSession();
1419
-			$user = $userSession->getUser();
1420
-			if (is_null($user)) {
1421
-				return null;
1422
-			}
1423
-			$userId = $user->getUID();
1424
-		}
1425
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1426
-	}
1427
-
1428
-	/**
1429
-	 * Returns an instance of the HTTP client service
1430
-	 *
1431
-	 * @return \OCP\Http\Client\IClientService
1432
-	 */
1433
-	public function getHTTPClientService() {
1434
-		return $this->query('HttpClientService');
1435
-	}
1436
-
1437
-	/**
1438
-	 * Create a new event source
1439
-	 *
1440
-	 * @return \OCP\IEventSource
1441
-	 */
1442
-	public function createEventSource() {
1443
-		return new \OC_EventSource();
1444
-	}
1445
-
1446
-	/**
1447
-	 * Get the active event logger
1448
-	 *
1449
-	 * The returned logger only logs data when debug mode is enabled
1450
-	 *
1451
-	 * @return \OCP\Diagnostics\IEventLogger
1452
-	 */
1453
-	public function getEventLogger() {
1454
-		return $this->query('EventLogger');
1455
-	}
1456
-
1457
-	/**
1458
-	 * Get the active query logger
1459
-	 *
1460
-	 * The returned logger only logs data when debug mode is enabled
1461
-	 *
1462
-	 * @return \OCP\Diagnostics\IQueryLogger
1463
-	 */
1464
-	public function getQueryLogger() {
1465
-		return $this->query('QueryLogger');
1466
-	}
1467
-
1468
-	/**
1469
-	 * Get the manager for temporary files and folders
1470
-	 *
1471
-	 * @return \OCP\ITempManager
1472
-	 */
1473
-	public function getTempManager() {
1474
-		return $this->query('TempManager');
1475
-	}
1476
-
1477
-	/**
1478
-	 * Get the app manager
1479
-	 *
1480
-	 * @return \OCP\App\IAppManager
1481
-	 */
1482
-	public function getAppManager() {
1483
-		return $this->query('AppManager');
1484
-	}
1485
-
1486
-	/**
1487
-	 * Creates a new mailer
1488
-	 *
1489
-	 * @return \OCP\Mail\IMailer
1490
-	 */
1491
-	public function getMailer() {
1492
-		return $this->query('Mailer');
1493
-	}
1494
-
1495
-	/**
1496
-	 * Get the webroot
1497
-	 *
1498
-	 * @return string
1499
-	 */
1500
-	public function getWebRoot() {
1501
-		return $this->webRoot;
1502
-	}
1503
-
1504
-	/**
1505
-	 * @return \OC\OCSClient
1506
-	 */
1507
-	public function getOcsClient() {
1508
-		return $this->query('OcsClient');
1509
-	}
1510
-
1511
-	/**
1512
-	 * @return \OCP\IDateTimeZone
1513
-	 */
1514
-	public function getDateTimeZone() {
1515
-		return $this->query('DateTimeZone');
1516
-	}
1517
-
1518
-	/**
1519
-	 * @return \OCP\IDateTimeFormatter
1520
-	 */
1521
-	public function getDateTimeFormatter() {
1522
-		return $this->query('DateTimeFormatter');
1523
-	}
1524
-
1525
-	/**
1526
-	 * @return \OCP\Files\Config\IMountProviderCollection
1527
-	 */
1528
-	public function getMountProviderCollection() {
1529
-		return $this->query('MountConfigManager');
1530
-	}
1531
-
1532
-	/**
1533
-	 * Get the IniWrapper
1534
-	 *
1535
-	 * @return IniGetWrapper
1536
-	 */
1537
-	public function getIniWrapper() {
1538
-		return $this->query('IniWrapper');
1539
-	}
1540
-
1541
-	/**
1542
-	 * @return \OCP\Command\IBus
1543
-	 */
1544
-	public function getCommandBus() {
1545
-		return $this->query('AsyncCommandBus');
1546
-	}
1547
-
1548
-	/**
1549
-	 * Get the trusted domain helper
1550
-	 *
1551
-	 * @return TrustedDomainHelper
1552
-	 */
1553
-	public function getTrustedDomainHelper() {
1554
-		return $this->query('TrustedDomainHelper');
1555
-	}
1556
-
1557
-	/**
1558
-	 * Get the locking provider
1559
-	 *
1560
-	 * @return \OCP\Lock\ILockingProvider
1561
-	 * @since 8.1.0
1562
-	 */
1563
-	public function getLockingProvider() {
1564
-		return $this->query('LockingProvider');
1565
-	}
1566
-
1567
-	/**
1568
-	 * @return \OCP\Files\Mount\IMountManager
1569
-	 **/
1570
-	function getMountManager() {
1571
-		return $this->query('MountManager');
1572
-	}
1573
-
1574
-	/** @return \OCP\Files\Config\IUserMountCache */
1575
-	function getUserMountCache() {
1576
-		return $this->query('UserMountCache');
1577
-	}
1578
-
1579
-	/**
1580
-	 * Get the MimeTypeDetector
1581
-	 *
1582
-	 * @return \OCP\Files\IMimeTypeDetector
1583
-	 */
1584
-	public function getMimeTypeDetector() {
1585
-		return $this->query('MimeTypeDetector');
1586
-	}
1587
-
1588
-	/**
1589
-	 * Get the MimeTypeLoader
1590
-	 *
1591
-	 * @return \OCP\Files\IMimeTypeLoader
1592
-	 */
1593
-	public function getMimeTypeLoader() {
1594
-		return $this->query('MimeTypeLoader');
1595
-	}
1596
-
1597
-	/**
1598
-	 * Get the manager of all the capabilities
1599
-	 *
1600
-	 * @return \OC\CapabilitiesManager
1601
-	 */
1602
-	public function getCapabilitiesManager() {
1603
-		return $this->query('CapabilitiesManager');
1604
-	}
1605
-
1606
-	/**
1607
-	 * Get the EventDispatcher
1608
-	 *
1609
-	 * @return EventDispatcherInterface
1610
-	 * @since 8.2.0
1611
-	 */
1612
-	public function getEventDispatcher() {
1613
-		return $this->query('EventDispatcher');
1614
-	}
1615
-
1616
-	/**
1617
-	 * Get the Notification Manager
1618
-	 *
1619
-	 * @return \OCP\Notification\IManager
1620
-	 * @since 8.2.0
1621
-	 */
1622
-	public function getNotificationManager() {
1623
-		return $this->query('NotificationManager');
1624
-	}
1625
-
1626
-	/**
1627
-	 * @return \OCP\Comments\ICommentsManager
1628
-	 */
1629
-	public function getCommentsManager() {
1630
-		return $this->query('CommentsManager');
1631
-	}
1632
-
1633
-	/**
1634
-	 * @return \OCA\Theming\ThemingDefaults
1635
-	 */
1636
-	public function getThemingDefaults() {
1637
-		return $this->query('ThemingDefaults');
1638
-	}
1639
-
1640
-	/**
1641
-	 * @return \OC\IntegrityCheck\Checker
1642
-	 */
1643
-	public function getIntegrityCodeChecker() {
1644
-		return $this->query('IntegrityCodeChecker');
1645
-	}
1646
-
1647
-	/**
1648
-	 * @return \OC\Session\CryptoWrapper
1649
-	 */
1650
-	public function getSessionCryptoWrapper() {
1651
-		return $this->query('CryptoWrapper');
1652
-	}
1653
-
1654
-	/**
1655
-	 * @return CsrfTokenManager
1656
-	 */
1657
-	public function getCsrfTokenManager() {
1658
-		return $this->query('CsrfTokenManager');
1659
-	}
1660
-
1661
-	/**
1662
-	 * @return Throttler
1663
-	 */
1664
-	public function getBruteForceThrottler() {
1665
-		return $this->query('Throttler');
1666
-	}
1667
-
1668
-	/**
1669
-	 * @return IContentSecurityPolicyManager
1670
-	 */
1671
-	public function getContentSecurityPolicyManager() {
1672
-		return $this->query('ContentSecurityPolicyManager');
1673
-	}
1674
-
1675
-	/**
1676
-	 * @return ContentSecurityPolicyNonceManager
1677
-	 */
1678
-	public function getContentSecurityPolicyNonceManager() {
1679
-		return $this->query('ContentSecurityPolicyNonceManager');
1680
-	}
1681
-
1682
-	/**
1683
-	 * Not a public API as of 8.2, wait for 9.0
1684
-	 *
1685
-	 * @return \OCA\Files_External\Service\BackendService
1686
-	 */
1687
-	public function getStoragesBackendService() {
1688
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1689
-	}
1690
-
1691
-	/**
1692
-	 * Not a public API as of 8.2, wait for 9.0
1693
-	 *
1694
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1695
-	 */
1696
-	public function getGlobalStoragesService() {
1697
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1698
-	}
1699
-
1700
-	/**
1701
-	 * Not a public API as of 8.2, wait for 9.0
1702
-	 *
1703
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1704
-	 */
1705
-	public function getUserGlobalStoragesService() {
1706
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1707
-	}
1708
-
1709
-	/**
1710
-	 * Not a public API as of 8.2, wait for 9.0
1711
-	 *
1712
-	 * @return \OCA\Files_External\Service\UserStoragesService
1713
-	 */
1714
-	public function getUserStoragesService() {
1715
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1716
-	}
1717
-
1718
-	/**
1719
-	 * @return \OCP\Share\IManager
1720
-	 */
1721
-	public function getShareManager() {
1722
-		return $this->query('ShareManager');
1723
-	}
1724
-
1725
-	/**
1726
-	 * Returns the LDAP Provider
1727
-	 *
1728
-	 * @return \OCP\LDAP\ILDAPProvider
1729
-	 */
1730
-	public function getLDAPProvider() {
1731
-		return $this->query('LDAPProvider');
1732
-	}
1733
-
1734
-	/**
1735
-	 * @return \OCP\Settings\IManager
1736
-	 */
1737
-	public function getSettingsManager() {
1738
-		return $this->query('SettingsManager');
1739
-	}
1740
-
1741
-	/**
1742
-	 * @return \OCP\Files\IAppData
1743
-	 */
1744
-	public function getAppDataDir($app) {
1745
-		/** @var \OC\Files\AppData\Factory $factory */
1746
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1747
-		return $factory->get($app);
1748
-	}
1749
-
1750
-	/**
1751
-	 * @return \OCP\Lockdown\ILockdownManager
1752
-	 */
1753
-	public function getLockdownManager() {
1754
-		return $this->query('LockdownManager');
1755
-	}
1756
-
1757
-	/**
1758
-	 * @return \OCP\Federation\ICloudIdManager
1759
-	 */
1760
-	public function getCloudIdManager() {
1761
-		return $this->query(ICloudIdManager::class);
1762
-	}
842
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
843
+            if (isset($prefixes['OCA\\Theming\\'])) {
844
+                $classExists = true;
845
+            } else {
846
+                $classExists = false;
847
+            }
848
+
849
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
850
+                return new ThemingDefaults(
851
+                    $c->getConfig(),
852
+                    $c->getL10N('theming'),
853
+                    $c->getURLGenerator(),
854
+                    $c->getAppDataDir('theming'),
855
+                    $c->getMemCacheFactory(),
856
+                    new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
857
+                );
858
+            }
859
+            return new \OC_Defaults();
860
+        });
861
+        $this->registerService(SCSSCacher::class, function(Server $c) {
862
+            /** @var Factory $cacheFactory */
863
+            $cacheFactory = $c->query(Factory::class);
864
+            return new SCSSCacher(
865
+                $c->getLogger(),
866
+                $c->query(\OC\Files\AppData\Factory::class),
867
+                $c->getURLGenerator(),
868
+                $c->getConfig(),
869
+                $c->getThemingDefaults(),
870
+                \OC::$SERVERROOT,
871
+                $cacheFactory->create('SCSS')
872
+            );
873
+        });
874
+        $this->registerService(EventDispatcher::class, function () {
875
+            return new EventDispatcher();
876
+        });
877
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
878
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
879
+
880
+        $this->registerService('CryptoWrapper', function (Server $c) {
881
+            // FIXME: Instantiiated here due to cyclic dependency
882
+            $request = new Request(
883
+                [
884
+                    'get' => $_GET,
885
+                    'post' => $_POST,
886
+                    'files' => $_FILES,
887
+                    'server' => $_SERVER,
888
+                    'env' => $_ENV,
889
+                    'cookies' => $_COOKIE,
890
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
891
+                        ? $_SERVER['REQUEST_METHOD']
892
+                        : null,
893
+                ],
894
+                $c->getSecureRandom(),
895
+                $c->getConfig()
896
+            );
897
+
898
+            return new CryptoWrapper(
899
+                $c->getConfig(),
900
+                $c->getCrypto(),
901
+                $c->getSecureRandom(),
902
+                $request
903
+            );
904
+        });
905
+        $this->registerService('CsrfTokenManager', function (Server $c) {
906
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
907
+
908
+            return new CsrfTokenManager(
909
+                $tokenGenerator,
910
+                $c->query(SessionStorage::class)
911
+            );
912
+        });
913
+        $this->registerService(SessionStorage::class, function (Server $c) {
914
+            return new SessionStorage($c->getSession());
915
+        });
916
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
917
+            return new ContentSecurityPolicyManager();
918
+        });
919
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
920
+
921
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
922
+            return new ContentSecurityPolicyNonceManager(
923
+                $c->getCsrfTokenManager(),
924
+                $c->getRequest()
925
+            );
926
+        });
927
+
928
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
929
+            $config = $c->getConfig();
930
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
931
+            /** @var \OCP\Share\IProviderFactory $factory */
932
+            $factory = new $factoryClass($this);
933
+
934
+            $manager = new \OC\Share20\Manager(
935
+                $c->getLogger(),
936
+                $c->getConfig(),
937
+                $c->getSecureRandom(),
938
+                $c->getHasher(),
939
+                $c->getMountManager(),
940
+                $c->getGroupManager(),
941
+                $c->getL10N('core'),
942
+                $factory,
943
+                $c->getUserManager(),
944
+                $c->getLazyRootFolder(),
945
+                $c->getEventDispatcher()
946
+            );
947
+
948
+            return $manager;
949
+        });
950
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
951
+
952
+        $this->registerService('SettingsManager', function(Server $c) {
953
+            $manager = new \OC\Settings\Manager(
954
+                $c->getLogger(),
955
+                $c->getDatabaseConnection(),
956
+                $c->getL10N('lib'),
957
+                $c->getConfig(),
958
+                $c->getEncryptionManager(),
959
+                $c->getUserManager(),
960
+                $c->getLockingProvider(),
961
+                $c->getRequest(),
962
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
963
+                $c->getURLGenerator()
964
+            );
965
+            return $manager;
966
+        });
967
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
968
+            return new \OC\Files\AppData\Factory(
969
+                $c->getRootFolder(),
970
+                $c->getSystemConfig()
971
+            );
972
+        });
973
+
974
+        $this->registerService('LockdownManager', function (Server $c) {
975
+            return new LockdownManager(function() use ($c) {
976
+                return $c->getSession();
977
+            });
978
+        });
979
+
980
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
981
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
982
+        });
983
+
984
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
985
+            return new CloudIdManager();
986
+        });
987
+
988
+        /* To trick DI since we don't extend the DIContainer here */
989
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
990
+            return new CleanPreviewsBackgroundJob(
991
+                $c->getRootFolder(),
992
+                $c->getLogger(),
993
+                $c->getJobList(),
994
+                new TimeFactory()
995
+            );
996
+        });
997
+
998
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
999
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1000
+
1001
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1002
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1003
+
1004
+        $this->registerService(Defaults::class, function (Server $c) {
1005
+            return new Defaults(
1006
+                $c->getThemingDefaults()
1007
+            );
1008
+        });
1009
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1010
+
1011
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1012
+            return $c->query(\OCP\IUserSession::class)->getSession();
1013
+        });
1014
+
1015
+        $this->registerService(IShareHelper::class, function(Server $c) {
1016
+            return new ShareHelper(
1017
+                $c->query(\OCP\Share\IManager::class)
1018
+            );
1019
+        });
1020
+    }
1021
+
1022
+    /**
1023
+     * @return \OCP\Contacts\IManager
1024
+     */
1025
+    public function getContactsManager() {
1026
+        return $this->query('ContactsManager');
1027
+    }
1028
+
1029
+    /**
1030
+     * @return \OC\Encryption\Manager
1031
+     */
1032
+    public function getEncryptionManager() {
1033
+        return $this->query('EncryptionManager');
1034
+    }
1035
+
1036
+    /**
1037
+     * @return \OC\Encryption\File
1038
+     */
1039
+    public function getEncryptionFilesHelper() {
1040
+        return $this->query('EncryptionFileHelper');
1041
+    }
1042
+
1043
+    /**
1044
+     * @return \OCP\Encryption\Keys\IStorage
1045
+     */
1046
+    public function getEncryptionKeyStorage() {
1047
+        return $this->query('EncryptionKeyStorage');
1048
+    }
1049
+
1050
+    /**
1051
+     * The current request object holding all information about the request
1052
+     * currently being processed is returned from this method.
1053
+     * In case the current execution was not initiated by a web request null is returned
1054
+     *
1055
+     * @return \OCP\IRequest
1056
+     */
1057
+    public function getRequest() {
1058
+        return $this->query('Request');
1059
+    }
1060
+
1061
+    /**
1062
+     * Returns the preview manager which can create preview images for a given file
1063
+     *
1064
+     * @return \OCP\IPreview
1065
+     */
1066
+    public function getPreviewManager() {
1067
+        return $this->query('PreviewManager');
1068
+    }
1069
+
1070
+    /**
1071
+     * Returns the tag manager which can get and set tags for different object types
1072
+     *
1073
+     * @see \OCP\ITagManager::load()
1074
+     * @return \OCP\ITagManager
1075
+     */
1076
+    public function getTagManager() {
1077
+        return $this->query('TagManager');
1078
+    }
1079
+
1080
+    /**
1081
+     * Returns the system-tag manager
1082
+     *
1083
+     * @return \OCP\SystemTag\ISystemTagManager
1084
+     *
1085
+     * @since 9.0.0
1086
+     */
1087
+    public function getSystemTagManager() {
1088
+        return $this->query('SystemTagManager');
1089
+    }
1090
+
1091
+    /**
1092
+     * Returns the system-tag object mapper
1093
+     *
1094
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1095
+     *
1096
+     * @since 9.0.0
1097
+     */
1098
+    public function getSystemTagObjectMapper() {
1099
+        return $this->query('SystemTagObjectMapper');
1100
+    }
1101
+
1102
+    /**
1103
+     * Returns the avatar manager, used for avatar functionality
1104
+     *
1105
+     * @return \OCP\IAvatarManager
1106
+     */
1107
+    public function getAvatarManager() {
1108
+        return $this->query('AvatarManager');
1109
+    }
1110
+
1111
+    /**
1112
+     * Returns the root folder of ownCloud's data directory
1113
+     *
1114
+     * @return \OCP\Files\IRootFolder
1115
+     */
1116
+    public function getRootFolder() {
1117
+        return $this->query('LazyRootFolder');
1118
+    }
1119
+
1120
+    /**
1121
+     * Returns the root folder of ownCloud's data directory
1122
+     * This is the lazy variant so this gets only initialized once it
1123
+     * is actually used.
1124
+     *
1125
+     * @return \OCP\Files\IRootFolder
1126
+     */
1127
+    public function getLazyRootFolder() {
1128
+        return $this->query('LazyRootFolder');
1129
+    }
1130
+
1131
+    /**
1132
+     * Returns a view to ownCloud's files folder
1133
+     *
1134
+     * @param string $userId user ID
1135
+     * @return \OCP\Files\Folder|null
1136
+     */
1137
+    public function getUserFolder($userId = null) {
1138
+        if ($userId === null) {
1139
+            $user = $this->getUserSession()->getUser();
1140
+            if (!$user) {
1141
+                return null;
1142
+            }
1143
+            $userId = $user->getUID();
1144
+        }
1145
+        $root = $this->getRootFolder();
1146
+        return $root->getUserFolder($userId);
1147
+    }
1148
+
1149
+    /**
1150
+     * Returns an app-specific view in ownClouds data directory
1151
+     *
1152
+     * @return \OCP\Files\Folder
1153
+     * @deprecated since 9.2.0 use IAppData
1154
+     */
1155
+    public function getAppFolder() {
1156
+        $dir = '/' . \OC_App::getCurrentApp();
1157
+        $root = $this->getRootFolder();
1158
+        if (!$root->nodeExists($dir)) {
1159
+            $folder = $root->newFolder($dir);
1160
+        } else {
1161
+            $folder = $root->get($dir);
1162
+        }
1163
+        return $folder;
1164
+    }
1165
+
1166
+    /**
1167
+     * @return \OC\User\Manager
1168
+     */
1169
+    public function getUserManager() {
1170
+        return $this->query('UserManager');
1171
+    }
1172
+
1173
+    /**
1174
+     * @return \OC\Group\Manager
1175
+     */
1176
+    public function getGroupManager() {
1177
+        return $this->query('GroupManager');
1178
+    }
1179
+
1180
+    /**
1181
+     * @return \OC\User\Session
1182
+     */
1183
+    public function getUserSession() {
1184
+        return $this->query('UserSession');
1185
+    }
1186
+
1187
+    /**
1188
+     * @return \OCP\ISession
1189
+     */
1190
+    public function getSession() {
1191
+        return $this->query('UserSession')->getSession();
1192
+    }
1193
+
1194
+    /**
1195
+     * @param \OCP\ISession $session
1196
+     */
1197
+    public function setSession(\OCP\ISession $session) {
1198
+        $this->query(SessionStorage::class)->setSession($session);
1199
+        $this->query('UserSession')->setSession($session);
1200
+        $this->query(Store::class)->setSession($session);
1201
+    }
1202
+
1203
+    /**
1204
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1205
+     */
1206
+    public function getTwoFactorAuthManager() {
1207
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1208
+    }
1209
+
1210
+    /**
1211
+     * @return \OC\NavigationManager
1212
+     */
1213
+    public function getNavigationManager() {
1214
+        return $this->query('NavigationManager');
1215
+    }
1216
+
1217
+    /**
1218
+     * @return \OCP\IConfig
1219
+     */
1220
+    public function getConfig() {
1221
+        return $this->query('AllConfig');
1222
+    }
1223
+
1224
+    /**
1225
+     * @internal For internal use only
1226
+     * @return \OC\SystemConfig
1227
+     */
1228
+    public function getSystemConfig() {
1229
+        return $this->query('SystemConfig');
1230
+    }
1231
+
1232
+    /**
1233
+     * Returns the app config manager
1234
+     *
1235
+     * @return \OCP\IAppConfig
1236
+     */
1237
+    public function getAppConfig() {
1238
+        return $this->query('AppConfig');
1239
+    }
1240
+
1241
+    /**
1242
+     * @return \OCP\L10N\IFactory
1243
+     */
1244
+    public function getL10NFactory() {
1245
+        return $this->query('L10NFactory');
1246
+    }
1247
+
1248
+    /**
1249
+     * get an L10N instance
1250
+     *
1251
+     * @param string $app appid
1252
+     * @param string $lang
1253
+     * @return IL10N
1254
+     */
1255
+    public function getL10N($app, $lang = null) {
1256
+        return $this->getL10NFactory()->get($app, $lang);
1257
+    }
1258
+
1259
+    /**
1260
+     * @return \OCP\IURLGenerator
1261
+     */
1262
+    public function getURLGenerator() {
1263
+        return $this->query('URLGenerator');
1264
+    }
1265
+
1266
+    /**
1267
+     * @return \OCP\IHelper
1268
+     */
1269
+    public function getHelper() {
1270
+        return $this->query('AppHelper');
1271
+    }
1272
+
1273
+    /**
1274
+     * @return AppFetcher
1275
+     */
1276
+    public function getAppFetcher() {
1277
+        return $this->query(AppFetcher::class);
1278
+    }
1279
+
1280
+    /**
1281
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1282
+     * getMemCacheFactory() instead.
1283
+     *
1284
+     * @return \OCP\ICache
1285
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1286
+     */
1287
+    public function getCache() {
1288
+        return $this->query('UserCache');
1289
+    }
1290
+
1291
+    /**
1292
+     * Returns an \OCP\CacheFactory instance
1293
+     *
1294
+     * @return \OCP\ICacheFactory
1295
+     */
1296
+    public function getMemCacheFactory() {
1297
+        return $this->query('MemCacheFactory');
1298
+    }
1299
+
1300
+    /**
1301
+     * Returns an \OC\RedisFactory instance
1302
+     *
1303
+     * @return \OC\RedisFactory
1304
+     */
1305
+    public function getGetRedisFactory() {
1306
+        return $this->query('RedisFactory');
1307
+    }
1308
+
1309
+
1310
+    /**
1311
+     * Returns the current session
1312
+     *
1313
+     * @return \OCP\IDBConnection
1314
+     */
1315
+    public function getDatabaseConnection() {
1316
+        return $this->query('DatabaseConnection');
1317
+    }
1318
+
1319
+    /**
1320
+     * Returns the activity manager
1321
+     *
1322
+     * @return \OCP\Activity\IManager
1323
+     */
1324
+    public function getActivityManager() {
1325
+        return $this->query('ActivityManager');
1326
+    }
1327
+
1328
+    /**
1329
+     * Returns an job list for controlling background jobs
1330
+     *
1331
+     * @return \OCP\BackgroundJob\IJobList
1332
+     */
1333
+    public function getJobList() {
1334
+        return $this->query('JobList');
1335
+    }
1336
+
1337
+    /**
1338
+     * Returns a logger instance
1339
+     *
1340
+     * @return \OCP\ILogger
1341
+     */
1342
+    public function getLogger() {
1343
+        return $this->query('Logger');
1344
+    }
1345
+
1346
+    /**
1347
+     * Returns a router for generating and matching urls
1348
+     *
1349
+     * @return \OCP\Route\IRouter
1350
+     */
1351
+    public function getRouter() {
1352
+        return $this->query('Router');
1353
+    }
1354
+
1355
+    /**
1356
+     * Returns a search instance
1357
+     *
1358
+     * @return \OCP\ISearch
1359
+     */
1360
+    public function getSearch() {
1361
+        return $this->query('Search');
1362
+    }
1363
+
1364
+    /**
1365
+     * Returns a SecureRandom instance
1366
+     *
1367
+     * @return \OCP\Security\ISecureRandom
1368
+     */
1369
+    public function getSecureRandom() {
1370
+        return $this->query('SecureRandom');
1371
+    }
1372
+
1373
+    /**
1374
+     * Returns a Crypto instance
1375
+     *
1376
+     * @return \OCP\Security\ICrypto
1377
+     */
1378
+    public function getCrypto() {
1379
+        return $this->query('Crypto');
1380
+    }
1381
+
1382
+    /**
1383
+     * Returns a Hasher instance
1384
+     *
1385
+     * @return \OCP\Security\IHasher
1386
+     */
1387
+    public function getHasher() {
1388
+        return $this->query('Hasher');
1389
+    }
1390
+
1391
+    /**
1392
+     * Returns a CredentialsManager instance
1393
+     *
1394
+     * @return \OCP\Security\ICredentialsManager
1395
+     */
1396
+    public function getCredentialsManager() {
1397
+        return $this->query('CredentialsManager');
1398
+    }
1399
+
1400
+    /**
1401
+     * Returns an instance of the HTTP helper class
1402
+     *
1403
+     * @deprecated Use getHTTPClientService()
1404
+     * @return \OC\HTTPHelper
1405
+     */
1406
+    public function getHTTPHelper() {
1407
+        return $this->query('HTTPHelper');
1408
+    }
1409
+
1410
+    /**
1411
+     * Get the certificate manager for the user
1412
+     *
1413
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1414
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1415
+     */
1416
+    public function getCertificateManager($userId = '') {
1417
+        if ($userId === '') {
1418
+            $userSession = $this->getUserSession();
1419
+            $user = $userSession->getUser();
1420
+            if (is_null($user)) {
1421
+                return null;
1422
+            }
1423
+            $userId = $user->getUID();
1424
+        }
1425
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1426
+    }
1427
+
1428
+    /**
1429
+     * Returns an instance of the HTTP client service
1430
+     *
1431
+     * @return \OCP\Http\Client\IClientService
1432
+     */
1433
+    public function getHTTPClientService() {
1434
+        return $this->query('HttpClientService');
1435
+    }
1436
+
1437
+    /**
1438
+     * Create a new event source
1439
+     *
1440
+     * @return \OCP\IEventSource
1441
+     */
1442
+    public function createEventSource() {
1443
+        return new \OC_EventSource();
1444
+    }
1445
+
1446
+    /**
1447
+     * Get the active event logger
1448
+     *
1449
+     * The returned logger only logs data when debug mode is enabled
1450
+     *
1451
+     * @return \OCP\Diagnostics\IEventLogger
1452
+     */
1453
+    public function getEventLogger() {
1454
+        return $this->query('EventLogger');
1455
+    }
1456
+
1457
+    /**
1458
+     * Get the active query logger
1459
+     *
1460
+     * The returned logger only logs data when debug mode is enabled
1461
+     *
1462
+     * @return \OCP\Diagnostics\IQueryLogger
1463
+     */
1464
+    public function getQueryLogger() {
1465
+        return $this->query('QueryLogger');
1466
+    }
1467
+
1468
+    /**
1469
+     * Get the manager for temporary files and folders
1470
+     *
1471
+     * @return \OCP\ITempManager
1472
+     */
1473
+    public function getTempManager() {
1474
+        return $this->query('TempManager');
1475
+    }
1476
+
1477
+    /**
1478
+     * Get the app manager
1479
+     *
1480
+     * @return \OCP\App\IAppManager
1481
+     */
1482
+    public function getAppManager() {
1483
+        return $this->query('AppManager');
1484
+    }
1485
+
1486
+    /**
1487
+     * Creates a new mailer
1488
+     *
1489
+     * @return \OCP\Mail\IMailer
1490
+     */
1491
+    public function getMailer() {
1492
+        return $this->query('Mailer');
1493
+    }
1494
+
1495
+    /**
1496
+     * Get the webroot
1497
+     *
1498
+     * @return string
1499
+     */
1500
+    public function getWebRoot() {
1501
+        return $this->webRoot;
1502
+    }
1503
+
1504
+    /**
1505
+     * @return \OC\OCSClient
1506
+     */
1507
+    public function getOcsClient() {
1508
+        return $this->query('OcsClient');
1509
+    }
1510
+
1511
+    /**
1512
+     * @return \OCP\IDateTimeZone
1513
+     */
1514
+    public function getDateTimeZone() {
1515
+        return $this->query('DateTimeZone');
1516
+    }
1517
+
1518
+    /**
1519
+     * @return \OCP\IDateTimeFormatter
1520
+     */
1521
+    public function getDateTimeFormatter() {
1522
+        return $this->query('DateTimeFormatter');
1523
+    }
1524
+
1525
+    /**
1526
+     * @return \OCP\Files\Config\IMountProviderCollection
1527
+     */
1528
+    public function getMountProviderCollection() {
1529
+        return $this->query('MountConfigManager');
1530
+    }
1531
+
1532
+    /**
1533
+     * Get the IniWrapper
1534
+     *
1535
+     * @return IniGetWrapper
1536
+     */
1537
+    public function getIniWrapper() {
1538
+        return $this->query('IniWrapper');
1539
+    }
1540
+
1541
+    /**
1542
+     * @return \OCP\Command\IBus
1543
+     */
1544
+    public function getCommandBus() {
1545
+        return $this->query('AsyncCommandBus');
1546
+    }
1547
+
1548
+    /**
1549
+     * Get the trusted domain helper
1550
+     *
1551
+     * @return TrustedDomainHelper
1552
+     */
1553
+    public function getTrustedDomainHelper() {
1554
+        return $this->query('TrustedDomainHelper');
1555
+    }
1556
+
1557
+    /**
1558
+     * Get the locking provider
1559
+     *
1560
+     * @return \OCP\Lock\ILockingProvider
1561
+     * @since 8.1.0
1562
+     */
1563
+    public function getLockingProvider() {
1564
+        return $this->query('LockingProvider');
1565
+    }
1566
+
1567
+    /**
1568
+     * @return \OCP\Files\Mount\IMountManager
1569
+     **/
1570
+    function getMountManager() {
1571
+        return $this->query('MountManager');
1572
+    }
1573
+
1574
+    /** @return \OCP\Files\Config\IUserMountCache */
1575
+    function getUserMountCache() {
1576
+        return $this->query('UserMountCache');
1577
+    }
1578
+
1579
+    /**
1580
+     * Get the MimeTypeDetector
1581
+     *
1582
+     * @return \OCP\Files\IMimeTypeDetector
1583
+     */
1584
+    public function getMimeTypeDetector() {
1585
+        return $this->query('MimeTypeDetector');
1586
+    }
1587
+
1588
+    /**
1589
+     * Get the MimeTypeLoader
1590
+     *
1591
+     * @return \OCP\Files\IMimeTypeLoader
1592
+     */
1593
+    public function getMimeTypeLoader() {
1594
+        return $this->query('MimeTypeLoader');
1595
+    }
1596
+
1597
+    /**
1598
+     * Get the manager of all the capabilities
1599
+     *
1600
+     * @return \OC\CapabilitiesManager
1601
+     */
1602
+    public function getCapabilitiesManager() {
1603
+        return $this->query('CapabilitiesManager');
1604
+    }
1605
+
1606
+    /**
1607
+     * Get the EventDispatcher
1608
+     *
1609
+     * @return EventDispatcherInterface
1610
+     * @since 8.2.0
1611
+     */
1612
+    public function getEventDispatcher() {
1613
+        return $this->query('EventDispatcher');
1614
+    }
1615
+
1616
+    /**
1617
+     * Get the Notification Manager
1618
+     *
1619
+     * @return \OCP\Notification\IManager
1620
+     * @since 8.2.0
1621
+     */
1622
+    public function getNotificationManager() {
1623
+        return $this->query('NotificationManager');
1624
+    }
1625
+
1626
+    /**
1627
+     * @return \OCP\Comments\ICommentsManager
1628
+     */
1629
+    public function getCommentsManager() {
1630
+        return $this->query('CommentsManager');
1631
+    }
1632
+
1633
+    /**
1634
+     * @return \OCA\Theming\ThemingDefaults
1635
+     */
1636
+    public function getThemingDefaults() {
1637
+        return $this->query('ThemingDefaults');
1638
+    }
1639
+
1640
+    /**
1641
+     * @return \OC\IntegrityCheck\Checker
1642
+     */
1643
+    public function getIntegrityCodeChecker() {
1644
+        return $this->query('IntegrityCodeChecker');
1645
+    }
1646
+
1647
+    /**
1648
+     * @return \OC\Session\CryptoWrapper
1649
+     */
1650
+    public function getSessionCryptoWrapper() {
1651
+        return $this->query('CryptoWrapper');
1652
+    }
1653
+
1654
+    /**
1655
+     * @return CsrfTokenManager
1656
+     */
1657
+    public function getCsrfTokenManager() {
1658
+        return $this->query('CsrfTokenManager');
1659
+    }
1660
+
1661
+    /**
1662
+     * @return Throttler
1663
+     */
1664
+    public function getBruteForceThrottler() {
1665
+        return $this->query('Throttler');
1666
+    }
1667
+
1668
+    /**
1669
+     * @return IContentSecurityPolicyManager
1670
+     */
1671
+    public function getContentSecurityPolicyManager() {
1672
+        return $this->query('ContentSecurityPolicyManager');
1673
+    }
1674
+
1675
+    /**
1676
+     * @return ContentSecurityPolicyNonceManager
1677
+     */
1678
+    public function getContentSecurityPolicyNonceManager() {
1679
+        return $this->query('ContentSecurityPolicyNonceManager');
1680
+    }
1681
+
1682
+    /**
1683
+     * Not a public API as of 8.2, wait for 9.0
1684
+     *
1685
+     * @return \OCA\Files_External\Service\BackendService
1686
+     */
1687
+    public function getStoragesBackendService() {
1688
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1689
+    }
1690
+
1691
+    /**
1692
+     * Not a public API as of 8.2, wait for 9.0
1693
+     *
1694
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1695
+     */
1696
+    public function getGlobalStoragesService() {
1697
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1698
+    }
1699
+
1700
+    /**
1701
+     * Not a public API as of 8.2, wait for 9.0
1702
+     *
1703
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1704
+     */
1705
+    public function getUserGlobalStoragesService() {
1706
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1707
+    }
1708
+
1709
+    /**
1710
+     * Not a public API as of 8.2, wait for 9.0
1711
+     *
1712
+     * @return \OCA\Files_External\Service\UserStoragesService
1713
+     */
1714
+    public function getUserStoragesService() {
1715
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1716
+    }
1717
+
1718
+    /**
1719
+     * @return \OCP\Share\IManager
1720
+     */
1721
+    public function getShareManager() {
1722
+        return $this->query('ShareManager');
1723
+    }
1724
+
1725
+    /**
1726
+     * Returns the LDAP Provider
1727
+     *
1728
+     * @return \OCP\LDAP\ILDAPProvider
1729
+     */
1730
+    public function getLDAPProvider() {
1731
+        return $this->query('LDAPProvider');
1732
+    }
1733
+
1734
+    /**
1735
+     * @return \OCP\Settings\IManager
1736
+     */
1737
+    public function getSettingsManager() {
1738
+        return $this->query('SettingsManager');
1739
+    }
1740
+
1741
+    /**
1742
+     * @return \OCP\Files\IAppData
1743
+     */
1744
+    public function getAppDataDir($app) {
1745
+        /** @var \OC\Files\AppData\Factory $factory */
1746
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1747
+        return $factory->get($app);
1748
+    }
1749
+
1750
+    /**
1751
+     * @return \OCP\Lockdown\ILockdownManager
1752
+     */
1753
+    public function getLockdownManager() {
1754
+        return $this->query('LockdownManager');
1755
+    }
1756
+
1757
+    /**
1758
+     * @return \OCP\Federation\ICloudIdManager
1759
+     */
1760
+    public function getCloudIdManager() {
1761
+        return $this->query(ICloudIdManager::class);
1762
+    }
1763 1763
 }
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 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,27 +417,27 @@  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 423
 		$this->registerAlias('AppFetcher', AppFetcher::class);
424 424
 		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
425 425
 
426
-		$this->registerService(\OCP\ICache::class, function ($c) {
426
+		$this->registerService(\OCP\ICache::class, function($c) {
427 427
 			return new Cache\File();
428 428
 		});
429 429
 		$this->registerAlias('UserCache', \OCP\ICache::class);
430 430
 
431
-		$this->registerService(Factory::class, function (Server $c) {
431
+		$this->registerService(Factory::class, function(Server $c) {
432 432
 			$config = $c->getConfig();
433 433
 
434 434
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
435 435
 				$v = \OC_App::getAppVersions();
436
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
436
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
437 437
 				$version = implode(',', $v);
438 438
 				$instanceId = \OC_Util::getInstanceId();
439 439
 				$path = \OC::$SERVERROOT;
440
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
440
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
441 441
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
442 442
 					$config->getSystemValue('memcache.local', null),
443 443
 					$config->getSystemValue('memcache.distributed', null),
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 		$this->registerAlias('MemCacheFactory', Factory::class);
455 455
 		$this->registerAlias(ICacheFactory::class, Factory::class);
456 456
 
457
-		$this->registerService('RedisFactory', function (Server $c) {
457
+		$this->registerService('RedisFactory', function(Server $c) {
458 458
 			$systemConfig = $c->getSystemConfig();
459 459
 			return new RedisFactory($systemConfig);
460 460
 		});
461 461
 
462
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
462
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
463 463
 			return new \OC\Activity\Manager(
464 464
 				$c->getRequest(),
465 465
 				$c->getUserSession(),
@@ -469,14 +469,14 @@  discard block
 block discarded – undo
469 469
 		});
470 470
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
471 471
 
472
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
472
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
473 473
 			return new \OC\Activity\EventMerger(
474 474
 				$c->getL10N('lib')
475 475
 			);
476 476
 		});
477 477
 		$this->registerAlias(IValidator::class, Validator::class);
478 478
 
479
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
479
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
480 480
 			return new AvatarManager(
481 481
 				$c->getUserManager(),
482 482
 				$c->getAppDataDir('avatar'),
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 		});
488 488
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
489 489
 
490
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
490
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
491 491
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
492 492
 			$logger = Log::getLogClass($logType);
493 493
 			call_user_func(array($logger, 'init'));
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 		});
497 497
 		$this->registerAlias('Logger', \OCP\ILogger::class);
498 498
 
499
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
499
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
500 500
 			$config = $c->getConfig();
501 501
 			return new \OC\BackgroundJob\JobList(
502 502
 				$c->getDatabaseConnection(),
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 		});
507 507
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
508 508
 
509
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
509
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
510 510
 			$cacheFactory = $c->getMemCacheFactory();
511 511
 			$logger = $c->getLogger();
512 512
 			if ($cacheFactory->isAvailable()) {
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 		});
519 519
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
520 520
 
521
-		$this->registerService(\OCP\ISearch::class, function ($c) {
521
+		$this->registerService(\OCP\ISearch::class, function($c) {
522 522
 			return new Search();
523 523
 		});
524 524
 		$this->registerAlias('Search', \OCP\ISearch::class);
@@ -538,27 +538,27 @@  discard block
 block discarded – undo
538 538
 			);
539 539
 		});
540 540
 
541
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
541
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
542 542
 			return new SecureRandom();
543 543
 		});
544 544
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
545 545
 
546
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
546
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
547 547
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
548 548
 		});
549 549
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
550 550
 
551
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
551
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
552 552
 			return new Hasher($c->getConfig());
553 553
 		});
554 554
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
555 555
 
556
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
556
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
557 557
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
558 558
 		});
559 559
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
560 560
 
561
-		$this->registerService(IDBConnection::class, function (Server $c) {
561
+		$this->registerService(IDBConnection::class, function(Server $c) {
562 562
 			$systemConfig = $c->getSystemConfig();
563 563
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
564 564
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		});
573 573
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
574 574
 
575
-		$this->registerService('HTTPHelper', function (Server $c) {
575
+		$this->registerService('HTTPHelper', function(Server $c) {
576 576
 			$config = $c->getConfig();
577 577
 			return new HTTPHelper(
578 578
 				$config,
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			);
581 581
 		});
582 582
 
583
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
583
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
584 584
 			$user = \OC_User::getUser();
585 585
 			$uid = $user ? $user : null;
586 586
 			return new ClientService(
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 			);
590 590
 		});
591 591
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
592
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
592
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
593 593
 			$eventLogger = new EventLogger();
594 594
 			if ($c->getSystemConfig()->getValue('debug', false)) {
595 595
 				// In debug mode, module is being activated by default
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 		});
600 600
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
601 601
 
602
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
602
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
603 603
 			$queryLogger = new QueryLogger();
604 604
 			if ($c->getSystemConfig()->getValue('debug', false)) {
605 605
 				// In debug mode, module is being activated by default
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 		});
610 610
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
611 611
 
612
-		$this->registerService(TempManager::class, function (Server $c) {
612
+		$this->registerService(TempManager::class, function(Server $c) {
613 613
 			return new TempManager(
614 614
 				$c->getLogger(),
615 615
 				$c->getConfig()
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 		$this->registerAlias('TempManager', TempManager::class);
619 619
 		$this->registerAlias(ITempManager::class, TempManager::class);
620 620
 
621
-		$this->registerService(AppManager::class, function (Server $c) {
621
+		$this->registerService(AppManager::class, function(Server $c) {
622 622
 			return new \OC\App\AppManager(
623 623
 				$c->getUserSession(),
624 624
 				$c->getAppConfig(),
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		$this->registerAlias('AppManager', AppManager::class);
631 631
 		$this->registerAlias(IAppManager::class, AppManager::class);
632 632
 
633
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
633
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
634 634
 			return new DateTimeZone(
635 635
 				$c->getConfig(),
636 636
 				$c->getSession()
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 		});
639 639
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
640 640
 
641
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
641
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
642 642
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
643 643
 
644 644
 			return new DateTimeFormatter(
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 		});
649 649
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
650 650
 
651
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
651
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
652 652
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
653 653
 			$listener = new UserMountCacheListener($mountCache);
654 654
 			$listener->listen($c->getUserManager());
@@ -656,10 +656,10 @@  discard block
 block discarded – undo
656 656
 		});
657 657
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
658 658
 
659
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
659
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
660 660
 			$loader = \OC\Files\Filesystem::getLoader();
661 661
 			$mountCache = $c->query('UserMountCache');
662
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
662
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
663 663
 
664 664
 			// builtin providers
665 665
 
@@ -672,14 +672,14 @@  discard block
 block discarded – undo
672 672
 		});
673 673
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
674 674
 
675
-		$this->registerService('IniWrapper', function ($c) {
675
+		$this->registerService('IniWrapper', function($c) {
676 676
 			return new IniGetWrapper();
677 677
 		});
678
-		$this->registerService('AsyncCommandBus', function (Server $c) {
678
+		$this->registerService('AsyncCommandBus', function(Server $c) {
679 679
 			$jobList = $c->getJobList();
680 680
 			return new AsyncBus($jobList);
681 681
 		});
682
-		$this->registerService('TrustedDomainHelper', function ($c) {
682
+		$this->registerService('TrustedDomainHelper', function($c) {
683 683
 			return new TrustedDomainHelper($this->getConfig());
684 684
 		});
685 685
 		$this->registerService('Throttler', function(Server $c) {
@@ -690,10 +690,10 @@  discard block
 block discarded – undo
690 690
 				$c->getConfig()
691 691
 			);
692 692
 		});
693
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
693
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
694 694
 			// IConfig and IAppManager requires a working database. This code
695 695
 			// might however be called when ownCloud is not yet setup.
696
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
696
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
697 697
 				$config = $c->getConfig();
698 698
 				$appManager = $c->getAppManager();
699 699
 			} else {
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 					$c->getTempManager()
712 712
 			);
713 713
 		});
714
-		$this->registerService(\OCP\IRequest::class, function ($c) {
714
+		$this->registerService(\OCP\IRequest::class, function($c) {
715 715
 			if (isset($this['urlParams'])) {
716 716
 				$urlParams = $this['urlParams'];
717 717
 			} else {
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 		});
748 748
 		$this->registerAlias('Request', \OCP\IRequest::class);
749 749
 
750
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
750
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
751 751
 			return new Mailer(
752 752
 				$c->getConfig(),
753 753
 				$c->getLogger(),
@@ -761,14 +761,14 @@  discard block
 block discarded – undo
761 761
 		$this->registerService('LDAPProvider', function(Server $c) {
762 762
 			$config = $c->getConfig();
763 763
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
764
-			if(is_null($factoryClass)) {
764
+			if (is_null($factoryClass)) {
765 765
 				throw new \Exception('ldapProviderFactory not set');
766 766
 			}
767 767
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
768 768
 			$factory = new $factoryClass($this);
769 769
 			return $factory->getLDAPProvider();
770 770
 		});
771
-		$this->registerService('LockingProvider', function (Server $c) {
771
+		$this->registerService('LockingProvider', function(Server $c) {
772 772
 			$ini = $c->getIniWrapper();
773 773
 			$config = $c->getConfig();
774 774
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -784,39 +784,39 @@  discard block
 block discarded – undo
784 784
 			return new NoopLockingProvider();
785 785
 		});
786 786
 
787
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
787
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
788 788
 			return new \OC\Files\Mount\Manager();
789 789
 		});
790 790
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
791 791
 
792
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
792
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
793 793
 			return new \OC\Files\Type\Detection(
794 794
 				$c->getURLGenerator(),
795 795
 				\OC::$configDir,
796
-				\OC::$SERVERROOT . '/resources/config/'
796
+				\OC::$SERVERROOT.'/resources/config/'
797 797
 			);
798 798
 		});
799 799
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
800 800
 
801
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
801
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
802 802
 			return new \OC\Files\Type\Loader(
803 803
 				$c->getDatabaseConnection()
804 804
 			);
805 805
 		});
806 806
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
807
-		$this->registerService(BundleFetcher::class, function () {
807
+		$this->registerService(BundleFetcher::class, function() {
808 808
 			return new BundleFetcher($this->getL10N('lib'));
809 809
 		});
810
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
810
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
811 811
 			return new Manager(
812 812
 				$c->query(IValidator::class)
813 813
 			);
814 814
 		});
815 815
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
816 816
 
817
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
817
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
818 818
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
819
-			$manager->registerCapability(function () use ($c) {
819
+			$manager->registerCapability(function() use ($c) {
820 820
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
821 821
 			});
822 822
 			return $manager;
@@ -871,13 +871,13 @@  discard block
 block discarded – undo
871 871
 				$cacheFactory->create('SCSS')
872 872
 			);
873 873
 		});
874
-		$this->registerService(EventDispatcher::class, function () {
874
+		$this->registerService(EventDispatcher::class, function() {
875 875
 			return new EventDispatcher();
876 876
 		});
877 877
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
878 878
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
879 879
 
880
-		$this->registerService('CryptoWrapper', function (Server $c) {
880
+		$this->registerService('CryptoWrapper', function(Server $c) {
881 881
 			// FIXME: Instantiiated here due to cyclic dependency
882 882
 			$request = new Request(
883 883
 				[
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 				$request
903 903
 			);
904 904
 		});
905
-		$this->registerService('CsrfTokenManager', function (Server $c) {
905
+		$this->registerService('CsrfTokenManager', function(Server $c) {
906 906
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
907 907
 
908 908
 			return new CsrfTokenManager(
@@ -910,10 +910,10 @@  discard block
 block discarded – undo
910 910
 				$c->query(SessionStorage::class)
911 911
 			);
912 912
 		});
913
-		$this->registerService(SessionStorage::class, function (Server $c) {
913
+		$this->registerService(SessionStorage::class, function(Server $c) {
914 914
 			return new SessionStorage($c->getSession());
915 915
 		});
916
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
916
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
917 917
 			return new ContentSecurityPolicyManager();
918 918
 		});
919 919
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -964,29 +964,29 @@  discard block
 block discarded – undo
964 964
 			);
965 965
 			return $manager;
966 966
 		});
967
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
967
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
968 968
 			return new \OC\Files\AppData\Factory(
969 969
 				$c->getRootFolder(),
970 970
 				$c->getSystemConfig()
971 971
 			);
972 972
 		});
973 973
 
974
-		$this->registerService('LockdownManager', function (Server $c) {
974
+		$this->registerService('LockdownManager', function(Server $c) {
975 975
 			return new LockdownManager(function() use ($c) {
976 976
 				return $c->getSession();
977 977
 			});
978 978
 		});
979 979
 
980
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
980
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
981 981
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
982 982
 		});
983 983
 
984
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
984
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
985 985
 			return new CloudIdManager();
986 986
 		});
987 987
 
988 988
 		/* To trick DI since we don't extend the DIContainer here */
989
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
989
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
990 990
 			return new CleanPreviewsBackgroundJob(
991 991
 				$c->getRootFolder(),
992 992
 				$c->getLogger(),
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1002 1002
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1003 1003
 
1004
-		$this->registerService(Defaults::class, function (Server $c) {
1004
+		$this->registerService(Defaults::class, function(Server $c) {
1005 1005
 			return new Defaults(
1006 1006
 				$c->getThemingDefaults()
1007 1007
 			);
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 	 * @deprecated since 9.2.0 use IAppData
1154 1154
 	 */
1155 1155
 	public function getAppFolder() {
1156
-		$dir = '/' . \OC_App::getCurrentApp();
1156
+		$dir = '/'.\OC_App::getCurrentApp();
1157 1157
 		$root = $this->getRootFolder();
1158 1158
 		if (!$root->nodeExists($dir)) {
1159 1159
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Response.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 	/**
228 228
 	 * By default renders no output
229
-	 * @return null
229
+	 * @return string
230 230
 	 * @since 6.0.0
231 231
 	 */
232 232
 	public function render() {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 	/**
261 261
 	 * Get the currently used Content-Security-Policy
262
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
262
+	 * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if
263 263
 	 *                                    none specified.
264 264
 	 * @since 8.1.0
265 265
 	 */
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function cacheFor($cacheSeconds) {
93 93
 
94
-		if($cacheSeconds > 0) {
95
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
94
+		if ($cacheSeconds > 0) {
95
+			$this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate');
96 96
 		} else {
97 97
 			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
98 98
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @since 8.0.0
147 147
 	 */
148 148
 	public function invalidateCookies(array $cookieNames) {
149
-		foreach($cookieNames as $cookieName) {
149
+		foreach ($cookieNames as $cookieName) {
150 150
 			$this->invalidateCookie($cookieName);
151 151
 		}
152 152
 		return $this;
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * @since 6.0.0 - return value was added in 7.0.0
171 171
 	 */
172 172
 	public function addHeader($name, $value) {
173
-		$name = trim($name);  // always remove leading and trailing whitespace
173
+		$name = trim($name); // always remove leading and trailing whitespace
174 174
 		                      // to be able to reliably check for security
175 175
 		                      // headers
176 176
 
177
-		if(is_null($value)) {
177
+		if (is_null($value)) {
178 178
 			unset($this->headers[$name]);
179 179
 		} else {
180 180
 			$this->headers[$name] = $value;
@@ -205,19 +205,19 @@  discard block
 block discarded – undo
205 205
 	public function getHeaders() {
206 206
 		$mergeWith = [];
207 207
 
208
-		if($this->lastModified) {
208
+		if ($this->lastModified) {
209 209
 			$mergeWith['Last-Modified'] =
210 210
 				$this->lastModified->format(\DateTime::RFC2822);
211 211
 		}
212 212
 
213 213
 		// Build Content-Security-Policy and use default if none has been specified
214
-		if(is_null($this->contentSecurityPolicy)) {
214
+		if (is_null($this->contentSecurityPolicy)) {
215 215
 			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
216 216
 		}
217 217
 		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
218 218
 
219
-		if($this->ETag) {
220
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
219
+		if ($this->ETag) {
220
+			$mergeWith['ETag'] = '"'.$this->ETag.'"';
221 221
 		}
222 222
 
223 223
 		return array_merge($mergeWith, $this->headers);
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -42,304 +42,304 @@
 block discarded – undo
42 42
  */
43 43
 class Response {
44 44
 
45
-	/**
46
-	 * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
-	 * @var array
48
-	 */
49
-	private $headers = array(
50
-		'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
-	);
52
-
53
-
54
-	/**
55
-	 * Cookies that will be need to be constructed as header
56
-	 * @var array
57
-	 */
58
-	private $cookies = array();
59
-
60
-
61
-	/**
62
-	 * HTTP status code - defaults to STATUS OK
63
-	 * @var int
64
-	 */
65
-	private $status = Http::STATUS_OK;
66
-
67
-
68
-	/**
69
-	 * Last modified date
70
-	 * @var \DateTime
71
-	 */
72
-	private $lastModified;
73
-
74
-
75
-	/**
76
-	 * ETag
77
-	 * @var string
78
-	 */
79
-	private $ETag;
80
-
81
-	/** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
-	private $contentSecurityPolicy = null;
83
-
84
-	/** @var bool */
85
-	private $throttled = false;
86
-
87
-	/**
88
-	 * Caches the response
89
-	 * @param int $cacheSeconds the amount of seconds that should be cached
90
-	 * if 0 then caching will be disabled
91
-	 * @return $this
92
-	 * @since 6.0.0 - return value was added in 7.0.0
93
-	 */
94
-	public function cacheFor($cacheSeconds) {
95
-
96
-		if($cacheSeconds > 0) {
97
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
98
-		} else {
99
-			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
100
-		}
101
-
102
-		return $this;
103
-	}
104
-
105
-	/**
106
-	 * Adds a new cookie to the response
107
-	 * @param string $name The name of the cookie
108
-	 * @param string $value The value of the cookie
109
-	 * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
110
-	 * 									to null cookie will be considered as session
111
-	 * 									cookie.
112
-	 * @return $this
113
-	 * @since 8.0.0
114
-	 */
115
-	public function addCookie($name, $value, \DateTime $expireDate = null) {
116
-		$this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
117
-		return $this;
118
-	}
119
-
120
-
121
-	/**
122
-	 * Set the specified cookies
123
-	 * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
124
-	 * @return $this
125
-	 * @since 8.0.0
126
-	 */
127
-	public function setCookies(array $cookies) {
128
-		$this->cookies = $cookies;
129
-		return $this;
130
-	}
131
-
132
-
133
-	/**
134
-	 * Invalidates the specified cookie
135
-	 * @param string $name
136
-	 * @return $this
137
-	 * @since 8.0.0
138
-	 */
139
-	public function invalidateCookie($name) {
140
-		$this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
141
-		return $this;
142
-	}
143
-
144
-	/**
145
-	 * Invalidates the specified cookies
146
-	 * @param array $cookieNames array('foo', 'bar')
147
-	 * @return $this
148
-	 * @since 8.0.0
149
-	 */
150
-	public function invalidateCookies(array $cookieNames) {
151
-		foreach($cookieNames as $cookieName) {
152
-			$this->invalidateCookie($cookieName);
153
-		}
154
-		return $this;
155
-	}
156
-
157
-	/**
158
-	 * Returns the cookies
159
-	 * @return array
160
-	 * @since 8.0.0
161
-	 */
162
-	public function getCookies() {
163
-		return $this->cookies;
164
-	}
165
-
166
-	/**
167
-	 * Adds a new header to the response that will be called before the render
168
-	 * function
169
-	 * @param string $name The name of the HTTP header
170
-	 * @param string $value The value, null will delete it
171
-	 * @return $this
172
-	 * @since 6.0.0 - return value was added in 7.0.0
173
-	 */
174
-	public function addHeader($name, $value) {
175
-		$name = trim($name);  // always remove leading and trailing whitespace
176
-		                      // to be able to reliably check for security
177
-		                      // headers
178
-
179
-		if(is_null($value)) {
180
-			unset($this->headers[$name]);
181
-		} else {
182
-			$this->headers[$name] = $value;
183
-		}
184
-
185
-		return $this;
186
-	}
187
-
188
-
189
-	/**
190
-	 * Set the headers
191
-	 * @param array $headers value header pairs
192
-	 * @return $this
193
-	 * @since 8.0.0
194
-	 */
195
-	public function setHeaders(array $headers) {
196
-		$this->headers = $headers;
197
-
198
-		return $this;
199
-	}
200
-
201
-
202
-	/**
203
-	 * Returns the set headers
204
-	 * @return array the headers
205
-	 * @since 6.0.0
206
-	 */
207
-	public function getHeaders() {
208
-		$mergeWith = [];
209
-
210
-		if($this->lastModified) {
211
-			$mergeWith['Last-Modified'] =
212
-				$this->lastModified->format(\DateTime::RFC2822);
213
-		}
214
-
215
-		// Build Content-Security-Policy and use default if none has been specified
216
-		if(is_null($this->contentSecurityPolicy)) {
217
-			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
218
-		}
219
-		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
220
-
221
-		if($this->ETag) {
222
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
223
-		}
224
-
225
-		return array_merge($mergeWith, $this->headers);
226
-	}
227
-
228
-
229
-	/**
230
-	 * By default renders no output
231
-	 * @return null
232
-	 * @since 6.0.0
233
-	 */
234
-	public function render() {
235
-		return null;
236
-	}
237
-
238
-
239
-	/**
240
-	 * Set response status
241
-	 * @param int $status a HTTP status code, see also the STATUS constants
242
-	 * @return Response Reference to this object
243
-	 * @since 6.0.0 - return value was added in 7.0.0
244
-	 */
245
-	public function setStatus($status) {
246
-		$this->status = $status;
247
-
248
-		return $this;
249
-	}
250
-
251
-	/**
252
-	 * Set a Content-Security-Policy
253
-	 * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
254
-	 * @return $this
255
-	 * @since 8.1.0
256
-	 */
257
-	public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
258
-		$this->contentSecurityPolicy = $csp;
259
-		return $this;
260
-	}
261
-
262
-	/**
263
-	 * Get the currently used Content-Security-Policy
264
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
265
-	 *                                    none specified.
266
-	 * @since 8.1.0
267
-	 */
268
-	public function getContentSecurityPolicy() {
269
-		return $this->contentSecurityPolicy;
270
-	}
271
-
272
-
273
-	/**
274
-	 * Get response status
275
-	 * @since 6.0.0
276
-	 */
277
-	public function getStatus() {
278
-		return $this->status;
279
-	}
280
-
281
-
282
-	/**
283
-	 * Get the ETag
284
-	 * @return string the etag
285
-	 * @since 6.0.0
286
-	 */
287
-	public function getETag() {
288
-		return $this->ETag;
289
-	}
290
-
291
-
292
-	/**
293
-	 * Get "last modified" date
294
-	 * @return \DateTime RFC2822 formatted last modified date
295
-	 * @since 6.0.0
296
-	 */
297
-	public function getLastModified() {
298
-		return $this->lastModified;
299
-	}
300
-
301
-
302
-	/**
303
-	 * Set the ETag
304
-	 * @param string $ETag
305
-	 * @return Response Reference to this object
306
-	 * @since 6.0.0 - return value was added in 7.0.0
307
-	 */
308
-	public function setETag($ETag) {
309
-		$this->ETag = $ETag;
310
-
311
-		return $this;
312
-	}
313
-
314
-
315
-	/**
316
-	 * Set "last modified" date
317
-	 * @param \DateTime $lastModified
318
-	 * @return Response Reference to this object
319
-	 * @since 6.0.0 - return value was added in 7.0.0
320
-	 */
321
-	public function setLastModified($lastModified) {
322
-		$this->lastModified = $lastModified;
323
-
324
-		return $this;
325
-	}
326
-
327
-	/**
328
-	 * Marks the response as to throttle. Will be throttled when the
329
-	 * @BruteForceProtection annotation is added.
330
-	 *
331
-	 * @since 12.0.0
332
-	 */
333
-	public function throttle() {
334
-		$this->throttled = true;
335
-	}
336
-
337
-	/**
338
-	 * Whether the current response is throttled.
339
-	 *
340
-	 * @since 12.0.0
341
-	 */
342
-	public function isThrottled() {
343
-		return $this->throttled;
344
-	}
45
+    /**
46
+     * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
+     * @var array
48
+     */
49
+    private $headers = array(
50
+        'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
+    );
52
+
53
+
54
+    /**
55
+     * Cookies that will be need to be constructed as header
56
+     * @var array
57
+     */
58
+    private $cookies = array();
59
+
60
+
61
+    /**
62
+     * HTTP status code - defaults to STATUS OK
63
+     * @var int
64
+     */
65
+    private $status = Http::STATUS_OK;
66
+
67
+
68
+    /**
69
+     * Last modified date
70
+     * @var \DateTime
71
+     */
72
+    private $lastModified;
73
+
74
+
75
+    /**
76
+     * ETag
77
+     * @var string
78
+     */
79
+    private $ETag;
80
+
81
+    /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
+    private $contentSecurityPolicy = null;
83
+
84
+    /** @var bool */
85
+    private $throttled = false;
86
+
87
+    /**
88
+     * Caches the response
89
+     * @param int $cacheSeconds the amount of seconds that should be cached
90
+     * if 0 then caching will be disabled
91
+     * @return $this
92
+     * @since 6.0.0 - return value was added in 7.0.0
93
+     */
94
+    public function cacheFor($cacheSeconds) {
95
+
96
+        if($cacheSeconds > 0) {
97
+            $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
98
+        } else {
99
+            $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
100
+        }
101
+
102
+        return $this;
103
+    }
104
+
105
+    /**
106
+     * Adds a new cookie to the response
107
+     * @param string $name The name of the cookie
108
+     * @param string $value The value of the cookie
109
+     * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
110
+     * 									to null cookie will be considered as session
111
+     * 									cookie.
112
+     * @return $this
113
+     * @since 8.0.0
114
+     */
115
+    public function addCookie($name, $value, \DateTime $expireDate = null) {
116
+        $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
117
+        return $this;
118
+    }
119
+
120
+
121
+    /**
122
+     * Set the specified cookies
123
+     * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
124
+     * @return $this
125
+     * @since 8.0.0
126
+     */
127
+    public function setCookies(array $cookies) {
128
+        $this->cookies = $cookies;
129
+        return $this;
130
+    }
131
+
132
+
133
+    /**
134
+     * Invalidates the specified cookie
135
+     * @param string $name
136
+     * @return $this
137
+     * @since 8.0.0
138
+     */
139
+    public function invalidateCookie($name) {
140
+        $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
141
+        return $this;
142
+    }
143
+
144
+    /**
145
+     * Invalidates the specified cookies
146
+     * @param array $cookieNames array('foo', 'bar')
147
+     * @return $this
148
+     * @since 8.0.0
149
+     */
150
+    public function invalidateCookies(array $cookieNames) {
151
+        foreach($cookieNames as $cookieName) {
152
+            $this->invalidateCookie($cookieName);
153
+        }
154
+        return $this;
155
+    }
156
+
157
+    /**
158
+     * Returns the cookies
159
+     * @return array
160
+     * @since 8.0.0
161
+     */
162
+    public function getCookies() {
163
+        return $this->cookies;
164
+    }
165
+
166
+    /**
167
+     * Adds a new header to the response that will be called before the render
168
+     * function
169
+     * @param string $name The name of the HTTP header
170
+     * @param string $value The value, null will delete it
171
+     * @return $this
172
+     * @since 6.0.0 - return value was added in 7.0.0
173
+     */
174
+    public function addHeader($name, $value) {
175
+        $name = trim($name);  // always remove leading and trailing whitespace
176
+                                // to be able to reliably check for security
177
+                                // headers
178
+
179
+        if(is_null($value)) {
180
+            unset($this->headers[$name]);
181
+        } else {
182
+            $this->headers[$name] = $value;
183
+        }
184
+
185
+        return $this;
186
+    }
187
+
188
+
189
+    /**
190
+     * Set the headers
191
+     * @param array $headers value header pairs
192
+     * @return $this
193
+     * @since 8.0.0
194
+     */
195
+    public function setHeaders(array $headers) {
196
+        $this->headers = $headers;
197
+
198
+        return $this;
199
+    }
200
+
201
+
202
+    /**
203
+     * Returns the set headers
204
+     * @return array the headers
205
+     * @since 6.0.0
206
+     */
207
+    public function getHeaders() {
208
+        $mergeWith = [];
209
+
210
+        if($this->lastModified) {
211
+            $mergeWith['Last-Modified'] =
212
+                $this->lastModified->format(\DateTime::RFC2822);
213
+        }
214
+
215
+        // Build Content-Security-Policy and use default if none has been specified
216
+        if(is_null($this->contentSecurityPolicy)) {
217
+            $this->setContentSecurityPolicy(new ContentSecurityPolicy());
218
+        }
219
+        $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
220
+
221
+        if($this->ETag) {
222
+            $mergeWith['ETag'] = '"' . $this->ETag . '"';
223
+        }
224
+
225
+        return array_merge($mergeWith, $this->headers);
226
+    }
227
+
228
+
229
+    /**
230
+     * By default renders no output
231
+     * @return null
232
+     * @since 6.0.0
233
+     */
234
+    public function render() {
235
+        return null;
236
+    }
237
+
238
+
239
+    /**
240
+     * Set response status
241
+     * @param int $status a HTTP status code, see also the STATUS constants
242
+     * @return Response Reference to this object
243
+     * @since 6.0.0 - return value was added in 7.0.0
244
+     */
245
+    public function setStatus($status) {
246
+        $this->status = $status;
247
+
248
+        return $this;
249
+    }
250
+
251
+    /**
252
+     * Set a Content-Security-Policy
253
+     * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
254
+     * @return $this
255
+     * @since 8.1.0
256
+     */
257
+    public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
258
+        $this->contentSecurityPolicy = $csp;
259
+        return $this;
260
+    }
261
+
262
+    /**
263
+     * Get the currently used Content-Security-Policy
264
+     * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
265
+     *                                    none specified.
266
+     * @since 8.1.0
267
+     */
268
+    public function getContentSecurityPolicy() {
269
+        return $this->contentSecurityPolicy;
270
+    }
271
+
272
+
273
+    /**
274
+     * Get response status
275
+     * @since 6.0.0
276
+     */
277
+    public function getStatus() {
278
+        return $this->status;
279
+    }
280
+
281
+
282
+    /**
283
+     * Get the ETag
284
+     * @return string the etag
285
+     * @since 6.0.0
286
+     */
287
+    public function getETag() {
288
+        return $this->ETag;
289
+    }
290
+
291
+
292
+    /**
293
+     * Get "last modified" date
294
+     * @return \DateTime RFC2822 formatted last modified date
295
+     * @since 6.0.0
296
+     */
297
+    public function getLastModified() {
298
+        return $this->lastModified;
299
+    }
300
+
301
+
302
+    /**
303
+     * Set the ETag
304
+     * @param string $ETag
305
+     * @return Response Reference to this object
306
+     * @since 6.0.0 - return value was added in 7.0.0
307
+     */
308
+    public function setETag($ETag) {
309
+        $this->ETag = $ETag;
310
+
311
+        return $this;
312
+    }
313
+
314
+
315
+    /**
316
+     * Set "last modified" date
317
+     * @param \DateTime $lastModified
318
+     * @return Response Reference to this object
319
+     * @since 6.0.0 - return value was added in 7.0.0
320
+     */
321
+    public function setLastModified($lastModified) {
322
+        $this->lastModified = $lastModified;
323
+
324
+        return $this;
325
+    }
326
+
327
+    /**
328
+     * Marks the response as to throttle. Will be throttled when the
329
+     * @BruteForceProtection annotation is added.
330
+     *
331
+     * @since 12.0.0
332
+     */
333
+    public function throttle() {
334
+        $this->throttled = true;
335
+    }
336
+
337
+    /**
338
+     * Whether the current response is throttled.
339
+     *
340
+     * @since 12.0.0
341
+     */
342
+    public function isThrottled() {
343
+        return $this->throttled;
344
+    }
345 345
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 	 * @param RequestInterface $request
135 135
 	 * @param ResponseInterface $response
136 136
 	 *
137
-	 * @return void|bool
137
+	 * @return null|false
138 138
 	 */
139 139
 	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140 140
 		$path = $request->getPath();
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -34,194 +34,194 @@
 block discarded – undo
34 34
 use OCP\IConfig;
35 35
 
36 36
 class PublishPlugin extends ServerPlugin {
37
-	const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
-
39
-	/**
40
-	 * Reference to SabreDAV server object.
41
-	 *
42
-	 * @var \Sabre\DAV\Server
43
-	 */
44
-	protected $server;
45
-
46
-	/**
47
-	 * Config instance to get instance secret.
48
-	 *
49
-	 * @var IConfig
50
-	 */
51
-	protected $config;
52
-
53
-	/**
54
-	 * URL Generator for absolute URLs.
55
-	 *
56
-	 * @var IURLGenerator
57
-	 */
58
-	protected $urlGenerator;
59
-
60
-	/**
61
-	 * PublishPlugin constructor.
62
-	 *
63
-	 * @param IConfig $config
64
-	 * @param IURLGenerator $urlGenerator
65
-	 */
66
-	public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
-		$this->config = $config;
68
-		$this->urlGenerator = $urlGenerator;
69
-	}
70
-
71
-	/**
72
-	 * This method should return a list of server-features.
73
-	 *
74
-	 * This is for example 'versioning' and is added to the DAV: header
75
-	 * in an OPTIONS response.
76
-	 *
77
-	 * @return string[]
78
-	 */
79
-	public function getFeatures() {
80
-		// May have to be changed to be detected
81
-		return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
-	}
83
-
84
-	/**
85
-	 * Returns a plugin name.
86
-	 *
87
-	 * Using this name other plugins will be able to access other plugins
88
-	 * using Sabre\DAV\Server::getPlugin
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public function getPluginName()	{
93
-		return 'oc-calendar-publishing';
94
-	}
95
-
96
-	/**
97
-	 * This initializes the plugin.
98
-	 *
99
-	 * This function is called by Sabre\DAV\Server, after
100
-	 * addPlugin is called.
101
-	 *
102
-	 * This method should set up the required event subscriptions.
103
-	 *
104
-	 * @param Server $server
105
-	 */
106
-	public function initialize(Server $server) {
107
-		$this->server = $server;
108
-
109
-		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
111
-	}
112
-
113
-	public function propFind(PropFind $propFind, INode $node) {
114
-		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
-				if ($node->getPublishStatus()) {
117
-					// We return the publish-url only if the calendar is published.
118
-					$token = $node->getPublishStatus();
119
-					$publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
-
121
-					return new Publisher($publishUrl, true);
122
-				}
123
-			});
124
-
125
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
-				return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
-			});
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * We intercept this to handle POST requests on calendars.
133
-	 *
134
-	 * @param RequestInterface $request
135
-	 * @param ResponseInterface $response
136
-	 *
137
-	 * @return void|bool
138
-	 */
139
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
-		$path = $request->getPath();
141
-
142
-		// Only handling xml
143
-		$contentType = $request->getHeader('Content-Type');
144
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
-			return;
146
-		}
147
-
148
-		// Making sure the node exists
149
-		try {
150
-			$node = $this->server->tree->getNodeForPath($path);
151
-		} catch (NotFound $e) {
152
-			return;
153
-		}
154
-
155
-		$requestBody = $request->getBodyAsString();
156
-
157
-		// If this request handler could not deal with this POST request, it
158
-		// will return 'null' and other plugins get a chance to handle the
159
-		// request.
160
-		//
161
-		// However, we already requested the full body. This is a problem,
162
-		// because a body can only be read once. This is why we preemptively
163
-		// re-populated the request body with the existing data.
164
-		$request->setBody($requestBody);
165
-
166
-		$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
-
168
-		switch ($documentType) {
169
-
170
-			case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
-
172
-			// We can only deal with IShareableCalendar objects
173
-			if (!$node instanceof Calendar) {
174
-				return;
175
-			}
176
-			$this->server->transactionType = 'post-publish-calendar';
177
-
178
-			// Getting ACL info
179
-			$acl = $this->server->getPlugin('acl');
180
-
181
-			// If there's no ACL support, we allow everything
182
-			if ($acl) {
183
-				$acl->checkPrivileges($path, '{DAV:}write');
184
-			}
185
-
186
-			$node->setPublishStatus(true);
187
-
188
-			// iCloud sends back the 202, so we will too.
189
-			$response->setStatus(202);
190
-
191
-			// Adding this because sending a response body may cause issues,
192
-			// and I wanted some type of indicator the response was handled.
193
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
194
-
195
-			// Breaking the event chain
196
-			return false;
197
-
198
-			case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
-
200
-			// We can only deal with IShareableCalendar objects
201
-			if (!$node instanceof Calendar) {
202
-				return;
203
-			}
204
-			$this->server->transactionType = 'post-unpublish-calendar';
205
-
206
-			// Getting ACL info
207
-			$acl = $this->server->getPlugin('acl');
208
-
209
-			// If there's no ACL support, we allow everything
210
-			if ($acl) {
211
-				$acl->checkPrivileges($path, '{DAV:}write');
212
-			}
213
-
214
-			$node->setPublishStatus(false);
215
-
216
-			$response->setStatus(200);
217
-
218
-			// Adding this because sending a response body may cause issues,
219
-			// and I wanted some type of indicator the response was handled.
220
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
221
-
222
-			// Breaking the event chain
223
-			return false;
37
+    const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
+
39
+    /**
40
+     * Reference to SabreDAV server object.
41
+     *
42
+     * @var \Sabre\DAV\Server
43
+     */
44
+    protected $server;
45
+
46
+    /**
47
+     * Config instance to get instance secret.
48
+     *
49
+     * @var IConfig
50
+     */
51
+    protected $config;
52
+
53
+    /**
54
+     * URL Generator for absolute URLs.
55
+     *
56
+     * @var IURLGenerator
57
+     */
58
+    protected $urlGenerator;
59
+
60
+    /**
61
+     * PublishPlugin constructor.
62
+     *
63
+     * @param IConfig $config
64
+     * @param IURLGenerator $urlGenerator
65
+     */
66
+    public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
+        $this->config = $config;
68
+        $this->urlGenerator = $urlGenerator;
69
+    }
70
+
71
+    /**
72
+     * This method should return a list of server-features.
73
+     *
74
+     * This is for example 'versioning' and is added to the DAV: header
75
+     * in an OPTIONS response.
76
+     *
77
+     * @return string[]
78
+     */
79
+    public function getFeatures() {
80
+        // May have to be changed to be detected
81
+        return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
+    }
83
+
84
+    /**
85
+     * Returns a plugin name.
86
+     *
87
+     * Using this name other plugins will be able to access other plugins
88
+     * using Sabre\DAV\Server::getPlugin
89
+     *
90
+     * @return string
91
+     */
92
+    public function getPluginName()	{
93
+        return 'oc-calendar-publishing';
94
+    }
95
+
96
+    /**
97
+     * This initializes the plugin.
98
+     *
99
+     * This function is called by Sabre\DAV\Server, after
100
+     * addPlugin is called.
101
+     *
102
+     * This method should set up the required event subscriptions.
103
+     *
104
+     * @param Server $server
105
+     */
106
+    public function initialize(Server $server) {
107
+        $this->server = $server;
108
+
109
+        $this->server->on('method:POST', [$this, 'httpPost']);
110
+        $this->server->on('propFind',    [$this, 'propFind']);
111
+    }
112
+
113
+    public function propFind(PropFind $propFind, INode $node) {
114
+        if ($node instanceof Calendar) {
115
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
+                if ($node->getPublishStatus()) {
117
+                    // We return the publish-url only if the calendar is published.
118
+                    $token = $node->getPublishStatus();
119
+                    $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
+
121
+                    return new Publisher($publishUrl, true);
122
+                }
123
+            });
124
+
125
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
+                return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
+            });
128
+        }
129
+    }
130
+
131
+    /**
132
+     * We intercept this to handle POST requests on calendars.
133
+     *
134
+     * @param RequestInterface $request
135
+     * @param ResponseInterface $response
136
+     *
137
+     * @return void|bool
138
+     */
139
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
+        $path = $request->getPath();
141
+
142
+        // Only handling xml
143
+        $contentType = $request->getHeader('Content-Type');
144
+        if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
+            return;
146
+        }
147
+
148
+        // Making sure the node exists
149
+        try {
150
+            $node = $this->server->tree->getNodeForPath($path);
151
+        } catch (NotFound $e) {
152
+            return;
153
+        }
154
+
155
+        $requestBody = $request->getBodyAsString();
156
+
157
+        // If this request handler could not deal with this POST request, it
158
+        // will return 'null' and other plugins get a chance to handle the
159
+        // request.
160
+        //
161
+        // However, we already requested the full body. This is a problem,
162
+        // because a body can only be read once. This is why we preemptively
163
+        // re-populated the request body with the existing data.
164
+        $request->setBody($requestBody);
165
+
166
+        $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
+
168
+        switch ($documentType) {
169
+
170
+            case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
+
172
+            // We can only deal with IShareableCalendar objects
173
+            if (!$node instanceof Calendar) {
174
+                return;
175
+            }
176
+            $this->server->transactionType = 'post-publish-calendar';
177
+
178
+            // Getting ACL info
179
+            $acl = $this->server->getPlugin('acl');
180
+
181
+            // If there's no ACL support, we allow everything
182
+            if ($acl) {
183
+                $acl->checkPrivileges($path, '{DAV:}write');
184
+            }
185
+
186
+            $node->setPublishStatus(true);
187
+
188
+            // iCloud sends back the 202, so we will too.
189
+            $response->setStatus(202);
190
+
191
+            // Adding this because sending a response body may cause issues,
192
+            // and I wanted some type of indicator the response was handled.
193
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
194
+
195
+            // Breaking the event chain
196
+            return false;
197
+
198
+            case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
+
200
+            // We can only deal with IShareableCalendar objects
201
+            if (!$node instanceof Calendar) {
202
+                return;
203
+            }
204
+            $this->server->transactionType = 'post-unpublish-calendar';
205
+
206
+            // Getting ACL info
207
+            $acl = $this->server->getPlugin('acl');
208
+
209
+            // If there's no ACL support, we allow everything
210
+            if ($acl) {
211
+                $acl->checkPrivileges($path, '{DAV:}write');
212
+            }
213
+
214
+            $node->setPublishStatus(false);
215
+
216
+            $response->setStatus(200);
217
+
218
+            // Adding this because sending a response body may cause issues,
219
+            // and I wanted some type of indicator the response was handled.
220
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
221
+
222
+            // Breaking the event chain
223
+            return false;
224 224
 
225
-		}
226
-	}
225
+        }
226
+    }
227 227
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string
91 91
 	 */
92
-	public function getPluginName()	{
92
+	public function getPluginName() {
93 93
 		return 'oc-calendar-publishing';
94 94
 	}
95 95
 
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 		$this->server = $server;
108 108
 
109 109
 		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
110
+		$this->server->on('propFind', [$this, 'propFind']);
111 111
 	}
112 112
 
113 113
 	public function propFind(PropFind $propFind, INode $node) {
114 114
 		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
115
+			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) {
116 116
 				if ($node->getPublishStatus()) {
117 117
 					// We return the publish-url only if the calendar is published.
118 118
 					$token = $node->getPublishStatus();
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/AddressBookRoot.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
 	/**
32 32
 	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
33
+	 * @param CardDavBackend $carddavBackend
34 34
 	 * @param string $principalPrefix
35 35
 	 */
36 36
 	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,46 +25,46 @@
 block discarded – undo
25 25
 
26 26
 class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
27 27
 
28
-	/** @var IL10N */
29
-	protected $l10n;
28
+    /** @var IL10N */
29
+    protected $l10n;
30 30
 
31
-	/**
32
-	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
-	 * @param string $principalPrefix
35
-	 */
36
-	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
-		parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
-		$this->l10n = \OC::$server->getL10N('dav');
39
-	}
31
+    /**
32
+     * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
+     * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
+     * @param string $principalPrefix
35
+     */
36
+    public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
+        parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
+        $this->l10n = \OC::$server->getL10N('dav');
39
+    }
40 40
 
41
-	/**
42
-	 * This method returns a node for a principal.
43
-	 *
44
-	 * The passed array contains principal information, and is guaranteed to
45
-	 * at least contain a uri item. Other properties may or may not be
46
-	 * supplied by the authentication backend.
47
-	 *
48
-	 * @param array $principal
49
-	 * @return \Sabre\DAV\INode
50
-	 */
51
-	function getChildForPrincipal(array $principal) {
41
+    /**
42
+     * This method returns a node for a principal.
43
+     *
44
+     * The passed array contains principal information, and is guaranteed to
45
+     * at least contain a uri item. Other properties may or may not be
46
+     * supplied by the authentication backend.
47
+     *
48
+     * @param array $principal
49
+     * @return \Sabre\DAV\INode
50
+     */
51
+    function getChildForPrincipal(array $principal) {
52 52
 
53
-		return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
53
+        return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
54 54
 
55
-	}
55
+    }
56 56
 
57
-	function getName() {
57
+    function getName() {
58 58
 
59
-		if ($this->principalPrefix === 'principals') {
60
-			return parent::getName();
61
-		}
62
-		// Grabbing all the components of the principal path.
63
-		$parts = explode('/', $this->principalPrefix);
59
+        if ($this->principalPrefix === 'principals') {
60
+            return parent::getName();
61
+        }
62
+        // Grabbing all the components of the principal path.
63
+        $parts = explode('/', $this->principalPrefix);
64 64
 
65
-		// We are only interested in the second part.
66
-		return $parts[1];
65
+        // We are only interested in the second part.
66
+        return $parts[1];
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
lib/private/Share20/DefaultShareProvider.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -770,7 +770,7 @@
 block discarded – undo
770 770
 
771 771
 	/**
772 772
 	 * @param Share[] $shares
773
-	 * @param $userId
773
+	 * @param string $userId
774 774
 	 * @return Share[] The updates shares if no update is found for a share return the original
775 775
 	 */
776 776
 	private function resolveGroupShares($shares, $userId) {
Please login to merge, or discard this patch.
Indentation   +1101 added lines, -1101 removed lines patch added patch discarded remove patch
@@ -47,1138 +47,1138 @@
 block discarded – undo
47 47
  */
48 48
 class DefaultShareProvider implements IShareProvider {
49 49
 
50
-	// Special share type for user modified group shares
51
-	const SHARE_TYPE_USERGROUP = 2;
52
-
53
-	/** @var IDBConnection */
54
-	private $dbConn;
55
-
56
-	/** @var IUserManager */
57
-	private $userManager;
58
-
59
-	/** @var IGroupManager */
60
-	private $groupManager;
61
-
62
-	/** @var IRootFolder */
63
-	private $rootFolder;
64
-
65
-	/**
66
-	 * DefaultShareProvider constructor.
67
-	 *
68
-	 * @param IDBConnection $connection
69
-	 * @param IUserManager $userManager
70
-	 * @param IGroupManager $groupManager
71
-	 * @param IRootFolder $rootFolder
72
-	 */
73
-	public function __construct(
74
-			IDBConnection $connection,
75
-			IUserManager $userManager,
76
-			IGroupManager $groupManager,
77
-			IRootFolder $rootFolder) {
78
-		$this->dbConn = $connection;
79
-		$this->userManager = $userManager;
80
-		$this->groupManager = $groupManager;
81
-		$this->rootFolder = $rootFolder;
82
-	}
83
-
84
-	/**
85
-	 * Return the identifier of this provider.
86
-	 *
87
-	 * @return string Containing only [a-zA-Z0-9]
88
-	 */
89
-	public function identifier() {
90
-		return 'ocinternal';
91
-	}
92
-
93
-	/**
94
-	 * Share a path
95
-	 *
96
-	 * @param \OCP\Share\IShare $share
97
-	 * @return \OCP\Share\IShare The share object
98
-	 * @throws ShareNotFound
99
-	 * @throws \Exception
100
-	 */
101
-	public function create(\OCP\Share\IShare $share) {
102
-		$qb = $this->dbConn->getQueryBuilder();
103
-
104
-		$qb->insert('share');
105
-		$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
106
-
107
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
108
-			//Set the UID of the user we share with
109
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
110
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
111
-			//Set the GID of the group we share with
112
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
113
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
114
-			//Set the token of the share
115
-			$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
116
-
117
-			//If a password is set store it
118
-			if ($share->getPassword() !== null) {
119
-				$qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
120
-			}
121
-
122
-			//If an expiration date is set store it
123
-			if ($share->getExpirationDate() !== null) {
124
-				$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
125
-			}
126
-
127
-			if (method_exists($share, 'getParent')) {
128
-				$qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
129
-			}
130
-		} else {
131
-			throw new \Exception('invalid share type!');
132
-		}
133
-
134
-		// Set what is shares
135
-		$qb->setValue('item_type', $qb->createParameter('itemType'));
136
-		if ($share->getNode() instanceof \OCP\Files\File) {
137
-			$qb->setParameter('itemType', 'file');
138
-		} else {
139
-			$qb->setParameter('itemType', 'folder');
140
-		}
141
-
142
-		// Set the file id
143
-		$qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
144
-		$qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
145
-
146
-		// set the permissions
147
-		$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
148
-
149
-		// Set who created this share
150
-		$qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
151
-
152
-		// Set who is the owner of this file/folder (and this the owner of the share)
153
-		$qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
154
-
155
-		// Set the file target
156
-		$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
157
-
158
-		// Set the time this share was created
159
-		$qb->setValue('stime', $qb->createNamedParameter(time()));
160
-
161
-		// insert the data and fetch the id of the share
162
-		$this->dbConn->beginTransaction();
163
-		$qb->execute();
164
-		$id = $this->dbConn->lastInsertId('*PREFIX*share');
165
-
166
-		// Now fetch the inserted share and create a complete share object
167
-		$qb = $this->dbConn->getQueryBuilder();
168
-		$qb->select('*')
169
-			->from('share')
170
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
171
-
172
-		$cursor = $qb->execute();
173
-		$data = $cursor->fetch();
174
-		$this->dbConn->commit();
175
-		$cursor->closeCursor();
176
-
177
-		if ($data === false) {
178
-			throw new ShareNotFound();
179
-		}
180
-
181
-		$share = $this->createShare($data);
182
-		return $share;
183
-	}
184
-
185
-	/**
186
-	 * Update a share
187
-	 *
188
-	 * @param \OCP\Share\IShare $share
189
-	 * @return \OCP\Share\IShare The share object
190
-	 */
191
-	public function update(\OCP\Share\IShare $share) {
192
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
193
-			/*
50
+    // Special share type for user modified group shares
51
+    const SHARE_TYPE_USERGROUP = 2;
52
+
53
+    /** @var IDBConnection */
54
+    private $dbConn;
55
+
56
+    /** @var IUserManager */
57
+    private $userManager;
58
+
59
+    /** @var IGroupManager */
60
+    private $groupManager;
61
+
62
+    /** @var IRootFolder */
63
+    private $rootFolder;
64
+
65
+    /**
66
+     * DefaultShareProvider constructor.
67
+     *
68
+     * @param IDBConnection $connection
69
+     * @param IUserManager $userManager
70
+     * @param IGroupManager $groupManager
71
+     * @param IRootFolder $rootFolder
72
+     */
73
+    public function __construct(
74
+            IDBConnection $connection,
75
+            IUserManager $userManager,
76
+            IGroupManager $groupManager,
77
+            IRootFolder $rootFolder) {
78
+        $this->dbConn = $connection;
79
+        $this->userManager = $userManager;
80
+        $this->groupManager = $groupManager;
81
+        $this->rootFolder = $rootFolder;
82
+    }
83
+
84
+    /**
85
+     * Return the identifier of this provider.
86
+     *
87
+     * @return string Containing only [a-zA-Z0-9]
88
+     */
89
+    public function identifier() {
90
+        return 'ocinternal';
91
+    }
92
+
93
+    /**
94
+     * Share a path
95
+     *
96
+     * @param \OCP\Share\IShare $share
97
+     * @return \OCP\Share\IShare The share object
98
+     * @throws ShareNotFound
99
+     * @throws \Exception
100
+     */
101
+    public function create(\OCP\Share\IShare $share) {
102
+        $qb = $this->dbConn->getQueryBuilder();
103
+
104
+        $qb->insert('share');
105
+        $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
106
+
107
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
108
+            //Set the UID of the user we share with
109
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
110
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
111
+            //Set the GID of the group we share with
112
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
113
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
114
+            //Set the token of the share
115
+            $qb->setValue('token', $qb->createNamedParameter($share->getToken()));
116
+
117
+            //If a password is set store it
118
+            if ($share->getPassword() !== null) {
119
+                $qb->setValue('password', $qb->createNamedParameter($share->getPassword()));
120
+            }
121
+
122
+            //If an expiration date is set store it
123
+            if ($share->getExpirationDate() !== null) {
124
+                $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
125
+            }
126
+
127
+            if (method_exists($share, 'getParent')) {
128
+                $qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
129
+            }
130
+        } else {
131
+            throw new \Exception('invalid share type!');
132
+        }
133
+
134
+        // Set what is shares
135
+        $qb->setValue('item_type', $qb->createParameter('itemType'));
136
+        if ($share->getNode() instanceof \OCP\Files\File) {
137
+            $qb->setParameter('itemType', 'file');
138
+        } else {
139
+            $qb->setParameter('itemType', 'folder');
140
+        }
141
+
142
+        // Set the file id
143
+        $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
144
+        $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
145
+
146
+        // set the permissions
147
+        $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
148
+
149
+        // Set who created this share
150
+        $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
151
+
152
+        // Set who is the owner of this file/folder (and this the owner of the share)
153
+        $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
154
+
155
+        // Set the file target
156
+        $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
157
+
158
+        // Set the time this share was created
159
+        $qb->setValue('stime', $qb->createNamedParameter(time()));
160
+
161
+        // insert the data and fetch the id of the share
162
+        $this->dbConn->beginTransaction();
163
+        $qb->execute();
164
+        $id = $this->dbConn->lastInsertId('*PREFIX*share');
165
+
166
+        // Now fetch the inserted share and create a complete share object
167
+        $qb = $this->dbConn->getQueryBuilder();
168
+        $qb->select('*')
169
+            ->from('share')
170
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
171
+
172
+        $cursor = $qb->execute();
173
+        $data = $cursor->fetch();
174
+        $this->dbConn->commit();
175
+        $cursor->closeCursor();
176
+
177
+        if ($data === false) {
178
+            throw new ShareNotFound();
179
+        }
180
+
181
+        $share = $this->createShare($data);
182
+        return $share;
183
+    }
184
+
185
+    /**
186
+     * Update a share
187
+     *
188
+     * @param \OCP\Share\IShare $share
189
+     * @return \OCP\Share\IShare The share object
190
+     */
191
+    public function update(\OCP\Share\IShare $share) {
192
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
193
+            /*
194 194
 			 * We allow updating the recipient on user shares.
195 195
 			 */
196
-			$qb = $this->dbConn->getQueryBuilder();
197
-			$qb->update('share')
198
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
199
-				->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
200
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
201
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
202
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
203
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
204
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
205
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
206
-				->execute();
207
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
208
-			$qb = $this->dbConn->getQueryBuilder();
209
-			$qb->update('share')
210
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
211
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
212
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
213
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
214
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
215
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
216
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
217
-				->execute();
218
-
219
-			/*
196
+            $qb = $this->dbConn->getQueryBuilder();
197
+            $qb->update('share')
198
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
199
+                ->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
200
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
201
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
202
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
203
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
204
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
205
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
206
+                ->execute();
207
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
208
+            $qb = $this->dbConn->getQueryBuilder();
209
+            $qb->update('share')
210
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
211
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
212
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
213
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
214
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
215
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
216
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
217
+                ->execute();
218
+
219
+            /*
220 220
 			 * Update all user defined group shares
221 221
 			 */
222
-			$qb = $this->dbConn->getQueryBuilder();
223
-			$qb->update('share')
224
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
225
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
226
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
227
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
228
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
229
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
230
-				->execute();
231
-
232
-			/*
222
+            $qb = $this->dbConn->getQueryBuilder();
223
+            $qb->update('share')
224
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
225
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
226
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
227
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
228
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
229
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
230
+                ->execute();
231
+
232
+            /*
233 233
 			 * Now update the permissions for all children that have not set it to 0
234 234
 			 */
235
-			$qb = $this->dbConn->getQueryBuilder();
236
-			$qb->update('share')
237
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
238
-				->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
239
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
240
-				->execute();
241
-
242
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
243
-			$qb = $this->dbConn->getQueryBuilder();
244
-			$qb->update('share')
245
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
246
-				->set('password', $qb->createNamedParameter($share->getPassword()))
247
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
248
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
249
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
250
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
251
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
252
-				->set('token', $qb->createNamedParameter($share->getToken()))
253
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
254
-				->execute();
255
-		}
256
-
257
-		return $share;
258
-	}
259
-
260
-	/**
261
-	 * Get all children of this share
262
-	 * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
263
-	 *
264
-	 * @param \OCP\Share\IShare $parent
265
-	 * @return \OCP\Share\IShare[]
266
-	 */
267
-	public function getChildren(\OCP\Share\IShare $parent) {
268
-		$children = [];
269
-
270
-		$qb = $this->dbConn->getQueryBuilder();
271
-		$qb->select('*')
272
-			->from('share')
273
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
274
-			->andWhere(
275
-				$qb->expr()->in(
276
-					'share_type',
277
-					$qb->createNamedParameter([
278
-						\OCP\Share::SHARE_TYPE_USER,
279
-						\OCP\Share::SHARE_TYPE_GROUP,
280
-						\OCP\Share::SHARE_TYPE_LINK,
281
-					], IQueryBuilder::PARAM_INT_ARRAY)
282
-				)
283
-			)
284
-			->andWhere($qb->expr()->orX(
285
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
286
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
287
-			))
288
-			->orderBy('id');
289
-
290
-		$cursor = $qb->execute();
291
-		while($data = $cursor->fetch()) {
292
-			$children[] = $this->createShare($data);
293
-		}
294
-		$cursor->closeCursor();
295
-
296
-		return $children;
297
-	}
298
-
299
-	/**
300
-	 * Delete a share
301
-	 *
302
-	 * @param \OCP\Share\IShare $share
303
-	 */
304
-	public function delete(\OCP\Share\IShare $share) {
305
-		$qb = $this->dbConn->getQueryBuilder();
306
-		$qb->delete('share')
307
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
308
-
309
-		/*
235
+            $qb = $this->dbConn->getQueryBuilder();
236
+            $qb->update('share')
237
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
238
+                ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
239
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
240
+                ->execute();
241
+
242
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
243
+            $qb = $this->dbConn->getQueryBuilder();
244
+            $qb->update('share')
245
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
246
+                ->set('password', $qb->createNamedParameter($share->getPassword()))
247
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
248
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
249
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
250
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
251
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
252
+                ->set('token', $qb->createNamedParameter($share->getToken()))
253
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
254
+                ->execute();
255
+        }
256
+
257
+        return $share;
258
+    }
259
+
260
+    /**
261
+     * Get all children of this share
262
+     * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
263
+     *
264
+     * @param \OCP\Share\IShare $parent
265
+     * @return \OCP\Share\IShare[]
266
+     */
267
+    public function getChildren(\OCP\Share\IShare $parent) {
268
+        $children = [];
269
+
270
+        $qb = $this->dbConn->getQueryBuilder();
271
+        $qb->select('*')
272
+            ->from('share')
273
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
274
+            ->andWhere(
275
+                $qb->expr()->in(
276
+                    'share_type',
277
+                    $qb->createNamedParameter([
278
+                        \OCP\Share::SHARE_TYPE_USER,
279
+                        \OCP\Share::SHARE_TYPE_GROUP,
280
+                        \OCP\Share::SHARE_TYPE_LINK,
281
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
282
+                )
283
+            )
284
+            ->andWhere($qb->expr()->orX(
285
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
286
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
287
+            ))
288
+            ->orderBy('id');
289
+
290
+        $cursor = $qb->execute();
291
+        while($data = $cursor->fetch()) {
292
+            $children[] = $this->createShare($data);
293
+        }
294
+        $cursor->closeCursor();
295
+
296
+        return $children;
297
+    }
298
+
299
+    /**
300
+     * Delete a share
301
+     *
302
+     * @param \OCP\Share\IShare $share
303
+     */
304
+    public function delete(\OCP\Share\IShare $share) {
305
+        $qb = $this->dbConn->getQueryBuilder();
306
+        $qb->delete('share')
307
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
308
+
309
+        /*
310 310
 		 * If the share is a group share delete all possible
311 311
 		 * user defined groups shares.
312 312
 		 */
313
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
314
-			$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
315
-		}
316
-
317
-		$qb->execute();
318
-	}
319
-
320
-	/**
321
-	 * Unshare a share from the recipient. If this is a group share
322
-	 * this means we need a special entry in the share db.
323
-	 *
324
-	 * @param \OCP\Share\IShare $share
325
-	 * @param string $recipient UserId of recipient
326
-	 * @throws BackendError
327
-	 * @throws ProviderException
328
-	 */
329
-	public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
330
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
331
-
332
-			$group = $this->groupManager->get($share->getSharedWith());
333
-			$user = $this->userManager->get($recipient);
334
-
335
-			if (is_null($group)) {
336
-				throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
337
-			}
338
-
339
-			if (!$group->inGroup($user)) {
340
-				throw new ProviderException('Recipient not in receiving group');
341
-			}
342
-
343
-			// Try to fetch user specific share
344
-			$qb = $this->dbConn->getQueryBuilder();
345
-			$stmt = $qb->select('*')
346
-				->from('share')
347
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
348
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
349
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
350
-				->andWhere($qb->expr()->orX(
351
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
352
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
353
-				))
354
-				->execute();
355
-
356
-			$data = $stmt->fetch();
357
-
358
-			/*
313
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
314
+            $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
315
+        }
316
+
317
+        $qb->execute();
318
+    }
319
+
320
+    /**
321
+     * Unshare a share from the recipient. If this is a group share
322
+     * this means we need a special entry in the share db.
323
+     *
324
+     * @param \OCP\Share\IShare $share
325
+     * @param string $recipient UserId of recipient
326
+     * @throws BackendError
327
+     * @throws ProviderException
328
+     */
329
+    public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
330
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
331
+
332
+            $group = $this->groupManager->get($share->getSharedWith());
333
+            $user = $this->userManager->get($recipient);
334
+
335
+            if (is_null($group)) {
336
+                throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
337
+            }
338
+
339
+            if (!$group->inGroup($user)) {
340
+                throw new ProviderException('Recipient not in receiving group');
341
+            }
342
+
343
+            // Try to fetch user specific share
344
+            $qb = $this->dbConn->getQueryBuilder();
345
+            $stmt = $qb->select('*')
346
+                ->from('share')
347
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
348
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
349
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
350
+                ->andWhere($qb->expr()->orX(
351
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
352
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
353
+                ))
354
+                ->execute();
355
+
356
+            $data = $stmt->fetch();
357
+
358
+            /*
359 359
 			 * Check if there already is a user specific group share.
360 360
 			 * If there is update it (if required).
361 361
 			 */
362
-			if ($data === false) {
363
-				$qb = $this->dbConn->getQueryBuilder();
364
-
365
-				$type = $share->getNodeType();
366
-
367
-				//Insert new share
368
-				$qb->insert('share')
369
-					->values([
370
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
371
-						'share_with' => $qb->createNamedParameter($recipient),
372
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
373
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
374
-						'parent' => $qb->createNamedParameter($share->getId()),
375
-						'item_type' => $qb->createNamedParameter($type),
376
-						'item_source' => $qb->createNamedParameter($share->getNodeId()),
377
-						'file_source' => $qb->createNamedParameter($share->getNodeId()),
378
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
379
-						'permissions' => $qb->createNamedParameter(0),
380
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
381
-					])->execute();
382
-
383
-			} else if ($data['permissions'] !== 0) {
384
-
385
-				// Update existing usergroup share
386
-				$qb = $this->dbConn->getQueryBuilder();
387
-				$qb->update('share')
388
-					->set('permissions', $qb->createNamedParameter(0))
389
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
390
-					->execute();
391
-			}
392
-
393
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
394
-
395
-			if ($share->getSharedWith() !== $recipient) {
396
-				throw new ProviderException('Recipient does not match');
397
-			}
398
-
399
-			// We can just delete user and link shares
400
-			$this->delete($share);
401
-		} else {
402
-			throw new ProviderException('Invalid shareType');
403
-		}
404
-	}
405
-
406
-	/**
407
-	 * @inheritdoc
408
-	 */
409
-	public function move(\OCP\Share\IShare $share, $recipient) {
410
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
411
-			// Just update the target
412
-			$qb = $this->dbConn->getQueryBuilder();
413
-			$qb->update('share')
414
-				->set('file_target', $qb->createNamedParameter($share->getTarget()))
415
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
416
-				->execute();
417
-
418
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
419
-
420
-			// Check if there is a usergroup share
421
-			$qb = $this->dbConn->getQueryBuilder();
422
-			$stmt = $qb->select('id')
423
-				->from('share')
424
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
425
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
426
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
427
-				->andWhere($qb->expr()->orX(
428
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
429
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
430
-				))
431
-				->setMaxResults(1)
432
-				->execute();
433
-
434
-			$data = $stmt->fetch();
435
-			$stmt->closeCursor();
436
-
437
-			if ($data === false) {
438
-				// No usergroup share yet. Create one.
439
-				$qb = $this->dbConn->getQueryBuilder();
440
-				$qb->insert('share')
441
-					->values([
442
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
443
-						'share_with' => $qb->createNamedParameter($recipient),
444
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
445
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
446
-						'parent' => $qb->createNamedParameter($share->getId()),
447
-						'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
448
-						'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
449
-						'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
450
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
451
-						'permissions' => $qb->createNamedParameter($share->getPermissions()),
452
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
453
-					])->execute();
454
-			} else {
455
-				// Already a usergroup share. Update it.
456
-				$qb = $this->dbConn->getQueryBuilder();
457
-				$qb->update('share')
458
-					->set('file_target', $qb->createNamedParameter($share->getTarget()))
459
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
460
-					->execute();
461
-			}
462
-		}
463
-
464
-		return $share;
465
-	}
466
-
467
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
468
-		$qb = $this->dbConn->getQueryBuilder();
469
-		$qb->select('*')
470
-			->from('share', 's')
471
-			->andWhere($qb->expr()->orX(
472
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
473
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
474
-			));
475
-
476
-		$qb->andWhere($qb->expr()->orX(
477
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
478
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
479
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
480
-		));
481
-
482
-		/**
483
-		 * Reshares for this user are shares where they are the owner.
484
-		 */
485
-		if ($reshares === false) {
486
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
487
-		} else {
488
-			$qb->andWhere(
489
-				$qb->expr()->orX(
490
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
491
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
492
-				)
493
-			);
494
-		}
495
-
496
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
497
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
498
-
499
-		$qb->orderBy('id');
500
-
501
-		$cursor = $qb->execute();
502
-		$shares = [];
503
-		while ($data = $cursor->fetch()) {
504
-			$shares[$data['fileid']][] = $this->createShare($data);
505
-		}
506
-		$cursor->closeCursor();
507
-
508
-		return $shares;
509
-	}
510
-
511
-	/**
512
-	 * @inheritdoc
513
-	 */
514
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
515
-		$qb = $this->dbConn->getQueryBuilder();
516
-		$qb->select('*')
517
-			->from('share')
518
-			->andWhere($qb->expr()->orX(
519
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
520
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
521
-			));
522
-
523
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
524
-
525
-		/**
526
-		 * Reshares for this user are shares where they are the owner.
527
-		 */
528
-		if ($reshares === false) {
529
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
530
-		} else {
531
-			$qb->andWhere(
532
-				$qb->expr()->orX(
533
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
534
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
535
-				)
536
-			);
537
-		}
538
-
539
-		if ($node !== null) {
540
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
541
-		}
542
-
543
-		if ($limit !== -1) {
544
-			$qb->setMaxResults($limit);
545
-		}
546
-
547
-		$qb->setFirstResult($offset);
548
-		$qb->orderBy('id');
549
-
550
-		$cursor = $qb->execute();
551
-		$shares = [];
552
-		while($data = $cursor->fetch()) {
553
-			$shares[] = $this->createShare($data);
554
-		}
555
-		$cursor->closeCursor();
556
-
557
-		return $shares;
558
-	}
559
-
560
-	/**
561
-	 * @inheritdoc
562
-	 */
563
-	public function getShareById($id, $recipientId = null) {
564
-		$qb = $this->dbConn->getQueryBuilder();
565
-
566
-		$qb->select('*')
567
-			->from('share')
568
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
569
-			->andWhere(
570
-				$qb->expr()->in(
571
-					'share_type',
572
-					$qb->createNamedParameter([
573
-						\OCP\Share::SHARE_TYPE_USER,
574
-						\OCP\Share::SHARE_TYPE_GROUP,
575
-						\OCP\Share::SHARE_TYPE_LINK,
576
-					], IQueryBuilder::PARAM_INT_ARRAY)
577
-				)
578
-			)
579
-			->andWhere($qb->expr()->orX(
580
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
581
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
582
-			));
583
-
584
-		$cursor = $qb->execute();
585
-		$data = $cursor->fetch();
586
-		$cursor->closeCursor();
587
-
588
-		if ($data === false) {
589
-			throw new ShareNotFound();
590
-		}
591
-
592
-		try {
593
-			$share = $this->createShare($data);
594
-		} catch (InvalidShare $e) {
595
-			throw new ShareNotFound();
596
-		}
597
-
598
-		// If the recipient is set for a group share resolve to that user
599
-		if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
600
-			$share = $this->resolveGroupShares([$share], $recipientId)[0];
601
-		}
602
-
603
-		return $share;
604
-	}
605
-
606
-	/**
607
-	 * Get shares for a given path
608
-	 *
609
-	 * @param \OCP\Files\Node $path
610
-	 * @return \OCP\Share\IShare[]
611
-	 */
612
-	public function getSharesByPath(Node $path) {
613
-		$qb = $this->dbConn->getQueryBuilder();
614
-
615
-		$cursor = $qb->select('*')
616
-			->from('share')
617
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
618
-			->andWhere(
619
-				$qb->expr()->orX(
620
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
621
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
622
-				)
623
-			)
624
-			->andWhere($qb->expr()->orX(
625
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
626
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
627
-			))
628
-			->execute();
629
-
630
-		$shares = [];
631
-		while($data = $cursor->fetch()) {
632
-			$shares[] = $this->createShare($data);
633
-		}
634
-		$cursor->closeCursor();
635
-
636
-		return $shares;
637
-	}
638
-
639
-	/**
640
-	 * Returns whether the given database result can be interpreted as
641
-	 * a share with accessible file (not trashed, not deleted)
642
-	 */
643
-	private function isAccessibleResult($data) {
644
-		// exclude shares leading to deleted file entries
645
-		if ($data['fileid'] === null) {
646
-			return false;
647
-		}
648
-
649
-		// exclude shares leading to trashbin on home storages
650
-		$pathSections = explode('/', $data['path'], 2);
651
-		// FIXME: would not detect rare md5'd home storage case properly
652
-		if ($pathSections[0] !== 'files'
653
-		    	&& in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) {
654
-			return false;
655
-		}
656
-		return true;
657
-	}
658
-
659
-	/**
660
-	 * @inheritdoc
661
-	 */
662
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
663
-		/** @var Share[] $shares */
664
-		$shares = [];
665
-
666
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
667
-			//Get shares directly with this user
668
-			$qb = $this->dbConn->getQueryBuilder();
669
-			$qb->select('s.*',
670
-				'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
671
-				'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
672
-				'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
673
-			)
674
-				->selectAlias('st.id', 'storage_string_id')
675
-				->from('share', 's')
676
-				->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
677
-				->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
678
-
679
-			// Order by id
680
-			$qb->orderBy('s.id');
681
-
682
-			// Set limit and offset
683
-			if ($limit !== -1) {
684
-				$qb->setMaxResults($limit);
685
-			}
686
-			$qb->setFirstResult($offset);
687
-
688
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
689
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
690
-				->andWhere($qb->expr()->orX(
691
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
692
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
693
-				));
694
-
695
-			// Filter by node if provided
696
-			if ($node !== null) {
697
-				$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
698
-			}
699
-
700
-			$cursor = $qb->execute();
701
-
702
-			while($data = $cursor->fetch()) {
703
-				if ($this->isAccessibleResult($data)) {
704
-					$shares[] = $this->createShare($data);
705
-				}
706
-			}
707
-			$cursor->closeCursor();
708
-
709
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
710
-			$user = $this->userManager->get($userId);
711
-			$allGroups = $this->groupManager->getUserGroups($user);
712
-
713
-			/** @var Share[] $shares2 */
714
-			$shares2 = [];
715
-
716
-			$start = 0;
717
-			while(true) {
718
-				$groups = array_slice($allGroups, $start, 100);
719
-				$start += 100;
720
-
721
-				if ($groups === []) {
722
-					break;
723
-				}
724
-
725
-				$qb = $this->dbConn->getQueryBuilder();
726
-				$qb->select('s.*',
727
-					'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
728
-					'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
729
-					'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
730
-				)
731
-					->selectAlias('st.id', 'storage_string_id')
732
-					->from('share', 's')
733
-					->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
734
-					->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
735
-					->orderBy('s.id')
736
-					->setFirstResult(0);
737
-
738
-				if ($limit !== -1) {
739
-					$qb->setMaxResults($limit - count($shares));
740
-				}
741
-
742
-				// Filter by node if provided
743
-				if ($node !== null) {
744
-					$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
745
-				}
746
-
747
-				$groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
748
-
749
-				$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
750
-					->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
751
-						$groups,
752
-						IQueryBuilder::PARAM_STR_ARRAY
753
-					)))
754
-					->andWhere($qb->expr()->orX(
755
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
756
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
757
-					));
758
-
759
-				$cursor = $qb->execute();
760
-				while($data = $cursor->fetch()) {
761
-					if ($offset > 0) {
762
-						$offset--;
763
-						continue;
764
-					}
765
-
766
-					if ($this->isAccessibleResult($data)) {
767
-						$shares2[] = $this->createShare($data);
768
-					}
769
-				}
770
-				$cursor->closeCursor();
771
-			}
772
-
773
-			/*
362
+            if ($data === false) {
363
+                $qb = $this->dbConn->getQueryBuilder();
364
+
365
+                $type = $share->getNodeType();
366
+
367
+                //Insert new share
368
+                $qb->insert('share')
369
+                    ->values([
370
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
371
+                        'share_with' => $qb->createNamedParameter($recipient),
372
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
373
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
374
+                        'parent' => $qb->createNamedParameter($share->getId()),
375
+                        'item_type' => $qb->createNamedParameter($type),
376
+                        'item_source' => $qb->createNamedParameter($share->getNodeId()),
377
+                        'file_source' => $qb->createNamedParameter($share->getNodeId()),
378
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
379
+                        'permissions' => $qb->createNamedParameter(0),
380
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
381
+                    ])->execute();
382
+
383
+            } else if ($data['permissions'] !== 0) {
384
+
385
+                // Update existing usergroup share
386
+                $qb = $this->dbConn->getQueryBuilder();
387
+                $qb->update('share')
388
+                    ->set('permissions', $qb->createNamedParameter(0))
389
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
390
+                    ->execute();
391
+            }
392
+
393
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
394
+
395
+            if ($share->getSharedWith() !== $recipient) {
396
+                throw new ProviderException('Recipient does not match');
397
+            }
398
+
399
+            // We can just delete user and link shares
400
+            $this->delete($share);
401
+        } else {
402
+            throw new ProviderException('Invalid shareType');
403
+        }
404
+    }
405
+
406
+    /**
407
+     * @inheritdoc
408
+     */
409
+    public function move(\OCP\Share\IShare $share, $recipient) {
410
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
411
+            // Just update the target
412
+            $qb = $this->dbConn->getQueryBuilder();
413
+            $qb->update('share')
414
+                ->set('file_target', $qb->createNamedParameter($share->getTarget()))
415
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
416
+                ->execute();
417
+
418
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
419
+
420
+            // Check if there is a usergroup share
421
+            $qb = $this->dbConn->getQueryBuilder();
422
+            $stmt = $qb->select('id')
423
+                ->from('share')
424
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
425
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
426
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
427
+                ->andWhere($qb->expr()->orX(
428
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
429
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
430
+                ))
431
+                ->setMaxResults(1)
432
+                ->execute();
433
+
434
+            $data = $stmt->fetch();
435
+            $stmt->closeCursor();
436
+
437
+            if ($data === false) {
438
+                // No usergroup share yet. Create one.
439
+                $qb = $this->dbConn->getQueryBuilder();
440
+                $qb->insert('share')
441
+                    ->values([
442
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
443
+                        'share_with' => $qb->createNamedParameter($recipient),
444
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
445
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
446
+                        'parent' => $qb->createNamedParameter($share->getId()),
447
+                        'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
448
+                        'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
449
+                        'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
450
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
451
+                        'permissions' => $qb->createNamedParameter($share->getPermissions()),
452
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
453
+                    ])->execute();
454
+            } else {
455
+                // Already a usergroup share. Update it.
456
+                $qb = $this->dbConn->getQueryBuilder();
457
+                $qb->update('share')
458
+                    ->set('file_target', $qb->createNamedParameter($share->getTarget()))
459
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
460
+                    ->execute();
461
+            }
462
+        }
463
+
464
+        return $share;
465
+    }
466
+
467
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
468
+        $qb = $this->dbConn->getQueryBuilder();
469
+        $qb->select('*')
470
+            ->from('share', 's')
471
+            ->andWhere($qb->expr()->orX(
472
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
473
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
474
+            ));
475
+
476
+        $qb->andWhere($qb->expr()->orX(
477
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
478
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
479
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
480
+        ));
481
+
482
+        /**
483
+         * Reshares for this user are shares where they are the owner.
484
+         */
485
+        if ($reshares === false) {
486
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
487
+        } else {
488
+            $qb->andWhere(
489
+                $qb->expr()->orX(
490
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
491
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
492
+                )
493
+            );
494
+        }
495
+
496
+        $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
497
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
498
+
499
+        $qb->orderBy('id');
500
+
501
+        $cursor = $qb->execute();
502
+        $shares = [];
503
+        while ($data = $cursor->fetch()) {
504
+            $shares[$data['fileid']][] = $this->createShare($data);
505
+        }
506
+        $cursor->closeCursor();
507
+
508
+        return $shares;
509
+    }
510
+
511
+    /**
512
+     * @inheritdoc
513
+     */
514
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
515
+        $qb = $this->dbConn->getQueryBuilder();
516
+        $qb->select('*')
517
+            ->from('share')
518
+            ->andWhere($qb->expr()->orX(
519
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
520
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
521
+            ));
522
+
523
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
524
+
525
+        /**
526
+         * Reshares for this user are shares where they are the owner.
527
+         */
528
+        if ($reshares === false) {
529
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
530
+        } else {
531
+            $qb->andWhere(
532
+                $qb->expr()->orX(
533
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
534
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
535
+                )
536
+            );
537
+        }
538
+
539
+        if ($node !== null) {
540
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
541
+        }
542
+
543
+        if ($limit !== -1) {
544
+            $qb->setMaxResults($limit);
545
+        }
546
+
547
+        $qb->setFirstResult($offset);
548
+        $qb->orderBy('id');
549
+
550
+        $cursor = $qb->execute();
551
+        $shares = [];
552
+        while($data = $cursor->fetch()) {
553
+            $shares[] = $this->createShare($data);
554
+        }
555
+        $cursor->closeCursor();
556
+
557
+        return $shares;
558
+    }
559
+
560
+    /**
561
+     * @inheritdoc
562
+     */
563
+    public function getShareById($id, $recipientId = null) {
564
+        $qb = $this->dbConn->getQueryBuilder();
565
+
566
+        $qb->select('*')
567
+            ->from('share')
568
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
569
+            ->andWhere(
570
+                $qb->expr()->in(
571
+                    'share_type',
572
+                    $qb->createNamedParameter([
573
+                        \OCP\Share::SHARE_TYPE_USER,
574
+                        \OCP\Share::SHARE_TYPE_GROUP,
575
+                        \OCP\Share::SHARE_TYPE_LINK,
576
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
577
+                )
578
+            )
579
+            ->andWhere($qb->expr()->orX(
580
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
581
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
582
+            ));
583
+
584
+        $cursor = $qb->execute();
585
+        $data = $cursor->fetch();
586
+        $cursor->closeCursor();
587
+
588
+        if ($data === false) {
589
+            throw new ShareNotFound();
590
+        }
591
+
592
+        try {
593
+            $share = $this->createShare($data);
594
+        } catch (InvalidShare $e) {
595
+            throw new ShareNotFound();
596
+        }
597
+
598
+        // If the recipient is set for a group share resolve to that user
599
+        if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
600
+            $share = $this->resolveGroupShares([$share], $recipientId)[0];
601
+        }
602
+
603
+        return $share;
604
+    }
605
+
606
+    /**
607
+     * Get shares for a given path
608
+     *
609
+     * @param \OCP\Files\Node $path
610
+     * @return \OCP\Share\IShare[]
611
+     */
612
+    public function getSharesByPath(Node $path) {
613
+        $qb = $this->dbConn->getQueryBuilder();
614
+
615
+        $cursor = $qb->select('*')
616
+            ->from('share')
617
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
618
+            ->andWhere(
619
+                $qb->expr()->orX(
620
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
621
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
622
+                )
623
+            )
624
+            ->andWhere($qb->expr()->orX(
625
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
626
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
627
+            ))
628
+            ->execute();
629
+
630
+        $shares = [];
631
+        while($data = $cursor->fetch()) {
632
+            $shares[] = $this->createShare($data);
633
+        }
634
+        $cursor->closeCursor();
635
+
636
+        return $shares;
637
+    }
638
+
639
+    /**
640
+     * Returns whether the given database result can be interpreted as
641
+     * a share with accessible file (not trashed, not deleted)
642
+     */
643
+    private function isAccessibleResult($data) {
644
+        // exclude shares leading to deleted file entries
645
+        if ($data['fileid'] === null) {
646
+            return false;
647
+        }
648
+
649
+        // exclude shares leading to trashbin on home storages
650
+        $pathSections = explode('/', $data['path'], 2);
651
+        // FIXME: would not detect rare md5'd home storage case properly
652
+        if ($pathSections[0] !== 'files'
653
+                && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) {
654
+            return false;
655
+        }
656
+        return true;
657
+    }
658
+
659
+    /**
660
+     * @inheritdoc
661
+     */
662
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
663
+        /** @var Share[] $shares */
664
+        $shares = [];
665
+
666
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
667
+            //Get shares directly with this user
668
+            $qb = $this->dbConn->getQueryBuilder();
669
+            $qb->select('s.*',
670
+                'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
671
+                'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
672
+                'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
673
+            )
674
+                ->selectAlias('st.id', 'storage_string_id')
675
+                ->from('share', 's')
676
+                ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
677
+                ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
678
+
679
+            // Order by id
680
+            $qb->orderBy('s.id');
681
+
682
+            // Set limit and offset
683
+            if ($limit !== -1) {
684
+                $qb->setMaxResults($limit);
685
+            }
686
+            $qb->setFirstResult($offset);
687
+
688
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
689
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
690
+                ->andWhere($qb->expr()->orX(
691
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
692
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
693
+                ));
694
+
695
+            // Filter by node if provided
696
+            if ($node !== null) {
697
+                $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
698
+            }
699
+
700
+            $cursor = $qb->execute();
701
+
702
+            while($data = $cursor->fetch()) {
703
+                if ($this->isAccessibleResult($data)) {
704
+                    $shares[] = $this->createShare($data);
705
+                }
706
+            }
707
+            $cursor->closeCursor();
708
+
709
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
710
+            $user = $this->userManager->get($userId);
711
+            $allGroups = $this->groupManager->getUserGroups($user);
712
+
713
+            /** @var Share[] $shares2 */
714
+            $shares2 = [];
715
+
716
+            $start = 0;
717
+            while(true) {
718
+                $groups = array_slice($allGroups, $start, 100);
719
+                $start += 100;
720
+
721
+                if ($groups === []) {
722
+                    break;
723
+                }
724
+
725
+                $qb = $this->dbConn->getQueryBuilder();
726
+                $qb->select('s.*',
727
+                    'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
728
+                    'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime',
729
+                    'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum'
730
+                )
731
+                    ->selectAlias('st.id', 'storage_string_id')
732
+                    ->from('share', 's')
733
+                    ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
734
+                    ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
735
+                    ->orderBy('s.id')
736
+                    ->setFirstResult(0);
737
+
738
+                if ($limit !== -1) {
739
+                    $qb->setMaxResults($limit - count($shares));
740
+                }
741
+
742
+                // Filter by node if provided
743
+                if ($node !== null) {
744
+                    $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
745
+                }
746
+
747
+                $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
748
+
749
+                $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
750
+                    ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
751
+                        $groups,
752
+                        IQueryBuilder::PARAM_STR_ARRAY
753
+                    )))
754
+                    ->andWhere($qb->expr()->orX(
755
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
756
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
757
+                    ));
758
+
759
+                $cursor = $qb->execute();
760
+                while($data = $cursor->fetch()) {
761
+                    if ($offset > 0) {
762
+                        $offset--;
763
+                        continue;
764
+                    }
765
+
766
+                    if ($this->isAccessibleResult($data)) {
767
+                        $shares2[] = $this->createShare($data);
768
+                    }
769
+                }
770
+                $cursor->closeCursor();
771
+            }
772
+
773
+            /*
774 774
  			 * Resolve all group shares to user specific shares
775 775
  			 */
776
-			$shares = $this->resolveGroupShares($shares2, $userId);
777
-		} else {
778
-			throw new BackendError('Invalid backend');
779
-		}
780
-
781
-
782
-		return $shares;
783
-	}
784
-
785
-	/**
786
-	 * Get a share by token
787
-	 *
788
-	 * @param string $token
789
-	 * @return \OCP\Share\IShare
790
-	 * @throws ShareNotFound
791
-	 */
792
-	public function getShareByToken($token) {
793
-		$qb = $this->dbConn->getQueryBuilder();
794
-
795
-		$cursor = $qb->select('*')
796
-			->from('share')
797
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
798
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
799
-			->andWhere($qb->expr()->orX(
800
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
801
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
802
-			))
803
-			->execute();
804
-
805
-		$data = $cursor->fetch();
806
-
807
-		if ($data === false) {
808
-			throw new ShareNotFound();
809
-		}
810
-
811
-		try {
812
-			$share = $this->createShare($data);
813
-		} catch (InvalidShare $e) {
814
-			throw new ShareNotFound();
815
-		}
816
-
817
-		return $share;
818
-	}
819
-
820
-	/**
821
-	 * Create a share object from an database row
822
-	 *
823
-	 * @param mixed[] $data
824
-	 * @return \OCP\Share\IShare
825
-	 * @throws InvalidShare
826
-	 */
827
-	private function createShare($data) {
828
-		$share = new Share($this->rootFolder, $this->userManager);
829
-		$share->setId((int)$data['id'])
830
-			->setShareType((int)$data['share_type'])
831
-			->setPermissions((int)$data['permissions'])
832
-			->setTarget($data['file_target'])
833
-			->setMailSend((bool)$data['mail_send']);
834
-
835
-		$shareTime = new \DateTime();
836
-		$shareTime->setTimestamp((int)$data['stime']);
837
-		$share->setShareTime($shareTime);
838
-
839
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
840
-			$share->setSharedWith($data['share_with']);
841
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
842
-			$share->setSharedWith($data['share_with']);
843
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
844
-			$share->setPassword($data['password']);
845
-			$share->setToken($data['token']);
846
-		}
847
-
848
-		$share->setSharedBy($data['uid_initiator']);
849
-		$share->setShareOwner($data['uid_owner']);
850
-
851
-		$share->setNodeId((int)$data['file_source']);
852
-		$share->setNodeType($data['item_type']);
853
-
854
-		if ($data['expiration'] !== null) {
855
-			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
856
-			$share->setExpirationDate($expiration);
857
-		}
858
-
859
-		if (isset($data['f_permissions'])) {
860
-			$entryData = $data;
861
-			$entryData['permissions'] = $entryData['f_permissions'];
862
-			$entryData['parent'] = $entryData['f_parent'];;
863
-			$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
864
-				\OC::$server->getMimeTypeLoader()));
865
-		}
866
-
867
-		$share->setProviderId($this->identifier());
868
-
869
-		return $share;
870
-	}
871
-
872
-	/**
873
-	 * @param Share[] $shares
874
-	 * @param $userId
875
-	 * @return Share[] The updates shares if no update is found for a share return the original
876
-	 */
877
-	private function resolveGroupShares($shares, $userId) {
878
-		$result = [];
879
-
880
-		$start = 0;
881
-		while(true) {
882
-			/** @var Share[] $shareSlice */
883
-			$shareSlice = array_slice($shares, $start, 100);
884
-			$start += 100;
885
-
886
-			if ($shareSlice === []) {
887
-				break;
888
-			}
889
-
890
-			/** @var int[] $ids */
891
-			$ids = [];
892
-			/** @var Share[] $shareMap */
893
-			$shareMap = [];
894
-
895
-			foreach ($shareSlice as $share) {
896
-				$ids[] = (int)$share->getId();
897
-				$shareMap[$share->getId()] = $share;
898
-			}
899
-
900
-			$qb = $this->dbConn->getQueryBuilder();
901
-
902
-			$query = $qb->select('*')
903
-				->from('share')
904
-				->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
905
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
906
-				->andWhere($qb->expr()->orX(
907
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
908
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
909
-				));
910
-
911
-			$stmt = $query->execute();
912
-
913
-			while($data = $stmt->fetch()) {
914
-				$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
915
-				$shareMap[$data['parent']]->setTarget($data['file_target']);
916
-			}
917
-
918
-			$stmt->closeCursor();
919
-
920
-			foreach ($shareMap as $share) {
921
-				$result[] = $share;
922
-			}
923
-		}
924
-
925
-		return $result;
926
-	}
927
-
928
-	/**
929
-	 * A user is deleted from the system
930
-	 * So clean up the relevant shares.
931
-	 *
932
-	 * @param string $uid
933
-	 * @param int $shareType
934
-	 */
935
-	public function userDeleted($uid, $shareType) {
936
-		$qb = $this->dbConn->getQueryBuilder();
937
-
938
-		$qb->delete('share');
939
-
940
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
941
-			/*
776
+            $shares = $this->resolveGroupShares($shares2, $userId);
777
+        } else {
778
+            throw new BackendError('Invalid backend');
779
+        }
780
+
781
+
782
+        return $shares;
783
+    }
784
+
785
+    /**
786
+     * Get a share by token
787
+     *
788
+     * @param string $token
789
+     * @return \OCP\Share\IShare
790
+     * @throws ShareNotFound
791
+     */
792
+    public function getShareByToken($token) {
793
+        $qb = $this->dbConn->getQueryBuilder();
794
+
795
+        $cursor = $qb->select('*')
796
+            ->from('share')
797
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
798
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
799
+            ->andWhere($qb->expr()->orX(
800
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
801
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
802
+            ))
803
+            ->execute();
804
+
805
+        $data = $cursor->fetch();
806
+
807
+        if ($data === false) {
808
+            throw new ShareNotFound();
809
+        }
810
+
811
+        try {
812
+            $share = $this->createShare($data);
813
+        } catch (InvalidShare $e) {
814
+            throw new ShareNotFound();
815
+        }
816
+
817
+        return $share;
818
+    }
819
+
820
+    /**
821
+     * Create a share object from an database row
822
+     *
823
+     * @param mixed[] $data
824
+     * @return \OCP\Share\IShare
825
+     * @throws InvalidShare
826
+     */
827
+    private function createShare($data) {
828
+        $share = new Share($this->rootFolder, $this->userManager);
829
+        $share->setId((int)$data['id'])
830
+            ->setShareType((int)$data['share_type'])
831
+            ->setPermissions((int)$data['permissions'])
832
+            ->setTarget($data['file_target'])
833
+            ->setMailSend((bool)$data['mail_send']);
834
+
835
+        $shareTime = new \DateTime();
836
+        $shareTime->setTimestamp((int)$data['stime']);
837
+        $share->setShareTime($shareTime);
838
+
839
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
840
+            $share->setSharedWith($data['share_with']);
841
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
842
+            $share->setSharedWith($data['share_with']);
843
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
844
+            $share->setPassword($data['password']);
845
+            $share->setToken($data['token']);
846
+        }
847
+
848
+        $share->setSharedBy($data['uid_initiator']);
849
+        $share->setShareOwner($data['uid_owner']);
850
+
851
+        $share->setNodeId((int)$data['file_source']);
852
+        $share->setNodeType($data['item_type']);
853
+
854
+        if ($data['expiration'] !== null) {
855
+            $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
856
+            $share->setExpirationDate($expiration);
857
+        }
858
+
859
+        if (isset($data['f_permissions'])) {
860
+            $entryData = $data;
861
+            $entryData['permissions'] = $entryData['f_permissions'];
862
+            $entryData['parent'] = $entryData['f_parent'];;
863
+            $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
864
+                \OC::$server->getMimeTypeLoader()));
865
+        }
866
+
867
+        $share->setProviderId($this->identifier());
868
+
869
+        return $share;
870
+    }
871
+
872
+    /**
873
+     * @param Share[] $shares
874
+     * @param $userId
875
+     * @return Share[] The updates shares if no update is found for a share return the original
876
+     */
877
+    private function resolveGroupShares($shares, $userId) {
878
+        $result = [];
879
+
880
+        $start = 0;
881
+        while(true) {
882
+            /** @var Share[] $shareSlice */
883
+            $shareSlice = array_slice($shares, $start, 100);
884
+            $start += 100;
885
+
886
+            if ($shareSlice === []) {
887
+                break;
888
+            }
889
+
890
+            /** @var int[] $ids */
891
+            $ids = [];
892
+            /** @var Share[] $shareMap */
893
+            $shareMap = [];
894
+
895
+            foreach ($shareSlice as $share) {
896
+                $ids[] = (int)$share->getId();
897
+                $shareMap[$share->getId()] = $share;
898
+            }
899
+
900
+            $qb = $this->dbConn->getQueryBuilder();
901
+
902
+            $query = $qb->select('*')
903
+                ->from('share')
904
+                ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
905
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
906
+                ->andWhere($qb->expr()->orX(
907
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
908
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
909
+                ));
910
+
911
+            $stmt = $query->execute();
912
+
913
+            while($data = $stmt->fetch()) {
914
+                $shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
915
+                $shareMap[$data['parent']]->setTarget($data['file_target']);
916
+            }
917
+
918
+            $stmt->closeCursor();
919
+
920
+            foreach ($shareMap as $share) {
921
+                $result[] = $share;
922
+            }
923
+        }
924
+
925
+        return $result;
926
+    }
927
+
928
+    /**
929
+     * A user is deleted from the system
930
+     * So clean up the relevant shares.
931
+     *
932
+     * @param string $uid
933
+     * @param int $shareType
934
+     */
935
+    public function userDeleted($uid, $shareType) {
936
+        $qb = $this->dbConn->getQueryBuilder();
937
+
938
+        $qb->delete('share');
939
+
940
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
941
+            /*
942 942
 			 * Delete all user shares that are owned by this user
943 943
 			 * or that are received by this user
944 944
 			 */
945 945
 
946
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
946
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)));
947 947
 
948
-			$qb->andWhere(
949
-				$qb->expr()->orX(
950
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
951
-					$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
952
-				)
953
-			);
954
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
955
-			/*
948
+            $qb->andWhere(
949
+                $qb->expr()->orX(
950
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
951
+                    $qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
952
+                )
953
+            );
954
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
955
+            /*
956 956
 			 * Delete all group shares that are owned by this user
957 957
 			 * Or special user group shares that are received by this user
958 958
 			 */
959
-			$qb->where(
960
-				$qb->expr()->andX(
961
-					$qb->expr()->orX(
962
-						$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
963
-						$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
964
-					),
965
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
966
-				)
967
-			);
968
-
969
-			$qb->orWhere(
970
-				$qb->expr()->andX(
971
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)),
972
-					$qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
973
-				)
974
-			);
975
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
976
-			/*
959
+            $qb->where(
960
+                $qb->expr()->andX(
961
+                    $qb->expr()->orX(
962
+                        $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
963
+                        $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))
964
+                    ),
965
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))
966
+                )
967
+            );
968
+
969
+            $qb->orWhere(
970
+                $qb->expr()->andX(
971
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)),
972
+                    $qb->expr()->eq('share_with', $qb->createNamedParameter($uid))
973
+                )
974
+            );
975
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
976
+            /*
977 977
 			 * Delete all link shares owned by this user.
978 978
 			 * And all link shares initiated by this user (until #22327 is in)
979 979
 			 */
980
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
981
-
982
-			$qb->andWhere(
983
-				$qb->expr()->orX(
984
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
985
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
986
-				)
987
-			);
988
-		}
989
-
990
-		$qb->execute();
991
-	}
992
-
993
-	/**
994
-	 * Delete all shares received by this group. As well as any custom group
995
-	 * shares for group members.
996
-	 *
997
-	 * @param string $gid
998
-	 */
999
-	public function groupDeleted($gid) {
1000
-		/*
980
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
981
+
982
+            $qb->andWhere(
983
+                $qb->expr()->orX(
984
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)),
985
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid))
986
+                )
987
+            );
988
+        }
989
+
990
+        $qb->execute();
991
+    }
992
+
993
+    /**
994
+     * Delete all shares received by this group. As well as any custom group
995
+     * shares for group members.
996
+     *
997
+     * @param string $gid
998
+     */
999
+    public function groupDeleted($gid) {
1000
+        /*
1001 1001
 		 * First delete all custom group shares for group members
1002 1002
 		 */
1003
-		$qb = $this->dbConn->getQueryBuilder();
1004
-		$qb->select('id')
1005
-			->from('share')
1006
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1007
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1008
-
1009
-		$cursor = $qb->execute();
1010
-		$ids = [];
1011
-		while($row = $cursor->fetch()) {
1012
-			$ids[] = (int)$row['id'];
1013
-		}
1014
-		$cursor->closeCursor();
1015
-
1016
-		if (!empty($ids)) {
1017
-			$chunks = array_chunk($ids, 100);
1018
-			foreach ($chunks as $chunk) {
1019
-				$qb->delete('share')
1020
-					->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1021
-					->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1022
-				$qb->execute();
1023
-			}
1024
-		}
1025
-
1026
-		/*
1003
+        $qb = $this->dbConn->getQueryBuilder();
1004
+        $qb->select('id')
1005
+            ->from('share')
1006
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1007
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1008
+
1009
+        $cursor = $qb->execute();
1010
+        $ids = [];
1011
+        while($row = $cursor->fetch()) {
1012
+            $ids[] = (int)$row['id'];
1013
+        }
1014
+        $cursor->closeCursor();
1015
+
1016
+        if (!empty($ids)) {
1017
+            $chunks = array_chunk($ids, 100);
1018
+            foreach ($chunks as $chunk) {
1019
+                $qb->delete('share')
1020
+                    ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1021
+                    ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1022
+                $qb->execute();
1023
+            }
1024
+        }
1025
+
1026
+        /*
1027 1027
 		 * Now delete all the group shares
1028 1028
 		 */
1029
-		$qb = $this->dbConn->getQueryBuilder();
1030
-		$qb->delete('share')
1031
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1032
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1033
-		$qb->execute();
1034
-	}
1035
-
1036
-	/**
1037
-	 * Delete custom group shares to this group for this user
1038
-	 *
1039
-	 * @param string $uid
1040
-	 * @param string $gid
1041
-	 */
1042
-	public function userDeletedFromGroup($uid, $gid) {
1043
-		/*
1029
+        $qb = $this->dbConn->getQueryBuilder();
1030
+        $qb->delete('share')
1031
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1032
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1033
+        $qb->execute();
1034
+    }
1035
+
1036
+    /**
1037
+     * Delete custom group shares to this group for this user
1038
+     *
1039
+     * @param string $uid
1040
+     * @param string $gid
1041
+     */
1042
+    public function userDeletedFromGroup($uid, $gid) {
1043
+        /*
1044 1044
 		 * Get all group shares
1045 1045
 		 */
1046
-		$qb = $this->dbConn->getQueryBuilder();
1047
-		$qb->select('id')
1048
-			->from('share')
1049
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1050
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1051
-
1052
-		$cursor = $qb->execute();
1053
-		$ids = [];
1054
-		while($row = $cursor->fetch()) {
1055
-			$ids[] = (int)$row['id'];
1056
-		}
1057
-		$cursor->closeCursor();
1058
-
1059
-		if (!empty($ids)) {
1060
-			$chunks = array_chunk($ids, 100);
1061
-			foreach ($chunks as $chunk) {
1062
-				/*
1046
+        $qb = $this->dbConn->getQueryBuilder();
1047
+        $qb->select('id')
1048
+            ->from('share')
1049
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
1050
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid)));
1051
+
1052
+        $cursor = $qb->execute();
1053
+        $ids = [];
1054
+        while($row = $cursor->fetch()) {
1055
+            $ids[] = (int)$row['id'];
1056
+        }
1057
+        $cursor->closeCursor();
1058
+
1059
+        if (!empty($ids)) {
1060
+            $chunks = array_chunk($ids, 100);
1061
+            foreach ($chunks as $chunk) {
1062
+                /*
1063 1063
 				 * Delete all special shares wit this users for the found group shares
1064 1064
 				 */
1065
-				$qb->delete('share')
1066
-					->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1067
-					->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
1068
-					->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1069
-				$qb->execute();
1070
-			}
1071
-		}
1072
-	}
1073
-
1074
-	/**
1075
-	 * @inheritdoc
1076
-	 */
1077
-	public function getAccessList($nodes, $currentAccess) {
1078
-		$ids = [];
1079
-		foreach ($nodes as $node) {
1080
-			$ids[] = $node->getId();
1081
-		}
1082
-
1083
-		$qb = $this->dbConn->getQueryBuilder();
1084
-
1085
-		$or = $qb->expr()->orX(
1086
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
1087
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1088
-			$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
1089
-		);
1090
-
1091
-		if ($currentAccess) {
1092
-			$or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
1093
-		}
1094
-
1095
-		$qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
1096
-			->from('share')
1097
-			->where(
1098
-				$or
1099
-			)
1100
-			->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1101
-			->andWhere($qb->expr()->orX(
1102
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1103
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1104
-			));
1105
-		$cursor = $qb->execute();
1106
-
1107
-		$users = [];
1108
-		$link = false;
1109
-		while($row = $cursor->fetch()) {
1110
-			$type = (int)$row['share_type'];
1111
-			if ($type === \OCP\Share::SHARE_TYPE_USER) {
1112
-				$uid = $row['share_with'];
1113
-				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1114
-				$users[$uid][$row['id']] = $row;
1115
-			} else if ($type === \OCP\Share::SHARE_TYPE_GROUP) {
1116
-				$gid = $row['share_with'];
1117
-				$group = $this->groupManager->get($gid);
1118
-
1119
-				if ($gid === null) {
1120
-					continue;
1121
-				}
1122
-
1123
-				$userList = $group->getUsers();
1124
-				foreach ($userList as $user) {
1125
-					$uid = $user->getUID();
1126
-					$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1127
-					$users[$uid][$row['id']] = $row;
1128
-				}
1129
-			} else if ($type === \OCP\Share::SHARE_TYPE_LINK) {
1130
-				$link = true;
1131
-			} else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) {
1132
-				$uid = $row['share_with'];
1133
-				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1134
-				$users[$uid][$row['id']] = $row;
1135
-			}
1136
-		}
1137
-		$cursor->closeCursor();
1138
-
1139
-		if ($currentAccess === true) {
1140
-			$users = array_map([$this, 'filterSharesOfUser'], $users);
1141
-			$users = array_filter($users);
1142
-		} else {
1143
-			$users = array_keys($users);
1144
-		}
1145
-
1146
-		return ['users' => $users, 'public' => $link];
1147
-	}
1148
-
1149
-	/**
1150
-	 * For each user the path with the fewest slashes is returned
1151
-	 * @param array $shares
1152
-	 * @return array
1153
-	 */
1154
-	protected function filterSharesOfUser(array $shares) {
1155
-		// Group shares when the user has a share exception
1156
-		foreach ($shares as $id => $share) {
1157
-			$type = (int) $share['share_type'];
1158
-			$permissions = (int) $share['permissions'];
1159
-
1160
-			if ($type === self::SHARE_TYPE_USERGROUP) {
1161
-				unset($shares[$share['parent']]);
1162
-
1163
-				if ($permissions === 0) {
1164
-					unset($shares[$id]);
1165
-				}
1166
-			}
1167
-		}
1168
-
1169
-		$best = [];
1170
-		$bestDepth = 0;
1171
-		foreach ($shares as $id => $share) {
1172
-			$depth = substr_count($share['file_target'], '/');
1173
-			if (empty($best) || $depth < $bestDepth) {
1174
-				$bestDepth = $depth;
1175
-				$best = [
1176
-					'node_id' => $share['file_source'],
1177
-					'node_path' => $share['file_target'],
1178
-				];
1179
-			}
1180
-		}
1181
-
1182
-		return $best;
1183
-	}
1065
+                $qb->delete('share')
1066
+                    ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
1067
+                    ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid)))
1068
+                    ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)));
1069
+                $qb->execute();
1070
+            }
1071
+        }
1072
+    }
1073
+
1074
+    /**
1075
+     * @inheritdoc
1076
+     */
1077
+    public function getAccessList($nodes, $currentAccess) {
1078
+        $ids = [];
1079
+        foreach ($nodes as $node) {
1080
+            $ids[] = $node->getId();
1081
+        }
1082
+
1083
+        $qb = $this->dbConn->getQueryBuilder();
1084
+
1085
+        $or = $qb->expr()->orX(
1086
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
1087
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)),
1088
+            $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))
1089
+        );
1090
+
1091
+        if ($currentAccess) {
1092
+            $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)));
1093
+        }
1094
+
1095
+        $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions')
1096
+            ->from('share')
1097
+            ->where(
1098
+                $or
1099
+            )
1100
+            ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
1101
+            ->andWhere($qb->expr()->orX(
1102
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
1103
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
1104
+            ));
1105
+        $cursor = $qb->execute();
1106
+
1107
+        $users = [];
1108
+        $link = false;
1109
+        while($row = $cursor->fetch()) {
1110
+            $type = (int)$row['share_type'];
1111
+            if ($type === \OCP\Share::SHARE_TYPE_USER) {
1112
+                $uid = $row['share_with'];
1113
+                $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1114
+                $users[$uid][$row['id']] = $row;
1115
+            } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) {
1116
+                $gid = $row['share_with'];
1117
+                $group = $this->groupManager->get($gid);
1118
+
1119
+                if ($gid === null) {
1120
+                    continue;
1121
+                }
1122
+
1123
+                $userList = $group->getUsers();
1124
+                foreach ($userList as $user) {
1125
+                    $uid = $user->getUID();
1126
+                    $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1127
+                    $users[$uid][$row['id']] = $row;
1128
+                }
1129
+            } else if ($type === \OCP\Share::SHARE_TYPE_LINK) {
1130
+                $link = true;
1131
+            } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) {
1132
+                $uid = $row['share_with'];
1133
+                $users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
1134
+                $users[$uid][$row['id']] = $row;
1135
+            }
1136
+        }
1137
+        $cursor->closeCursor();
1138
+
1139
+        if ($currentAccess === true) {
1140
+            $users = array_map([$this, 'filterSharesOfUser'], $users);
1141
+            $users = array_filter($users);
1142
+        } else {
1143
+            $users = array_keys($users);
1144
+        }
1145
+
1146
+        return ['users' => $users, 'public' => $link];
1147
+    }
1148
+
1149
+    /**
1150
+     * For each user the path with the fewest slashes is returned
1151
+     * @param array $shares
1152
+     * @return array
1153
+     */
1154
+    protected function filterSharesOfUser(array $shares) {
1155
+        // Group shares when the user has a share exception
1156
+        foreach ($shares as $id => $share) {
1157
+            $type = (int) $share['share_type'];
1158
+            $permissions = (int) $share['permissions'];
1159
+
1160
+            if ($type === self::SHARE_TYPE_USERGROUP) {
1161
+                unset($shares[$share['parent']]);
1162
+
1163
+                if ($permissions === 0) {
1164
+                    unset($shares[$id]);
1165
+                }
1166
+            }
1167
+        }
1168
+
1169
+        $best = [];
1170
+        $bestDepth = 0;
1171
+        foreach ($shares as $id => $share) {
1172
+            $depth = substr_count($share['file_target'], '/');
1173
+            if (empty($best) || $depth < $bestDepth) {
1174
+                $bestDepth = $depth;
1175
+                $best = [
1176
+                    'node_id' => $share['file_source'],
1177
+                    'node_path' => $share['file_target'],
1178
+                ];
1179
+            }
1180
+        }
1181
+
1182
+        return $best;
1183
+    }
1184 1184
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 			->orderBy('id');
289 289
 
290 290
 		$cursor = $qb->execute();
291
-		while($data = $cursor->fetch()) {
291
+		while ($data = $cursor->fetch()) {
292 292
 			$children[] = $this->createShare($data);
293 293
 		}
294 294
 		$cursor->closeCursor();
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 			$user = $this->userManager->get($recipient);
334 334
 
335 335
 			if (is_null($group)) {
336
-				throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist');
336
+				throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist');
337 337
 			}
338 338
 
339 339
 			if (!$group->inGroup($user)) {
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 			);
494 494
 		}
495 495
 
496
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
496
+		$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
497 497
 		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
498 498
 
499 499
 		$qb->orderBy('id');
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 
550 550
 		$cursor = $qb->execute();
551 551
 		$shares = [];
552
-		while($data = $cursor->fetch()) {
552
+		while ($data = $cursor->fetch()) {
553 553
 			$shares[] = $this->createShare($data);
554 554
 		}
555 555
 		$cursor->closeCursor();
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 			->execute();
629 629
 
630 630
 		$shares = [];
631
-		while($data = $cursor->fetch()) {
631
+		while ($data = $cursor->fetch()) {
632 632
 			$shares[] = $this->createShare($data);
633 633
 		}
634 634
 		$cursor->closeCursor();
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 
700 700
 			$cursor = $qb->execute();
701 701
 
702
-			while($data = $cursor->fetch()) {
702
+			while ($data = $cursor->fetch()) {
703 703
 				if ($this->isAccessibleResult($data)) {
704 704
 					$shares[] = $this->createShare($data);
705 705
 				}
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 			$shares2 = [];
715 715
 
716 716
 			$start = 0;
717
-			while(true) {
717
+			while (true) {
718 718
 				$groups = array_slice($allGroups, $start, 100);
719 719
 				$start += 100;
720 720
 
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 					));
758 758
 
759 759
 				$cursor = $qb->execute();
760
-				while($data = $cursor->fetch()) {
760
+				while ($data = $cursor->fetch()) {
761 761
 					if ($offset > 0) {
762 762
 						$offset--;
763 763
 						continue;
@@ -826,14 +826,14 @@  discard block
 block discarded – undo
826 826
 	 */
827 827
 	private function createShare($data) {
828 828
 		$share = new Share($this->rootFolder, $this->userManager);
829
-		$share->setId((int)$data['id'])
830
-			->setShareType((int)$data['share_type'])
831
-			->setPermissions((int)$data['permissions'])
829
+		$share->setId((int) $data['id'])
830
+			->setShareType((int) $data['share_type'])
831
+			->setPermissions((int) $data['permissions'])
832 832
 			->setTarget($data['file_target'])
833
-			->setMailSend((bool)$data['mail_send']);
833
+			->setMailSend((bool) $data['mail_send']);
834 834
 
835 835
 		$shareTime = new \DateTime();
836
-		$shareTime->setTimestamp((int)$data['stime']);
836
+		$shareTime->setTimestamp((int) $data['stime']);
837 837
 		$share->setShareTime($shareTime);
838 838
 
839 839
 		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 		$share->setSharedBy($data['uid_initiator']);
849 849
 		$share->setShareOwner($data['uid_owner']);
850 850
 
851
-		$share->setNodeId((int)$data['file_source']);
851
+		$share->setNodeId((int) $data['file_source']);
852 852
 		$share->setNodeType($data['item_type']);
853 853
 
854 854
 		if ($data['expiration'] !== null) {
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
 		if (isset($data['f_permissions'])) {
860 860
 			$entryData = $data;
861 861
 			$entryData['permissions'] = $entryData['f_permissions'];
862
-			$entryData['parent'] = $entryData['f_parent'];;
862
+			$entryData['parent'] = $entryData['f_parent']; ;
863 863
 			$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData,
864 864
 				\OC::$server->getMimeTypeLoader()));
865 865
 		}
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 		$result = [];
879 879
 
880 880
 		$start = 0;
881
-		while(true) {
881
+		while (true) {
882 882
 			/** @var Share[] $shareSlice */
883 883
 			$shareSlice = array_slice($shares, $start, 100);
884 884
 			$start += 100;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 			$shareMap = [];
894 894
 
895 895
 			foreach ($shareSlice as $share) {
896
-				$ids[] = (int)$share->getId();
896
+				$ids[] = (int) $share->getId();
897 897
 				$shareMap[$share->getId()] = $share;
898 898
 			}
899 899
 
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
 
911 911
 			$stmt = $query->execute();
912 912
 
913
-			while($data = $stmt->fetch()) {
914
-				$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
913
+			while ($data = $stmt->fetch()) {
914
+				$shareMap[$data['parent']]->setPermissions((int) $data['permissions']);
915 915
 				$shareMap[$data['parent']]->setTarget($data['file_target']);
916 916
 			}
917 917
 
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 
1009 1009
 		$cursor = $qb->execute();
1010 1010
 		$ids = [];
1011
-		while($row = $cursor->fetch()) {
1012
-			$ids[] = (int)$row['id'];
1011
+		while ($row = $cursor->fetch()) {
1012
+			$ids[] = (int) $row['id'];
1013 1013
 		}
1014 1014
 		$cursor->closeCursor();
1015 1015
 
@@ -1051,8 +1051,8 @@  discard block
 block discarded – undo
1051 1051
 
1052 1052
 		$cursor = $qb->execute();
1053 1053
 		$ids = [];
1054
-		while($row = $cursor->fetch()) {
1055
-			$ids[] = (int)$row['id'];
1054
+		while ($row = $cursor->fetch()) {
1055
+			$ids[] = (int) $row['id'];
1056 1056
 		}
1057 1057
 		$cursor->closeCursor();
1058 1058
 
@@ -1106,8 +1106,8 @@  discard block
 block discarded – undo
1106 1106
 
1107 1107
 		$users = [];
1108 1108
 		$link = false;
1109
-		while($row = $cursor->fetch()) {
1110
-			$type = (int)$row['share_type'];
1109
+		while ($row = $cursor->fetch()) {
1110
+			$type = (int) $row['share_type'];
1111 1111
 			if ($type === \OCP\Share::SHARE_TYPE_USER) {
1112 1112
 				$uid = $row['share_with'];
1113 1113
 				$users[$uid] = isset($users[$uid]) ? $users[$uid] : [];
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ShareTypeList.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 	 * The deserialize method is called during xml parsing.
62 62
 	 *
63 63
 	 * @param Reader $reader
64
-	 * @return mixed
64
+	 * @return null|ShareTypeList
65 65
 	 */
66 66
 	static function xmlDeserialize(Reader $reader) {
67 67
 		$shareTypes = [];
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -32,61 +32,61 @@
 block discarded – undo
32 32
  * This property contains multiple "share-type" elements, each containing a share type.
33 33
  */
34 34
 class ShareTypeList implements Element {
35
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
35
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
36 36
 
37
-	/**
38
-	 * Share types
39
-	 *
40
-	 * @var int[]
41
-	 */
42
-	private $shareTypes;
37
+    /**
38
+     * Share types
39
+     *
40
+     * @var int[]
41
+     */
42
+    private $shareTypes;
43 43
 
44
-	/**
45
-	 * @param int[] $shareTypes
46
-	 */
47
-	public function __construct($shareTypes) {
48
-		$this->shareTypes = $shareTypes;
49
-	}
44
+    /**
45
+     * @param int[] $shareTypes
46
+     */
47
+    public function __construct($shareTypes) {
48
+        $this->shareTypes = $shareTypes;
49
+    }
50 50
 
51
-	/**
52
-	 * Returns the share types
53
-	 *
54
-	 * @return int[]
55
-	 */
56
-	public function getShareTypes() {
57
-		return $this->shareTypes;
58
-	}
51
+    /**
52
+     * Returns the share types
53
+     *
54
+     * @return int[]
55
+     */
56
+    public function getShareTypes() {
57
+        return $this->shareTypes;
58
+    }
59 59
 
60
-	/**
61
-	 * The deserialize method is called during xml parsing.
62
-	 *
63
-	 * @param Reader $reader
64
-	 * @return mixed
65
-	 */
66
-	static function xmlDeserialize(Reader $reader) {
67
-		$shareTypes = [];
60
+    /**
61
+     * The deserialize method is called during xml parsing.
62
+     *
63
+     * @param Reader $reader
64
+     * @return mixed
65
+     */
66
+    static function xmlDeserialize(Reader $reader) {
67
+        $shareTypes = [];
68 68
 
69
-		$tree = $reader->parseInnerTree();
70
-		if ($tree === null) {
71
-			return null;
72
-		}
73
-		foreach ($tree as $elem) {
74
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
75
-				$shareTypes[] = (int)$elem['value'];
76
-			}
77
-		}
78
-		return new self($shareTypes);
79
-	}
69
+        $tree = $reader->parseInnerTree();
70
+        if ($tree === null) {
71
+            return null;
72
+        }
73
+        foreach ($tree as $elem) {
74
+            if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
75
+                $shareTypes[] = (int)$elem['value'];
76
+            }
77
+        }
78
+        return new self($shareTypes);
79
+    }
80 80
 
81
-	/**
82
-	 * The xmlSerialize metod is called during xml writing.
83
-	 *
84
-	 * @param Writer $writer
85
-	 * @return void
86
-	 */
87
-	function xmlSerialize(Writer $writer) {
88
-		foreach ($this->shareTypes as $shareType) {
89
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType);
90
-		}
91
-	}
81
+    /**
82
+     * The xmlSerialize metod is called during xml writing.
83
+     *
84
+     * @param Writer $writer
85
+     * @return void
86
+     */
87
+    function xmlSerialize(Writer $writer) {
88
+        foreach ($this->shareTypes as $shareType) {
89
+            $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType);
90
+        }
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 			return null;
72 72
 		}
73 73
 		foreach ($tree as $elem) {
74
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
75
-				$shareTypes[] = (int)$elem['value'];
74
+			if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') {
75
+				$shareTypes[] = (int) $elem['value'];
76 76
 			}
77 77
 		}
78 78
 		return new self($shareTypes);
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	function xmlSerialize(Writer $writer) {
88 88
 		foreach ($this->shareTypes as $shareType) {
89
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType);
89
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType);
90 90
 		}
91 91
 	}
92 92
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/TagList.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
 	 * the next element.
81 81
 	 *
82 82
 	 * @param Reader $reader
83
-	 * @return mixed
83
+	 * @return null|TagList
84 84
 	 */
85 85
 	static function xmlDeserialize(Reader $reader) {
86 86
 		$tags = [];
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -34,92 +34,92 @@
 block discarded – undo
34 34
  * This property contains multiple "tag" elements, each containing a tag name.
35 35
  */
36 36
 class TagList implements Element {
37
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
37
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
38 38
 
39
-	/**
40
-	 * tags
41
-	 *
42
-	 * @var array
43
-	 */
44
-	private $tags;
39
+    /**
40
+     * tags
41
+     *
42
+     * @var array
43
+     */
44
+    private $tags;
45 45
 
46
-	/**
47
-	 * @param array $tags
48
-	 */
49
-	public function __construct(array $tags) {
50
-		$this->tags = $tags;
51
-	}
46
+    /**
47
+     * @param array $tags
48
+     */
49
+    public function __construct(array $tags) {
50
+        $this->tags = $tags;
51
+    }
52 52
 
53
-	/**
54
-	 * Returns the tags
55
-	 *
56
-	 * @return array
57
-	 */
58
-	public function getTags() {
53
+    /**
54
+     * Returns the tags
55
+     *
56
+     * @return array
57
+     */
58
+    public function getTags() {
59 59
 
60
-		return $this->tags;
60
+        return $this->tags;
61 61
 
62
-	}
62
+    }
63 63
 
64
-	/**
65
-	 * The deserialize method is called during xml parsing.
66
-	 *
67
-	 * This method is called statictly, this is because in theory this method
68
-	 * may be used as a type of constructor, or factory method.
69
-	 *
70
-	 * Often you want to return an instance of the current class, but you are
71
-	 * free to return other data as well.
72
-	 *
73
-	 * You are responsible for advancing the reader to the next element. Not
74
-	 * doing anything will result in a never-ending loop.
75
-	 *
76
-	 * If you just want to skip parsing for this element altogether, you can
77
-	 * just call $reader->next();
78
-	 *
79
-	 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
80
-	 * the next element.
81
-	 *
82
-	 * @param Reader $reader
83
-	 * @return mixed
84
-	 */
85
-	static function xmlDeserialize(Reader $reader) {
86
-		$tags = [];
64
+    /**
65
+     * The deserialize method is called during xml parsing.
66
+     *
67
+     * This method is called statictly, this is because in theory this method
68
+     * may be used as a type of constructor, or factory method.
69
+     *
70
+     * Often you want to return an instance of the current class, but you are
71
+     * free to return other data as well.
72
+     *
73
+     * You are responsible for advancing the reader to the next element. Not
74
+     * doing anything will result in a never-ending loop.
75
+     *
76
+     * If you just want to skip parsing for this element altogether, you can
77
+     * just call $reader->next();
78
+     *
79
+     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
80
+     * the next element.
81
+     *
82
+     * @param Reader $reader
83
+     * @return mixed
84
+     */
85
+    static function xmlDeserialize(Reader $reader) {
86
+        $tags = [];
87 87
 
88
-		$tree = $reader->parseInnerTree();
89
-		if ($tree === null) {
90
-			return null;
91
-		}
92
-		foreach ($tree as $elem) {
93
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
94
-				$tags[] = $elem['value'];
95
-			}
96
-		}
97
-		return new self($tags);
98
-	}
88
+        $tree = $reader->parseInnerTree();
89
+        if ($tree === null) {
90
+            return null;
91
+        }
92
+        foreach ($tree as $elem) {
93
+            if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
94
+                $tags[] = $elem['value'];
95
+            }
96
+        }
97
+        return new self($tags);
98
+    }
99 99
 
100
-	/**
101
-	 * The xmlSerialize metod is called during xml writing.
102
-	 *
103
-	 * Use the $writer argument to write its own xml serialization.
104
-	 *
105
-	 * An important note: do _not_ create a parent element. Any element
106
-	 * implementing XmlSerializble should only ever write what's considered
107
-	 * its 'inner xml'.
108
-	 *
109
-	 * The parent of the current element is responsible for writing a
110
-	 * containing element.
111
-	 *
112
-	 * This allows serializers to be re-used for different element names.
113
-	 *
114
-	 * If you are opening new elements, you must also close them again.
115
-	 *
116
-	 * @param Writer $writer
117
-	 * @return void
118
-	 */
119
-	function xmlSerialize(Writer $writer) {
100
+    /**
101
+     * The xmlSerialize metod is called during xml writing.
102
+     *
103
+     * Use the $writer argument to write its own xml serialization.
104
+     *
105
+     * An important note: do _not_ create a parent element. Any element
106
+     * implementing XmlSerializble should only ever write what's considered
107
+     * its 'inner xml'.
108
+     *
109
+     * The parent of the current element is responsible for writing a
110
+     * containing element.
111
+     *
112
+     * This allows serializers to be re-used for different element names.
113
+     *
114
+     * If you are opening new elements, you must also close them again.
115
+     *
116
+     * @param Writer $writer
117
+     * @return void
118
+     */
119
+    function xmlSerialize(Writer $writer) {
120 120
 
121
-		foreach ($this->tags as $tag) {
122
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
123
-		}
124
-	}
121
+        foreach ($this->tags as $tag) {
122
+            $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
123
+        }
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			return null;
91 91
 		}
92 92
 		foreach ($tree as $elem) {
93
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
93
+			if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') {
94 94
 				$tags[] = $elem['value'];
95 95
 			}
96 96
 		}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	function xmlSerialize(Writer $writer) {
120 120
 
121 121
 		foreach ($this->tags as $tag) {
122
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
122
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag);
123 123
 		}
124 124
 	}
125 125
 }
Please login to merge, or discard this patch.
lib/private/L10N/Factory.php 3 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -318,6 +318,11 @@
 block discarded – undo
318 318
 	 */
319 319
 	// FIXME This method is only public, until OC_L10N does not need it anymore,
320 320
 	// FIXME This is also the reason, why it is not in the public interface
321
+
322
+	/**
323
+	 * @param string $app
324
+	 * @param string $lang
325
+	 */
321 326
 	public function getL10nFilesForApp($app, $lang) {
322 327
 		$languageFiles = [];
323 328
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 		 *
132 132
 		 * @link https://github.com/owncloud/core/issues/21955
133 133
 		 */
134
-		if($this->config->getSystemValue('installed', false)) {
135
-			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
136
-			if(!is_null($userId)) {
134
+		if ($this->config->getSystemValue('installed', false)) {
135
+			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null;
136
+			if (!is_null($userId)) {
137 137
 				$userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
138 138
 			} else {
139 139
 				$userLang = null;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		// merge with translations from theme
203 203
 		$theme = $this->config->getSystemValue('theme');
204 204
 		if (!empty($theme)) {
205
-			$themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
205
+			$themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot));
206 206
 
207 207
 			if (is_dir($themeDir)) {
208 208
 				$files = scandir($themeDir);
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 */
298 298
 	private function isSubDirectory($sub, $parent) {
299 299
 		// Check whether $sub contains no ".."
300
-		if(strpos($sub, '..') !== false) {
300
+		if (strpos($sub, '..') !== false) {
301 301
 			return false;
302 302
 		}
303 303
 
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
 		$languageFiles = [];
323 323
 
324 324
 		$i18nDir = $this->findL10nDir($app);
325
-		$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
325
+		$transFile = strip_tags($i18nDir).strip_tags($lang).'.json';
326 326
 
327
-		if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
328
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
329
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
330
-				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
327
+		if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/')
328
+				|| $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/')
329
+				|| $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/')
330
+				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/')
331 331
 			)
332 332
 			&& file_exists($transFile)) {
333 333
 			// load the translations file
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 		// merge with translations from theme
338 338
 		$theme = $this->config->getSystemValue('theme');
339 339
 		if (!empty($theme)) {
340
-			$transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
340
+			$transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot));
341 341
 			if (file_exists($transFile)) {
342 342
 				$languageFiles[] = $transFile;
343 343
 			}
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
 	 */
355 355
 	protected function findL10nDir($app = null) {
356 356
 		if (in_array($app, ['core', 'lib', 'settings'])) {
357
-			if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
358
-				return $this->serverRoot . '/' . $app . '/l10n/';
357
+			if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) {
358
+				return $this->serverRoot.'/'.$app.'/l10n/';
359 359
 			}
360 360
 		} else if ($app && \OC_App::getAppPath($app) !== false) {
361 361
 			// Check if the app is in the app folder
362
-			return \OC_App::getAppPath($app) . '/l10n/';
362
+			return \OC_App::getAppPath($app).'/l10n/';
363 363
 		}
364
-		return $this->serverRoot . '/core/l10n/';
364
+		return $this->serverRoot.'/core/l10n/';
365 365
 	}
366 366
 
367 367
 
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
 			return $this->pluralFunctions[$string];
379 379
 		}
380 380
 
381
-		if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
381
+		if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
382 382
 			// sanitize
383
-			$nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
384
-			$plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
383
+			$nplurals = preg_replace('/[^0-9]/', '', $matches[1]);
384
+			$plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]);
385 385
 
386 386
 			$body = str_replace(
387
-				array( 'plural', 'n', '$n$plurals', ),
388
-				array( '$plural', '$n', '$nplurals', ),
389
-				'nplurals='. $nplurals . '; plural=' . $plural
387
+				array('plural', 'n', '$n$plurals',),
388
+				array('$plural', '$n', '$nplurals',),
389
+				'nplurals='.$nplurals.'; plural='.$plural
390 390
 			);
391 391
 
392 392
 			// add parents
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
 			$body .= ';';
395 395
 			$res = '';
396 396
 			$p = 0;
397
-			for($i = 0; $i < strlen($body); $i++) {
397
+			for ($i = 0; $i < strlen($body); $i++) {
398 398
 				$ch = $body[$i];
399
-				switch ( $ch ) {
399
+				switch ($ch) {
400 400
 					case '?':
401 401
 						$res .= ' ? (';
402 402
 						$p++;
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 						$res .= ') : (';
406 406
 						break;
407 407
 					case ';':
408
-						$res .= str_repeat( ')', $p ) . ';';
408
+						$res .= str_repeat(')', $p).';';
409 409
 						$p = 0;
410 410
 						break;
411 411
 					default:
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 				}
414 414
 			}
415 415
 
416
-			$body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
416
+			$body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);';
417 417
 			$function = create_function('$n', $body);
418 418
 			$this->pluralFunctions[$string] = $function;
419 419
 			return $function;
Please login to merge, or discard this patch.
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -40,373 +40,373 @@
 block discarded – undo
40 40
  */
41 41
 class Factory implements IFactory {
42 42
 
43
-	/** @var string */
44
-	protected $requestLanguage = '';
45
-
46
-	/**
47
-	 * cached instances
48
-	 * @var array Structure: Lang => App => \OCP\IL10N
49
-	 */
50
-	protected $instances = [];
51
-
52
-	/**
53
-	 * @var array Structure: App => string[]
54
-	 */
55
-	protected $availableLanguages = [];
56
-
57
-	/**
58
-	 * @var array Structure: string => callable
59
-	 */
60
-	protected $pluralFunctions = [];
61
-
62
-	/** @var IConfig */
63
-	protected $config;
64
-
65
-	/** @var IRequest */
66
-	protected $request;
67
-
68
-	/** @var IUserSession */
69
-	protected $userSession;
70
-
71
-	/** @var string */
72
-	protected $serverRoot;
73
-
74
-	/**
75
-	 * @param IConfig $config
76
-	 * @param IRequest $request
77
-	 * @param IUserSession $userSession
78
-	 * @param string $serverRoot
79
-	 */
80
-	public function __construct(IConfig $config,
81
-								IRequest $request,
82
-								IUserSession $userSession,
83
-								$serverRoot) {
84
-		$this->config = $config;
85
-		$this->request = $request;
86
-		$this->userSession = $userSession;
87
-		$this->serverRoot = $serverRoot;
88
-	}
89
-
90
-	/**
91
-	 * Get a language instance
92
-	 *
93
-	 * @param string $app
94
-	 * @param string|null $lang
95
-	 * @return \OCP\IL10N
96
-	 */
97
-	public function get($app, $lang = null) {
98
-		$app = \OC_App::cleanAppId($app);
99
-		if ($lang !== null) {
100
-			$lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
101
-		}
102
-		if ($lang === null || !$this->languageExists($app, $lang)) {
103
-			$lang = $this->findLanguage($app);
104
-		}
105
-
106
-		if (!isset($this->instances[$lang][$app])) {
107
-			$this->instances[$lang][$app] = new L10N(
108
-				$this, $app, $lang,
109
-				$this->getL10nFilesForApp($app, $lang)
110
-			);
111
-		}
112
-
113
-		return $this->instances[$lang][$app];
114
-	}
115
-
116
-	/**
117
-	 * Find the best language
118
-	 *
119
-	 * @param string|null $app App id or null for core
120
-	 * @return string language If nothing works it returns 'en'
121
-	 */
122
-	public function findLanguage($app = null) {
123
-		if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) {
124
-			return $this->requestLanguage;
125
-		}
126
-
127
-		/**
128
-		 * At this point ownCloud might not yet be installed and thus the lookup
129
-		 * in the preferences table might fail. For this reason we need to check
130
-		 * whether the instance has already been installed
131
-		 *
132
-		 * @link https://github.com/owncloud/core/issues/21955
133
-		 */
134
-		if($this->config->getSystemValue('installed', false)) {
135
-			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
136
-			if(!is_null($userId)) {
137
-				$userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
138
-			} else {
139
-				$userLang = null;
140
-			}
141
-		} else {
142
-			$userId = null;
143
-			$userLang = null;
144
-		}
145
-
146
-		if ($userLang) {
147
-			$this->requestLanguage = $userLang;
148
-			if ($this->languageExists($app, $userLang)) {
149
-				return $userLang;
150
-			}
151
-		}
152
-
153
-		try {
154
-			// Try to get the language from the Request
155
-			$lang = $this->getLanguageFromRequest($app);
156
-			if ($userId !== null && $app === null && !$userLang) {
157
-				$this->config->setUserValue($userId, 'core', 'lang', $lang);
158
-			}
159
-			return $lang;
160
-		} catch (LanguageNotFoundException $e) {
161
-			// Finding language from request failed fall back to default language
162
-			$defaultLanguage = $this->config->getSystemValue('default_language', false);
163
-			if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) {
164
-				return $defaultLanguage;
165
-			}
166
-		}
167
-
168
-		// We could not find any language so fall back to english
169
-		return 'en';
170
-	}
171
-
172
-	/**
173
-	 * Find all available languages for an app
174
-	 *
175
-	 * @param string|null $app App id or null for core
176
-	 * @return array an array of available languages
177
-	 */
178
-	public function findAvailableLanguages($app = null) {
179
-		$key = $app;
180
-		if ($key === null) {
181
-			$key = 'null';
182
-		}
183
-
184
-		// also works with null as key
185
-		if (!empty($this->availableLanguages[$key])) {
186
-			return $this->availableLanguages[$key];
187
-		}
188
-
189
-		$available = ['en']; //english is always available
190
-		$dir = $this->findL10nDir($app);
191
-		if (is_dir($dir)) {
192
-			$files = scandir($dir);
193
-			if ($files !== false) {
194
-				foreach ($files as $file) {
195
-					if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
196
-						$available[] = substr($file, 0, -5);
197
-					}
198
-				}
199
-			}
200
-		}
201
-
202
-		// merge with translations from theme
203
-		$theme = $this->config->getSystemValue('theme');
204
-		if (!empty($theme)) {
205
-			$themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
206
-
207
-			if (is_dir($themeDir)) {
208
-				$files = scandir($themeDir);
209
-				if ($files !== false) {
210
-					foreach ($files as $file) {
211
-						if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
212
-							$available[] = substr($file, 0, -5);
213
-						}
214
-					}
215
-				}
216
-			}
217
-		}
218
-
219
-		$this->availableLanguages[$key] = $available;
220
-		return $available;
221
-	}
222
-
223
-	/**
224
-	 * @param string|null $app App id or null for core
225
-	 * @param string $lang
226
-	 * @return bool
227
-	 */
228
-	public function languageExists($app, $lang) {
229
-		if ($lang === 'en') {//english is always available
230
-			return true;
231
-		}
232
-
233
-		$languages = $this->findAvailableLanguages($app);
234
-		return array_search($lang, $languages) !== false;
235
-	}
236
-
237
-	/**
238
-	 * @param string|null $app
239
-	 * @return string
240
-	 * @throws LanguageNotFoundException
241
-	 */
242
-	private function getLanguageFromRequest($app) {
243
-		$header = $this->request->getHeader('ACCEPT_LANGUAGE');
244
-		if ($header) {
245
-			$available = $this->findAvailableLanguages($app);
246
-
247
-			// E.g. make sure that 'de' is before 'de_DE'.
248
-			sort($available);
249
-
250
-			$preferences = preg_split('/,\s*/', strtolower($header));
251
-			foreach ($preferences as $preference) {
252
-				list($preferred_language) = explode(';', $preference);
253
-				$preferred_language = str_replace('-', '_', $preferred_language);
254
-
255
-				foreach ($available as $available_language) {
256
-					if ($preferred_language === strtolower($available_language)) {
257
-						return $available_language;
258
-					}
259
-				}
260
-
261
-				// Fallback from de_De to de
262
-				foreach ($available as $available_language) {
263
-					if (substr($preferred_language, 0, 2) === $available_language) {
264
-						return $available_language;
265
-					}
266
-				}
267
-			}
268
-		}
269
-
270
-		throw new LanguageNotFoundException();
271
-	}
272
-
273
-	/**
274
-	 * Checks if $sub is a subdirectory of $parent
275
-	 *
276
-	 * @param string $sub
277
-	 * @param string $parent
278
-	 * @return bool
279
-	 */
280
-	private function isSubDirectory($sub, $parent) {
281
-		// Check whether $sub contains no ".."
282
-		if(strpos($sub, '..') !== false) {
283
-			return false;
284
-		}
285
-
286
-		// Check whether $sub is a subdirectory of $parent
287
-		if (strpos($sub, $parent) === 0) {
288
-			return true;
289
-		}
290
-
291
-		return false;
292
-	}
293
-
294
-	/**
295
-	 * Get a list of language files that should be loaded
296
-	 *
297
-	 * @param string $app
298
-	 * @param string $lang
299
-	 * @return string[]
300
-	 */
301
-	// FIXME This method is only public, until OC_L10N does not need it anymore,
302
-	// FIXME This is also the reason, why it is not in the public interface
303
-	public function getL10nFilesForApp($app, $lang) {
304
-		$languageFiles = [];
305
-
306
-		$i18nDir = $this->findL10nDir($app);
307
-		$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
308
-
309
-		if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
310
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
311
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
312
-				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
313
-			)
314
-			&& file_exists($transFile)) {
315
-			// load the translations file
316
-			$languageFiles[] = $transFile;
317
-		}
318
-
319
-		// merge with translations from theme
320
-		$theme = $this->config->getSystemValue('theme');
321
-		if (!empty($theme)) {
322
-			$transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
323
-			if (file_exists($transFile)) {
324
-				$languageFiles[] = $transFile;
325
-			}
326
-		}
327
-
328
-		return $languageFiles;
329
-	}
330
-
331
-	/**
332
-	 * find the l10n directory
333
-	 *
334
-	 * @param string $app App id or empty string for core
335
-	 * @return string directory
336
-	 */
337
-	protected function findL10nDir($app = null) {
338
-		if (in_array($app, ['core', 'lib', 'settings'])) {
339
-			if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
340
-				return $this->serverRoot . '/' . $app . '/l10n/';
341
-			}
342
-		} else if ($app && \OC_App::getAppPath($app) !== false) {
343
-			// Check if the app is in the app folder
344
-			return \OC_App::getAppPath($app) . '/l10n/';
345
-		}
346
-		return $this->serverRoot . '/core/l10n/';
347
-	}
348
-
349
-
350
-	/**
351
-	 * Creates a function from the plural string
352
-	 *
353
-	 * Parts of the code is copied from Habari:
354
-	 * https://github.com/habari/system/blob/master/classes/locale.php
355
-	 * @param string $string
356
-	 * @return string
357
-	 */
358
-	public function createPluralFunction($string) {
359
-		if (isset($this->pluralFunctions[$string])) {
360
-			return $this->pluralFunctions[$string];
361
-		}
362
-
363
-		if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
364
-			// sanitize
365
-			$nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
366
-			$plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
367
-
368
-			$body = str_replace(
369
-				array( 'plural', 'n', '$n$plurals', ),
370
-				array( '$plural', '$n', '$nplurals', ),
371
-				'nplurals='. $nplurals . '; plural=' . $plural
372
-			);
373
-
374
-			// add parents
375
-			// important since PHP's ternary evaluates from left to right
376
-			$body .= ';';
377
-			$res = '';
378
-			$p = 0;
379
-			for($i = 0; $i < strlen($body); $i++) {
380
-				$ch = $body[$i];
381
-				switch ( $ch ) {
382
-					case '?':
383
-						$res .= ' ? (';
384
-						$p++;
385
-						break;
386
-					case ':':
387
-						$res .= ') : (';
388
-						break;
389
-					case ';':
390
-						$res .= str_repeat( ')', $p ) . ';';
391
-						$p = 0;
392
-						break;
393
-					default:
394
-						$res .= $ch;
395
-				}
396
-			}
397
-
398
-			$body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
399
-			$function = create_function('$n', $body);
400
-			$this->pluralFunctions[$string] = $function;
401
-			return $function;
402
-		} else {
403
-			// default: one plural form for all cases but n==1 (english)
404
-			$function = create_function(
405
-				'$n',
406
-				'$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);'
407
-			);
408
-			$this->pluralFunctions[$string] = $function;
409
-			return $function;
410
-		}
411
-	}
43
+    /** @var string */
44
+    protected $requestLanguage = '';
45
+
46
+    /**
47
+     * cached instances
48
+     * @var array Structure: Lang => App => \OCP\IL10N
49
+     */
50
+    protected $instances = [];
51
+
52
+    /**
53
+     * @var array Structure: App => string[]
54
+     */
55
+    protected $availableLanguages = [];
56
+
57
+    /**
58
+     * @var array Structure: string => callable
59
+     */
60
+    protected $pluralFunctions = [];
61
+
62
+    /** @var IConfig */
63
+    protected $config;
64
+
65
+    /** @var IRequest */
66
+    protected $request;
67
+
68
+    /** @var IUserSession */
69
+    protected $userSession;
70
+
71
+    /** @var string */
72
+    protected $serverRoot;
73
+
74
+    /**
75
+     * @param IConfig $config
76
+     * @param IRequest $request
77
+     * @param IUserSession $userSession
78
+     * @param string $serverRoot
79
+     */
80
+    public function __construct(IConfig $config,
81
+                                IRequest $request,
82
+                                IUserSession $userSession,
83
+                                $serverRoot) {
84
+        $this->config = $config;
85
+        $this->request = $request;
86
+        $this->userSession = $userSession;
87
+        $this->serverRoot = $serverRoot;
88
+    }
89
+
90
+    /**
91
+     * Get a language instance
92
+     *
93
+     * @param string $app
94
+     * @param string|null $lang
95
+     * @return \OCP\IL10N
96
+     */
97
+    public function get($app, $lang = null) {
98
+        $app = \OC_App::cleanAppId($app);
99
+        if ($lang !== null) {
100
+            $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
101
+        }
102
+        if ($lang === null || !$this->languageExists($app, $lang)) {
103
+            $lang = $this->findLanguage($app);
104
+        }
105
+
106
+        if (!isset($this->instances[$lang][$app])) {
107
+            $this->instances[$lang][$app] = new L10N(
108
+                $this, $app, $lang,
109
+                $this->getL10nFilesForApp($app, $lang)
110
+            );
111
+        }
112
+
113
+        return $this->instances[$lang][$app];
114
+    }
115
+
116
+    /**
117
+     * Find the best language
118
+     *
119
+     * @param string|null $app App id or null for core
120
+     * @return string language If nothing works it returns 'en'
121
+     */
122
+    public function findLanguage($app = null) {
123
+        if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) {
124
+            return $this->requestLanguage;
125
+        }
126
+
127
+        /**
128
+         * At this point ownCloud might not yet be installed and thus the lookup
129
+         * in the preferences table might fail. For this reason we need to check
130
+         * whether the instance has already been installed
131
+         *
132
+         * @link https://github.com/owncloud/core/issues/21955
133
+         */
134
+        if($this->config->getSystemValue('installed', false)) {
135
+            $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
136
+            if(!is_null($userId)) {
137
+                $userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
138
+            } else {
139
+                $userLang = null;
140
+            }
141
+        } else {
142
+            $userId = null;
143
+            $userLang = null;
144
+        }
145
+
146
+        if ($userLang) {
147
+            $this->requestLanguage = $userLang;
148
+            if ($this->languageExists($app, $userLang)) {
149
+                return $userLang;
150
+            }
151
+        }
152
+
153
+        try {
154
+            // Try to get the language from the Request
155
+            $lang = $this->getLanguageFromRequest($app);
156
+            if ($userId !== null && $app === null && !$userLang) {
157
+                $this->config->setUserValue($userId, 'core', 'lang', $lang);
158
+            }
159
+            return $lang;
160
+        } catch (LanguageNotFoundException $e) {
161
+            // Finding language from request failed fall back to default language
162
+            $defaultLanguage = $this->config->getSystemValue('default_language', false);
163
+            if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) {
164
+                return $defaultLanguage;
165
+            }
166
+        }
167
+
168
+        // We could not find any language so fall back to english
169
+        return 'en';
170
+    }
171
+
172
+    /**
173
+     * Find all available languages for an app
174
+     *
175
+     * @param string|null $app App id or null for core
176
+     * @return array an array of available languages
177
+     */
178
+    public function findAvailableLanguages($app = null) {
179
+        $key = $app;
180
+        if ($key === null) {
181
+            $key = 'null';
182
+        }
183
+
184
+        // also works with null as key
185
+        if (!empty($this->availableLanguages[$key])) {
186
+            return $this->availableLanguages[$key];
187
+        }
188
+
189
+        $available = ['en']; //english is always available
190
+        $dir = $this->findL10nDir($app);
191
+        if (is_dir($dir)) {
192
+            $files = scandir($dir);
193
+            if ($files !== false) {
194
+                foreach ($files as $file) {
195
+                    if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
196
+                        $available[] = substr($file, 0, -5);
197
+                    }
198
+                }
199
+            }
200
+        }
201
+
202
+        // merge with translations from theme
203
+        $theme = $this->config->getSystemValue('theme');
204
+        if (!empty($theme)) {
205
+            $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
206
+
207
+            if (is_dir($themeDir)) {
208
+                $files = scandir($themeDir);
209
+                if ($files !== false) {
210
+                    foreach ($files as $file) {
211
+                        if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
212
+                            $available[] = substr($file, 0, -5);
213
+                        }
214
+                    }
215
+                }
216
+            }
217
+        }
218
+
219
+        $this->availableLanguages[$key] = $available;
220
+        return $available;
221
+    }
222
+
223
+    /**
224
+     * @param string|null $app App id or null for core
225
+     * @param string $lang
226
+     * @return bool
227
+     */
228
+    public function languageExists($app, $lang) {
229
+        if ($lang === 'en') {//english is always available
230
+            return true;
231
+        }
232
+
233
+        $languages = $this->findAvailableLanguages($app);
234
+        return array_search($lang, $languages) !== false;
235
+    }
236
+
237
+    /**
238
+     * @param string|null $app
239
+     * @return string
240
+     * @throws LanguageNotFoundException
241
+     */
242
+    private function getLanguageFromRequest($app) {
243
+        $header = $this->request->getHeader('ACCEPT_LANGUAGE');
244
+        if ($header) {
245
+            $available = $this->findAvailableLanguages($app);
246
+
247
+            // E.g. make sure that 'de' is before 'de_DE'.
248
+            sort($available);
249
+
250
+            $preferences = preg_split('/,\s*/', strtolower($header));
251
+            foreach ($preferences as $preference) {
252
+                list($preferred_language) = explode(';', $preference);
253
+                $preferred_language = str_replace('-', '_', $preferred_language);
254
+
255
+                foreach ($available as $available_language) {
256
+                    if ($preferred_language === strtolower($available_language)) {
257
+                        return $available_language;
258
+                    }
259
+                }
260
+
261
+                // Fallback from de_De to de
262
+                foreach ($available as $available_language) {
263
+                    if (substr($preferred_language, 0, 2) === $available_language) {
264
+                        return $available_language;
265
+                    }
266
+                }
267
+            }
268
+        }
269
+
270
+        throw new LanguageNotFoundException();
271
+    }
272
+
273
+    /**
274
+     * Checks if $sub is a subdirectory of $parent
275
+     *
276
+     * @param string $sub
277
+     * @param string $parent
278
+     * @return bool
279
+     */
280
+    private function isSubDirectory($sub, $parent) {
281
+        // Check whether $sub contains no ".."
282
+        if(strpos($sub, '..') !== false) {
283
+            return false;
284
+        }
285
+
286
+        // Check whether $sub is a subdirectory of $parent
287
+        if (strpos($sub, $parent) === 0) {
288
+            return true;
289
+        }
290
+
291
+        return false;
292
+    }
293
+
294
+    /**
295
+     * Get a list of language files that should be loaded
296
+     *
297
+     * @param string $app
298
+     * @param string $lang
299
+     * @return string[]
300
+     */
301
+    // FIXME This method is only public, until OC_L10N does not need it anymore,
302
+    // FIXME This is also the reason, why it is not in the public interface
303
+    public function getL10nFilesForApp($app, $lang) {
304
+        $languageFiles = [];
305
+
306
+        $i18nDir = $this->findL10nDir($app);
307
+        $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
308
+
309
+        if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
310
+                || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
311
+                || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
312
+                || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
313
+            )
314
+            && file_exists($transFile)) {
315
+            // load the translations file
316
+            $languageFiles[] = $transFile;
317
+        }
318
+
319
+        // merge with translations from theme
320
+        $theme = $this->config->getSystemValue('theme');
321
+        if (!empty($theme)) {
322
+            $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
323
+            if (file_exists($transFile)) {
324
+                $languageFiles[] = $transFile;
325
+            }
326
+        }
327
+
328
+        return $languageFiles;
329
+    }
330
+
331
+    /**
332
+     * find the l10n directory
333
+     *
334
+     * @param string $app App id or empty string for core
335
+     * @return string directory
336
+     */
337
+    protected function findL10nDir($app = null) {
338
+        if (in_array($app, ['core', 'lib', 'settings'])) {
339
+            if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
340
+                return $this->serverRoot . '/' . $app . '/l10n/';
341
+            }
342
+        } else if ($app && \OC_App::getAppPath($app) !== false) {
343
+            // Check if the app is in the app folder
344
+            return \OC_App::getAppPath($app) . '/l10n/';
345
+        }
346
+        return $this->serverRoot . '/core/l10n/';
347
+    }
348
+
349
+
350
+    /**
351
+     * Creates a function from the plural string
352
+     *
353
+     * Parts of the code is copied from Habari:
354
+     * https://github.com/habari/system/blob/master/classes/locale.php
355
+     * @param string $string
356
+     * @return string
357
+     */
358
+    public function createPluralFunction($string) {
359
+        if (isset($this->pluralFunctions[$string])) {
360
+            return $this->pluralFunctions[$string];
361
+        }
362
+
363
+        if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
364
+            // sanitize
365
+            $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
366
+            $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
367
+
368
+            $body = str_replace(
369
+                array( 'plural', 'n', '$n$plurals', ),
370
+                array( '$plural', '$n', '$nplurals', ),
371
+                'nplurals='. $nplurals . '; plural=' . $plural
372
+            );
373
+
374
+            // add parents
375
+            // important since PHP's ternary evaluates from left to right
376
+            $body .= ';';
377
+            $res = '';
378
+            $p = 0;
379
+            for($i = 0; $i < strlen($body); $i++) {
380
+                $ch = $body[$i];
381
+                switch ( $ch ) {
382
+                    case '?':
383
+                        $res .= ' ? (';
384
+                        $p++;
385
+                        break;
386
+                    case ':':
387
+                        $res .= ') : (';
388
+                        break;
389
+                    case ';':
390
+                        $res .= str_repeat( ')', $p ) . ';';
391
+                        $p = 0;
392
+                        break;
393
+                    default:
394
+                        $res .= $ch;
395
+                }
396
+            }
397
+
398
+            $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
399
+            $function = create_function('$n', $body);
400
+            $this->pluralFunctions[$string] = $function;
401
+            return $function;
402
+        } else {
403
+            // default: one plural form for all cases but n==1 (english)
404
+            $function = create_function(
405
+                '$n',
406
+                '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);'
407
+            );
408
+            $this->pluralFunctions[$string] = $function;
409
+            return $function;
410
+        }
411
+    }
412 412
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Cache.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -110,6 +110,9 @@
 block discarded – undo
110 110
 		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
111 111
 	}
112 112
 
113
+	/**
114
+	 * @param ICacheEntry $entry
115
+	 */
113 116
 	protected function formatCacheEntry($entry) {
114 117
 		$path = isset($entry['path']) ? $entry['path'] : '';
115 118
 		$entry = parent::formatCacheEntry($entry);
Please login to merge, or discard this patch.
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -37,106 +37,106 @@
 block discarded – undo
37 37
  * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
38 38
  */
39 39
 class Cache extends CacheJail {
40
-	/**
41
-	 * @var \OCA\Files_Sharing\SharedStorage
42
-	 */
43
-	private $storage;
44
-
45
-	/**
46
-	 * @var ICacheEntry
47
-	 */
48
-	private $sourceRootInfo;
49
-
50
-	private $rootUnchanged = true;
51
-
52
-	private $ownerDisplayName;
53
-
54
-	private $numericId;
55
-
56
-	/**
57
-	 * @param \OCA\Files_Sharing\SharedStorage $storage
58
-	 * @param ICacheEntry $sourceRootInfo
59
-	 */
60
-	public function __construct($storage, ICacheEntry $sourceRootInfo) {
61
-		$this->storage = $storage;
62
-		$this->sourceRootInfo = $sourceRootInfo;
63
-		$this->numericId = $sourceRootInfo->getStorageId();
64
-		parent::__construct(
65
-			null,
66
-			$this->sourceRootInfo->getPath()
67
-		);
68
-	}
69
-
70
-	public function getCache() {
71
-		if (is_null($this->cache)) {
72
-			$this->cache = $this->storage->getSourceStorage()->getCache();
73
-		}
74
-		return $this->cache;
75
-	}
76
-
77
-	public function getNumericStorageId() {
78
-		if (isset($this->numericId)) {
79
-			return $this->numericId;
80
-		} else {
81
-			return false;
82
-		}
83
-	}
84
-
85
-	public function get($file) {
86
-		if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
87
-			return $this->formatCacheEntry(clone $this->sourceRootInfo);
88
-		}
89
-		return parent::get($file);
90
-	}
91
-
92
-	public function update($id, array $data) {
93
-		$this->rootUnchanged = false;
94
-		parent::update($id, $data);
95
-	}
96
-
97
-	public function insert($file, array $data) {
98
-		$this->rootUnchanged = false;
99
-		return parent::insert($file, $data);
100
-	}
101
-
102
-	public function remove($file) {
103
-		$this->rootUnchanged = false;
104
-		parent::remove($file);
105
-	}
106
-
107
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
108
-		$this->rootUnchanged = false;
109
-		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
110
-	}
111
-
112
-	protected function formatCacheEntry($entry) {
113
-		$path = isset($entry['path']) ? $entry['path'] : '';
114
-		$entry = parent::formatCacheEntry($entry);
115
-		$sharePermissions = $this->storage->getPermissions($path);
116
-		if (isset($entry['permissions'])) {
117
-			$entry['permissions'] &= $sharePermissions;
118
-		} else {
119
-			$entry['permissions'] = $sharePermissions;
120
-		}
121
-		$entry['uid_owner'] = $this->storage->getOwner($path);
122
-		$entry['displayname_owner'] = $this->getOwnerDisplayName();
123
-		if ($path === '') {
124
-			$entry['is_share_mount_point'] = true;
125
-		}
126
-		return $entry;
127
-	}
128
-
129
-	private function getOwnerDisplayName() {
130
-		if (!$this->ownerDisplayName) {
131
-			$this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
132
-		}
133
-		return $this->ownerDisplayName;
134
-	}
135
-
136
-	/**
137
-	 * remove all entries for files that are stored on the storage from the cache
138
-	 */
139
-	public function clear() {
140
-		// Not a valid action for Shared Cache
141
-	}
40
+    /**
41
+     * @var \OCA\Files_Sharing\SharedStorage
42
+     */
43
+    private $storage;
44
+
45
+    /**
46
+     * @var ICacheEntry
47
+     */
48
+    private $sourceRootInfo;
49
+
50
+    private $rootUnchanged = true;
51
+
52
+    private $ownerDisplayName;
53
+
54
+    private $numericId;
55
+
56
+    /**
57
+     * @param \OCA\Files_Sharing\SharedStorage $storage
58
+     * @param ICacheEntry $sourceRootInfo
59
+     */
60
+    public function __construct($storage, ICacheEntry $sourceRootInfo) {
61
+        $this->storage = $storage;
62
+        $this->sourceRootInfo = $sourceRootInfo;
63
+        $this->numericId = $sourceRootInfo->getStorageId();
64
+        parent::__construct(
65
+            null,
66
+            $this->sourceRootInfo->getPath()
67
+        );
68
+    }
69
+
70
+    public function getCache() {
71
+        if (is_null($this->cache)) {
72
+            $this->cache = $this->storage->getSourceStorage()->getCache();
73
+        }
74
+        return $this->cache;
75
+    }
76
+
77
+    public function getNumericStorageId() {
78
+        if (isset($this->numericId)) {
79
+            return $this->numericId;
80
+        } else {
81
+            return false;
82
+        }
83
+    }
84
+
85
+    public function get($file) {
86
+        if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
87
+            return $this->formatCacheEntry(clone $this->sourceRootInfo);
88
+        }
89
+        return parent::get($file);
90
+    }
91
+
92
+    public function update($id, array $data) {
93
+        $this->rootUnchanged = false;
94
+        parent::update($id, $data);
95
+    }
96
+
97
+    public function insert($file, array $data) {
98
+        $this->rootUnchanged = false;
99
+        return parent::insert($file, $data);
100
+    }
101
+
102
+    public function remove($file) {
103
+        $this->rootUnchanged = false;
104
+        parent::remove($file);
105
+    }
106
+
107
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
108
+        $this->rootUnchanged = false;
109
+        return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
110
+    }
111
+
112
+    protected function formatCacheEntry($entry) {
113
+        $path = isset($entry['path']) ? $entry['path'] : '';
114
+        $entry = parent::formatCacheEntry($entry);
115
+        $sharePermissions = $this->storage->getPermissions($path);
116
+        if (isset($entry['permissions'])) {
117
+            $entry['permissions'] &= $sharePermissions;
118
+        } else {
119
+            $entry['permissions'] = $sharePermissions;
120
+        }
121
+        $entry['uid_owner'] = $this->storage->getOwner($path);
122
+        $entry['displayname_owner'] = $this->getOwnerDisplayName();
123
+        if ($path === '') {
124
+            $entry['is_share_mount_point'] = true;
125
+        }
126
+        return $entry;
127
+    }
128
+
129
+    private function getOwnerDisplayName() {
130
+        if (!$this->ownerDisplayName) {
131
+            $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
132
+        }
133
+        return $this->ownerDisplayName;
134
+    }
135
+
136
+    /**
137
+     * remove all entries for files that are stored on the storage from the cache
138
+     */
139
+    public function clear() {
140
+        // Not a valid action for Shared Cache
141
+    }
142 142
 }
Please login to merge, or discard this patch.