Passed
Push — master ( 1df567...eb2b1b )
by Morris
14:23 queued 12s
created
config/config.sample.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -41,17 +41,17 @@  discard block
 block discarded – undo
41 41
  */
42 42
 'instanceid' => '',
43 43
 
44
- /**
45
-  * The salt used to hash all passwords, auto-generated by the Nextcloud
46
-  * installer. (There are also per-user salts.) If you lose this salt you lose
47
-  * all your passwords. This example is for documentation only, and you should
48
-  * never use it.
49
-  *
50
-  * @deprecated This salt is deprecated and only used for legacy-compatibility,
51
-  * developers should *NOT* use this value for anything nowadays.
52
-  *
53
-  * 'passwordsalt' => 'd3c944a9af095aa08f',
54
- */
44
+    /**
45
+     * The salt used to hash all passwords, auto-generated by the Nextcloud
46
+     * installer. (There are also per-user salts.) If you lose this salt you lose
47
+     * all your passwords. This example is for documentation only, and you should
48
+     * never use it.
49
+     *
50
+     * @deprecated This salt is deprecated and only used for legacy-compatibility,
51
+     * developers should *NOT* use this value for anything nowadays.
52
+     *
53
+     * 'passwordsalt' => 'd3c944a9af095aa08f',
54
+     */
55 55
 'passwordsalt' => '',
56 56
 
57 57
 /**
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
  *   Using TLS certificates where commonName=<IP address> is deprecated
70 70
  */
71 71
 'trusted_domains' =>
72
-   [
72
+    [
73 73
     'demo.example.org',
74 74
     'otherdomain.example.org',
75 75
     '10.111.112.113',
76 76
     '[2001:db8::1]'
77
-  ],
77
+    ],
78 78
 
79 79
 
80 80
 /**
@@ -718,10 +718,10 @@  discard block
 block discarded – undo
718 718
  *  - www.edri.org
719 719
  */
720 720
 'connectivity_check_domains' => [
721
-	'www.nextcloud.com',
722
-	'www.startpage.com',
723
-	'www.eff.org',
724
-	'www.edri.org'
721
+    'www.nextcloud.com',
722
+    'www.startpage.com',
723
+    'www.eff.org',
724
+    'www.edri.org'
725 725
 ],
726 726
 
727 727
 /**
@@ -837,9 +837,9 @@  discard block
 block discarded – undo
837 837
  * Defaults to an empty array.
838 838
  */
839 839
 'log.condition' => [
840
-	'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9',
841
-	'users' => ['sample-user'],
842
-	'apps' => ['files'],
840
+    'shared_secret' => '57b58edb6637fe3059b3595cf9c41b9',
841
+    'users' => ['sample-user'],
842
+    'apps' => ['files'],
843 843
 ],
844 844
 
845 845
 /**
@@ -893,18 +893,18 @@  discard block
 block discarded – undo
893 893
  *  - iOS client app id: ``1125420102``
894 894
  */
895 895
 'customclient_desktop' =>
896
-	'https://nextcloud.com/install/#install-clients',
896
+    'https://nextcloud.com/install/#install-clients',
897 897
 'customclient_android' =>
898
-	'https://play.google.com/store/apps/details?id=com.nextcloud.client',
898
+    'https://play.google.com/store/apps/details?id=com.nextcloud.client',
899 899
 'customclient_ios' =>
900
-	'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8',
900
+    'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8',
901 901
 'customclient_ios_appid' =>
902
-		'1125420102',
902
+        '1125420102',
903 903
 /**
904
- * Apps
905
- *
906
- * Options for the Apps folder, Apps store, and App code checker.
907
- */
904
+         * Apps
905
+         *
906
+         * Options for the Apps folder, Apps store, and App code checker.
907
+         */
908 908
 
909 909
 /**
910 910
  * When enabled, admins may install apps from the Nextcloud app store.
@@ -930,11 +930,11 @@  discard block
 block discarded – undo
930 930
  * indicates if a Web server can write files to that folder.
931 931
  */
932 932
 'apps_paths' => [
933
-	[
934
-		'path'=> '/var/www/nextcloud/apps',
935
-		'url' => '/apps',
936
-		'writable' => true,
937
-	],
933
+    [
934
+        'path'=> '/var/www/nextcloud/apps',
935
+        'url' => '/apps',
936
+        'writable' => true,
937
+    ],
938 938
 ],
939 939
 
940 940
 /**
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
  * Defaults to ``''`` (empty string)
1000 1000
  */
1001 1001
 'preview_office_cl_parameters' =>
1002
-	' --headless --nologo --nofirststartwizard --invisible --norestore '.
1003
-	'--convert-to png --outdir ',
1002
+    ' --headless --nologo --nofirststartwizard --invisible --norestore '.
1003
+    '--convert-to png --outdir ',
1004 1004
 
1005 1005
 /**
1006 1006
  * Only register providers that have been explicitly enabled
@@ -1037,17 +1037,17 @@  discard block
 block discarded – undo
1037 1037
  *  - OC\Preview\Krita
1038 1038
  */
1039 1039
 'enabledPreviewProviders' => [
1040
-	'OC\Preview\PNG',
1041
-	'OC\Preview\JPEG',
1042
-	'OC\Preview\GIF',
1043
-	'OC\Preview\HEIC',
1044
-	'OC\Preview\BMP',
1045
-	'OC\Preview\XBitmap',
1046
-	'OC\Preview\MP3',
1047
-	'OC\Preview\TXT',
1048
-	'OC\Preview\MarkDown',
1049
-	'OC\Preview\OpenDocument',
1050
-	'OC\Preview\Krita',
1040
+    'OC\Preview\PNG',
1041
+    'OC\Preview\JPEG',
1042
+    'OC\Preview\GIF',
1043
+    'OC\Preview\HEIC',
1044
+    'OC\Preview\BMP',
1045
+    'OC\Preview\XBitmap',
1046
+    'OC\Preview\MP3',
1047
+    'OC\Preview\TXT',
1048
+    'OC\Preview\MarkDown',
1049
+    'OC\Preview\OpenDocument',
1050
+    'OC\Preview\Krita',
1051 1051
 ],
1052 1052
 
1053 1053
 /**
@@ -1123,11 +1123,11 @@  discard block
 block discarded – undo
1123 1123
 
1124 1124
 /**
1125 1125
  * Extra SSL options to be used for configuration.
1126
-  *
1126
+ *
1127 1127
  * Defaults to an empty array.
1128 1128
  */
1129 1129
 'openssl' => [
1130
-	'config' => '/absolute/location/of/openssl.cnf',
1130
+    'config' => '/absolute/location/of/openssl.cnf',
1131 1131
 ],
1132 1132
 
1133 1133
 /**
@@ -1175,11 +1175,11 @@  discard block
 block discarded – undo
1175 1175
  * for more information.
1176 1176
  */
1177 1177
 'redis' => [
1178
-	'host' => 'localhost', // can also be a unix domain socket: '/tmp/redis.sock'
1179
-	'port' => 6379,
1180
-	'timeout' => 0.0,
1181
-	'password' => '', // Optional, if not defined no password will be used.
1182
-	'dbindex' => 0, // Optional, if undefined SELECT will not run and will use Redis Server's default DB Index.
1178
+    'host' => 'localhost', // can also be a unix domain socket: '/tmp/redis.sock'
1179
+    'port' => 6379,
1180
+    'timeout' => 0.0,
1181
+    'password' => '', // Optional, if not defined no password will be used.
1182
+    'dbindex' => 0, // Optional, if undefined SELECT will not run and will use Redis Server's default DB Index.
1183 1183
 ],
1184 1184
 
1185 1185
 /**
@@ -1208,14 +1208,14 @@  discard block
 block discarded – undo
1208 1208
  * https://github.com/phpredis/phpredis/commit/c5994f2a42b8a348af92d3acb4edff1328ad8ce1
1209 1209
  */
1210 1210
 'redis.cluster' => [
1211
-	'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required
1212
-		'localhost:7000',
1213
-		'localhost:7001',
1214
-	],
1215
-	'timeout' => 0.0,
1216
-	'read_timeout' => 0.0,
1217
-	'failover_mode' => \RedisCluster::FAILOVER_ERROR,
1218
-	'password' => '', // Optional, if not defined no password will be used.
1211
+    'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required
1212
+        'localhost:7000',
1213
+        'localhost:7001',
1214
+    ],
1215
+    'timeout' => 0.0,
1216
+    'read_timeout' => 0.0,
1217
+    'failover_mode' => \RedisCluster::FAILOVER_ERROR,
1218
+    'password' => '', // Optional, if not defined no password will be used.
1219 1219
 ],
1220 1220
 
1221 1221
 
@@ -1223,35 +1223,35 @@  discard block
 block discarded – undo
1223 1223
  * Server details for one or more memcached servers to use for memory caching.
1224 1224
  */
1225 1225
 'memcached_servers' => [
1226
-	// hostname, port and optional weight. Also see:
1227
-	// http://www.php.net/manual/en/memcached.addservers.php
1228
-	// http://www.php.net/manual/en/memcached.addserver.php
1229
-	['localhost', 11211],
1230
-	//array('other.host.local', 11211),
1226
+    // hostname, port and optional weight. Also see:
1227
+    // http://www.php.net/manual/en/memcached.addservers.php
1228
+    // http://www.php.net/manual/en/memcached.addserver.php
1229
+    ['localhost', 11211],
1230
+    //array('other.host.local', 11211),
1231 1231
 ],
1232 1232
 
1233 1233
 /**
1234 1234
  * Connection options for memcached
1235 1235
  */
1236 1236
 'memcached_options' => [
1237
-	// Set timeouts to 50ms
1238
-	\Memcached::OPT_CONNECT_TIMEOUT => 50,
1239
-	\Memcached::OPT_RETRY_TIMEOUT =>   50,
1240
-	\Memcached::OPT_SEND_TIMEOUT =>    50,
1241
-	\Memcached::OPT_RECV_TIMEOUT =>    50,
1242
-	\Memcached::OPT_POLL_TIMEOUT =>    50,
1237
+    // Set timeouts to 50ms
1238
+    \Memcached::OPT_CONNECT_TIMEOUT => 50,
1239
+    \Memcached::OPT_RETRY_TIMEOUT =>   50,
1240
+    \Memcached::OPT_SEND_TIMEOUT =>    50,
1241
+    \Memcached::OPT_RECV_TIMEOUT =>    50,
1242
+    \Memcached::OPT_POLL_TIMEOUT =>    50,
1243 1243
 
1244
-	// Enable compression
1245
-	\Memcached::OPT_COMPRESSION =>          true,
1244
+    // Enable compression
1245
+    \Memcached::OPT_COMPRESSION =>          true,
1246 1246
 
1247
-	// Turn on consistent hashing
1248
-	\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
1247
+    // Turn on consistent hashing
1248
+    \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
1249 1249
 
1250
-	// Enable Binary Protocol
1251
-	\Memcached::OPT_BINARY_PROTOCOL =>      true,
1250
+    // Enable Binary Protocol
1251
+    \Memcached::OPT_BINARY_PROTOCOL =>      true,
1252 1252
 
1253
-	// Binary serializer vill be enabled if the igbinary PECL module is available
1254
-	//\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY,
1253
+    // Binary serializer vill be enabled if the igbinary PECL module is available
1254
+    //\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY,
1255 1255
 ],
1256 1256
 
1257 1257
 
@@ -1297,61 +1297,61 @@  discard block
 block discarded – undo
1297 1297
  * One way to test is applying for a trystack account at http://trystack.org/
1298 1298
  */
1299 1299
 'objectstore' => [
1300
-	'class' => 'OC\\Files\\ObjectStore\\Swift',
1301
-	'arguments' => [
1302
-		// trystack will use your facebook id as the user name
1303
-		'username' => 'facebook100000123456789',
1304
-		// in the trystack dashboard go to user -> settings -> API Password to
1305
-		// generate a password
1306
-		'password' => 'Secr3tPaSSWoRdt7',
1307
-		// must already exist in the objectstore, name can be different
1308
-		'container' => 'nextcloud',
1309
-		// prefix to prepend to the fileid, default is 'oid:urn:'
1310
-		'objectPrefix' => 'oid:urn:',
1311
-		// create the container if it does not exist. default is false
1312
-		'autocreate' => true,
1313
-		// required, dev-/trystack defaults to 'RegionOne'
1314
-		'region' => 'RegionOne',
1315
-		// The Identity / Keystone endpoint
1316
-		'url' => 'http://8.21.28.222:5000/v2.0',
1317
-		// required on dev-/trystack
1318
-		'tenantName' => 'facebook100000123456789',
1319
-		// dev-/trystack uses swift by default, the lib defaults to 'cloudFiles'
1320
-		// if omitted
1321
-		'serviceName' => 'swift',
1322
-		// The Interface / url Type, optional
1323
-		'urlType' => 'internal'
1324
-	],
1300
+    'class' => 'OC\\Files\\ObjectStore\\Swift',
1301
+    'arguments' => [
1302
+        // trystack will use your facebook id as the user name
1303
+        'username' => 'facebook100000123456789',
1304
+        // in the trystack dashboard go to user -> settings -> API Password to
1305
+        // generate a password
1306
+        'password' => 'Secr3tPaSSWoRdt7',
1307
+        // must already exist in the objectstore, name can be different
1308
+        'container' => 'nextcloud',
1309
+        // prefix to prepend to the fileid, default is 'oid:urn:'
1310
+        'objectPrefix' => 'oid:urn:',
1311
+        // create the container if it does not exist. default is false
1312
+        'autocreate' => true,
1313
+        // required, dev-/trystack defaults to 'RegionOne'
1314
+        'region' => 'RegionOne',
1315
+        // The Identity / Keystone endpoint
1316
+        'url' => 'http://8.21.28.222:5000/v2.0',
1317
+        // required on dev-/trystack
1318
+        'tenantName' => 'facebook100000123456789',
1319
+        // dev-/trystack uses swift by default, the lib defaults to 'cloudFiles'
1320
+        // if omitted
1321
+        'serviceName' => 'swift',
1322
+        // The Interface / url Type, optional
1323
+        'urlType' => 'internal'
1324
+    ],
1325 1325
 ],
1326 1326
 
1327 1327
 /**
1328 1328
  * To use swift V3
1329 1329
  */
1330 1330
 'objectstore' => [
1331
-	'class' => 'OC\\Files\\ObjectStore\\Swift',
1332
-	'arguments' => [
1333
-		'autocreate' => true,
1334
-		'user' => [
1335
-			'name' => 'swift',
1336
-			'password' => 'swift',
1337
-			'domain' => [
1338
-				'name' => 'default',
1339
-			],
1340
-		],
1341
-		'scope' => [
1342
-			'project' => [
1343
-				'name' => 'service',
1344
-				'domain' => [
1345
-					'name' => 'default',
1346
-				],
1347
-			],
1348
-		],
1349
-		'tenantName' => 'service',
1350
-		'serviceName' => 'swift',
1351
-		'region' => 'regionOne',
1352
-		'url' => 'http://yourswifthost:5000/v3',
1353
-		'bucket' => 'nextcloud',
1354
-	],
1331
+    'class' => 'OC\\Files\\ObjectStore\\Swift',
1332
+    'arguments' => [
1333
+        'autocreate' => true,
1334
+        'user' => [
1335
+            'name' => 'swift',
1336
+            'password' => 'swift',
1337
+            'domain' => [
1338
+                'name' => 'default',
1339
+            ],
1340
+        ],
1341
+        'scope' => [
1342
+            'project' => [
1343
+                'name' => 'service',
1344
+                'domain' => [
1345
+                    'name' => 'default',
1346
+                ],
1347
+            ],
1348
+        ],
1349
+        'tenantName' => 'service',
1350
+        'serviceName' => 'swift',
1351
+        'region' => 'regionOne',
1352
+        'url' => 'http://yourswifthost:5000/v3',
1353
+        'bucket' => 'nextcloud',
1354
+    ],
1355 1355
 ],
1356 1356
 
1357 1357
 /**
@@ -1420,8 +1420,8 @@  discard block
 block discarded – undo
1420 1420
  * encryption in MySQL or specify a custom wait timeout on a cheap hoster.
1421 1421
  */
1422 1422
 'dbdriveroptions' => [
1423
-	PDO::MYSQL_ATTR_SSL_CA => '/file/path/to/ca_cert.pem',
1424
-	PDO::MYSQL_ATTR_INIT_COMMAND => 'SET wait_timeout = 28800'
1423
+    PDO::MYSQL_ATTR_SSL_CA => '/file/path/to/ca_cert.pem',
1424
+    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET wait_timeout = 28800'
1425 1425
 ],
1426 1426
 
1427 1427
 /**
@@ -1478,10 +1478,10 @@  discard block
 block discarded – undo
1478 1478
  *  - pgsql (PostgreSQL)
1479 1479
  */
1480 1480
 'supportedDatabases' => [
1481
-	'sqlite',
1482
-	'mysql',
1483
-	'pgsql',
1484
-	'oci',
1481
+    'sqlite',
1482
+    'mysql',
1483
+    'pgsql',
1484
+    'oci',
1485 1485
 ],
1486 1486
 
1487 1487
 /**
@@ -1809,8 +1809,8 @@  discard block
 block discarded – undo
1809 1809
  * WARNING: only use this if you know what you are doing
1810 1810
  */
1811 1811
 'csrf.optout' => [
1812
-	'/^WebDAVFS/', // OS X Finder
1813
-	'/^Microsoft-WebDAV-MiniRedir/', // Windows webdav drive
1812
+    '/^WebDAVFS/', // OS X Finder
1813
+    '/^Microsoft-WebDAV-MiniRedir/', // Windows webdav drive
1814 1814
 ],
1815 1815
 
1816 1816
 /**
Please login to merge, or discard this patch.
lib/private/Preview/Storage/Root.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
 use OCP\Files\SimpleFS\ISimpleFolder;
33 33
 
34 34
 class Root extends AppData {
35
-	private $isMultibucketPreviewDistributionEnabled = false;
36
-	public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) {
37
-		parent::__construct($rootFolder, $systemConfig, 'preview');
35
+    private $isMultibucketPreviewDistributionEnabled = false;
36
+    public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) {
37
+        parent::__construct($rootFolder, $systemConfig, 'preview');
38 38
 
39
-		$this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true;
40
-	}
39
+        $this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true;
40
+    }
41 41
 
42 42
 
43
-	public function getFolder(string $name): ISimpleFolder {
44
-		$internalFolder = $this->getInternalFolder($name);
43
+    public function getFolder(string $name): ISimpleFolder {
44
+        $internalFolder = $this->getInternalFolder($name);
45 45
 
46
-		if ($this->isMultibucketPreviewDistributionEnabled) {
47
-			try {
48
-				return parent::getFolder('old-multibucket/' . $internalFolder);
49
-			} catch (NotFoundException $e) {
50
-				// not in multibucket fallback
51
-			}
52
-		}
46
+        if ($this->isMultibucketPreviewDistributionEnabled) {
47
+            try {
48
+                return parent::getFolder('old-multibucket/' . $internalFolder);
49
+            } catch (NotFoundException $e) {
50
+                // not in multibucket fallback
51
+            }
52
+        }
53 53
 
54
-		try {
55
-			return parent::getFolder($internalFolder);
56
-		} catch (NotFoundException $e) {
57
-			/*
54
+        try {
55
+            return parent::getFolder($internalFolder);
56
+        } catch (NotFoundException $e) {
57
+            /*
58 58
 			 * The new folder structure is not found.
59 59
 			 * Lets try the old one
60 60
 			 */
61
-		}
61
+        }
62 62
 
63
-		return parent::getFolder($name);
64
-	}
63
+        return parent::getFolder($name);
64
+    }
65 65
 
66
-	public function newFolder(string $name): ISimpleFolder {
67
-		$internalFolder = $this->getInternalFolder($name);
68
-		return parent::newFolder($internalFolder);
69
-	}
66
+    public function newFolder(string $name): ISimpleFolder {
67
+        $internalFolder = $this->getInternalFolder($name);
68
+        return parent::newFolder($internalFolder);
69
+    }
70 70
 
71
-	/*
71
+    /*
72 72
 	 * Do not allow directory listing on this special root
73 73
 	 * since it gets to big and time consuming
74 74
 	 */
75
-	public function getDirectoryListing(): array {
76
-		return [];
77
-	}
75
+    public function getDirectoryListing(): array {
76
+        return [];
77
+    }
78 78
 
79
-	private function getInternalFolder(string $name): string {
80
-		return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name;
81
-	}
79
+    private function getInternalFolder(string $name): string {
80
+        return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name;
81
+    }
82 82
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 		if ($this->isMultibucketPreviewDistributionEnabled) {
47 47
 			try {
48
-				return parent::getFolder('old-multibucket/' . $internalFolder);
48
+				return parent::getFolder('old-multibucket/'.$internalFolder);
49 49
 			} catch (NotFoundException $e) {
50 50
 				// not in multibucket fallback
51 51
 			}
@@ -77,6 +77,6 @@  discard block
 block discarded – undo
77 77
 	}
78 78
 
79 79
 	private function getInternalFolder(string $name): string {
80
-		return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name;
80
+		return implode('/', str_split(substr(md5($name), 0, 7))).'/'.$name;
81 81
 	}
82 82
 }
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +2096 added lines, -2096 removed lines patch added patch discarded remove patch
@@ -245,2105 +245,2105 @@
 block discarded – undo
245 245
  */
246 246
 class Server extends ServerContainer implements IServerContainer {
247 247
 
248
-	/** @var string */
249
-	private $webRoot;
250
-
251
-	/**
252
-	 * @param string $webRoot
253
-	 * @param \OC\Config $config
254
-	 */
255
-	public function __construct($webRoot, \OC\Config $config) {
256
-		parent::__construct();
257
-		$this->webRoot = $webRoot;
258
-
259
-		// To find out if we are running from CLI or not
260
-		$this->registerParameter('isCLI', \OC::$CLI);
261
-
262
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
263
-			return $c;
264
-		});
265
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
266
-			return $c;
267
-		});
268
-
269
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
270
-		$this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
271
-
272
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
273
-		$this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
274
-
275
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
276
-		$this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
277
-
278
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
279
-		$this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
280
-
281
-		$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
282
-
283
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
284
-
285
-
286
-		$this->registerService(IPreview::class, function (Server $c) {
287
-			return new PreviewManager(
288
-				$c->getConfig(),
289
-				$c->getRootFolder(),
290
-				new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig(), 'preview'),
291
-				$c->getEventDispatcher(),
292
-				$c->getGeneratorHelper(),
293
-				$c->getSession()->get('user_id')
294
-			);
295
-		});
296
-		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
297
-
298
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
299
-			return new \OC\Preview\Watcher(
300
-				new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig(), 'preview')
301
-			);
302
-		});
303
-
304
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
305
-			$view = new View();
306
-			$util = new Encryption\Util(
307
-				$view,
308
-				$c->getUserManager(),
309
-				$c->getGroupManager(),
310
-				$c->getConfig()
311
-			);
312
-			return new Encryption\Manager(
313
-				$c->getConfig(),
314
-				$c->getLogger(),
315
-				$c->getL10N('core'),
316
-				new View(),
317
-				$util,
318
-				new ArrayCache()
319
-			);
320
-		});
321
-		$this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
322
-
323
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
324
-			$util = new Encryption\Util(
325
-				new View(),
326
-				$c->getUserManager(),
327
-				$c->getGroupManager(),
328
-				$c->getConfig()
329
-			);
330
-			return new Encryption\File(
331
-				$util,
332
-				$c->getRootFolder(),
333
-				$c->getShareManager()
334
-			);
335
-		});
336
-
337
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
338
-			$view = new View();
339
-			$util = new Encryption\Util(
340
-				$view,
341
-				$c->getUserManager(),
342
-				$c->getGroupManager(),
343
-				$c->getConfig()
344
-			);
345
-
346
-			return new Encryption\Keys\Storage($view, $util);
347
-		});
348
-		$this->registerService('TagMapper', function (Server $c) {
349
-			return new TagMapper($c->getDatabaseConnection());
350
-		});
351
-
352
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
353
-			$tagMapper = $c->query('TagMapper');
354
-			return new TagManager($tagMapper, $c->getUserSession());
355
-		});
356
-		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
357
-
358
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
359
-			$config = $c->getConfig();
360
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
361
-			return new $factoryClass($this);
362
-		});
363
-		$this->registerService(ISystemTagManager::class, function (Server $c) {
364
-			return $c->query('SystemTagManagerFactory')->getManager();
365
-		});
366
-		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
367
-
368
-		$this->registerService(ISystemTagObjectMapper::class, function (Server $c) {
369
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
370
-		});
371
-		$this->registerService('RootFolder', function (Server $c) {
372
-			$manager = \OC\Files\Filesystem::getMountManager(null);
373
-			$view = new View();
374
-			$root = new Root(
375
-				$manager,
376
-				$view,
377
-				null,
378
-				$c->getUserMountCache(),
379
-				$this->getLogger(),
380
-				$this->getUserManager()
381
-			);
382
-
383
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
384
-			$previewConnector->connectWatcher();
385
-
386
-			return $root;
387
-		});
388
-		$this->registerService(HookConnector::class, function (Server $c) {
389
-			return new HookConnector(
390
-				$c->query(IRootFolder::class),
391
-				new View(),
392
-				$c->query(\OC\EventDispatcher\SymfonyAdapter::class),
393
-				$c->query(IEventDispatcher::class)
394
-			);
395
-		});
396
-
397
-		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
398
-
399
-		$this->registerService(IRootFolder::class, function (Server $c) {
400
-			return new LazyRoot(function () use ($c) {
401
-				return $c->query('RootFolder');
402
-			});
403
-		});
404
-		$this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
405
-
406
-		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
407
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
408
-
409
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
410
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
411
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
412
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
413
-
414
-				/** @var IEventDispatcher $dispatcher */
415
-				$dispatcher = $this->query(IEventDispatcher::class);
416
-				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
417
-			});
418
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
419
-				\OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]);
420
-
421
-				/** @var IEventDispatcher $dispatcher */
422
-				$dispatcher = $this->query(IEventDispatcher::class);
423
-				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
424
-			});
425
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
426
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
427
-
428
-				/** @var IEventDispatcher $dispatcher */
429
-				$dispatcher = $this->query(IEventDispatcher::class);
430
-				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
431
-			});
432
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
433
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
434
-
435
-				/** @var IEventDispatcher $dispatcher */
436
-				$dispatcher = $this->query(IEventDispatcher::class);
437
-				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
438
-			});
439
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
440
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
441
-
442
-				/** @var IEventDispatcher $dispatcher */
443
-				$dispatcher = $this->query(IEventDispatcher::class);
444
-				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
445
-			});
446
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
447
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
448
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
449
-				\OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
450
-
451
-				/** @var IEventDispatcher $dispatcher */
452
-				$dispatcher = $this->query(IEventDispatcher::class);
453
-				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
454
-			});
455
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
456
-				/** @var IEventDispatcher $dispatcher */
457
-				$dispatcher = $this->query(IEventDispatcher::class);
458
-				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
459
-			});
460
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
461
-				/** @var IEventDispatcher $dispatcher */
462
-				$dispatcher = $this->query(IEventDispatcher::class);
463
-				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
464
-			});
465
-			return $groupManager;
466
-		});
467
-		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
468
-
469
-		$this->registerService(Store::class, function (Server $c) {
470
-			$session = $c->getSession();
471
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
472
-				$tokenProvider = $c->query(IProvider::class);
473
-			} else {
474
-				$tokenProvider = null;
475
-			}
476
-			$logger = $c->getLogger();
477
-			return new Store($session, $logger, $tokenProvider);
478
-		});
479
-		$this->registerAlias(IStore::class, Store::class);
480
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
481
-			$dbConnection = $c->getDatabaseConnection();
482
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
483
-		});
484
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
485
-
486
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
487
-			$manager = $c->getUserManager();
488
-			$session = new \OC\Session\Memory('');
489
-			$timeFactory = new TimeFactory();
490
-			// Token providers might require a working database. This code
491
-			// might however be called when ownCloud is not yet setup.
492
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
493
-				$defaultTokenProvider = $c->query(IProvider::class);
494
-			} else {
495
-				$defaultTokenProvider = null;
496
-			}
497
-
498
-			$legacyDispatcher = $c->getEventDispatcher();
499
-
500
-			$userSession = new \OC\User\Session(
501
-				$manager,
502
-				$session,
503
-				$timeFactory,
504
-				$defaultTokenProvider,
505
-				$c->getConfig(),
506
-				$c->getSecureRandom(),
507
-				$c->getLockdownManager(),
508
-				$c->getLogger(),
509
-				$c->query(IEventDispatcher::class)
510
-			);
511
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
512
-				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
513
-
514
-				/** @var IEventDispatcher $dispatcher */
515
-				$dispatcher = $this->query(IEventDispatcher::class);
516
-				$dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password));
517
-			});
518
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
519
-				/** @var $user \OC\User\User */
520
-				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
521
-
522
-				/** @var IEventDispatcher $dispatcher */
523
-				$dispatcher = $this->query(IEventDispatcher::class);
524
-				$dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
525
-			});
526
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
527
-				/** @var $user \OC\User\User */
528
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
529
-				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
530
-
531
-				/** @var IEventDispatcher $dispatcher */
532
-				$dispatcher = $this->query(IEventDispatcher::class);
533
-				$dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user));
534
-			});
535
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
536
-				/** @var $user \OC\User\User */
537
-				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
538
-
539
-				/** @var IEventDispatcher $dispatcher */
540
-				$dispatcher = $this->query(IEventDispatcher::class);
541
-				$dispatcher->dispatchTyped(new UserDeletedEvent($user));
542
-			});
543
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
544
-				/** @var $user \OC\User\User */
545
-				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
546
-
547
-				/** @var IEventDispatcher $dispatcher */
548
-				$dispatcher = $this->query(IEventDispatcher::class);
549
-				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
550
-			});
551
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
552
-				/** @var $user \OC\User\User */
553
-				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
554
-
555
-				/** @var IEventDispatcher $dispatcher */
556
-				$dispatcher = $this->query(IEventDispatcher::class);
557
-				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
558
-			});
559
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
560
-				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
561
-
562
-				/** @var IEventDispatcher $dispatcher */
563
-				$dispatcher = $this->query(IEventDispatcher::class);
564
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
565
-			});
566
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
567
-				/** @var $user \OC\User\User */
568
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
569
-
570
-				/** @var IEventDispatcher $dispatcher */
571
-				$dispatcher = $this->query(IEventDispatcher::class);
572
-				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
573
-			});
574
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
575
-				/** @var IEventDispatcher $dispatcher */
576
-				$dispatcher = $this->query(IEventDispatcher::class);
577
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
578
-			});
579
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
580
-				/** @var $user \OC\User\User */
581
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
582
-
583
-				/** @var IEventDispatcher $dispatcher */
584
-				$dispatcher = $this->query(IEventDispatcher::class);
585
-				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
586
-			});
587
-			$userSession->listen('\OC\User', 'logout', function ($user) {
588
-				\OC_Hook::emit('OC_User', 'logout', []);
589
-
590
-				/** @var IEventDispatcher $dispatcher */
591
-				$dispatcher = $this->query(IEventDispatcher::class);
592
-				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
593
-			});
594
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
595
-				/** @var IEventDispatcher $dispatcher */
596
-				$dispatcher = $this->query(IEventDispatcher::class);
597
-				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
598
-			});
599
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
600
-				/** @var $user \OC\User\User */
601
-				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
602
-
603
-				/** @var IEventDispatcher $dispatcher */
604
-				$dispatcher = $this->query(IEventDispatcher::class);
605
-				$dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
606
-			});
607
-			return $userSession;
608
-		});
609
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
610
-		$this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
611
-
612
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
613
-
614
-		$this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
615
-		$this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
616
-
617
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
618
-			return new \OC\AllConfig(
619
-				$c->getSystemConfig()
620
-			);
621
-		});
622
-		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
623
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
624
-
625
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
626
-			return new \OC\SystemConfig($config);
627
-		});
628
-		$this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
629
-
630
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
631
-			return new \OC\AppConfig($c->getDatabaseConnection());
632
-		});
633
-		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
634
-		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
635
-
636
-		$this->registerService(IFactory::class, function (Server $c) {
637
-			return new \OC\L10N\Factory(
638
-				$c->getConfig(),
639
-				$c->getRequest(),
640
-				$c->getUserSession(),
641
-				\OC::$SERVERROOT
642
-			);
643
-		});
644
-		$this->registerDeprecatedAlias('L10NFactory', IFactory::class);
645
-
646
-		$this->registerService(IURLGenerator::class, function (Server $c) {
647
-			$config = $c->getConfig();
648
-			$cacheFactory = $c->getMemCacheFactory();
649
-			$request = $c->getRequest();
650
-			return new \OC\URLGenerator(
651
-				$config,
652
-				$cacheFactory,
653
-				$request
654
-			);
655
-		});
656
-		$this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
657
-
658
-		$this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
659
-		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
660
-
661
-		$this->registerService(ICache::class, function ($c) {
662
-			return new Cache\File();
663
-		});
664
-		$this->registerDeprecatedAlias('UserCache', ICache::class);
665
-
666
-		$this->registerService(Factory::class, function (Server $c) {
667
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
668
-				ArrayCache::class,
669
-				ArrayCache::class,
670
-				ArrayCache::class
671
-			);
672
-			$config = $c->getConfig();
673
-
674
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
675
-				$v = \OC_App::getAppVersions();
676
-				$v['core'] = implode(',', \OC_Util::getVersion());
677
-				$version = implode(',', $v);
678
-				$instanceId = \OC_Util::getInstanceId();
679
-				$path = \OC::$SERVERROOT;
680
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
681
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
682
-					$config->getSystemValue('memcache.local', null),
683
-					$config->getSystemValue('memcache.distributed', null),
684
-					$config->getSystemValue('memcache.locking', null)
685
-				);
686
-			}
687
-			return $arrayCacheFactory;
688
-		});
689
-		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
690
-		$this->registerAlias(ICacheFactory::class, Factory::class);
691
-
692
-		$this->registerService('RedisFactory', function (Server $c) {
693
-			$systemConfig = $c->getSystemConfig();
694
-			return new RedisFactory($systemConfig);
695
-		});
696
-
697
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
698
-			return new \OC\Activity\Manager(
699
-				$c->getRequest(),
700
-				$c->getUserSession(),
701
-				$c->getConfig(),
702
-				$c->query(IValidator::class)
703
-			);
704
-		});
705
-		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
706
-
707
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
708
-			return new \OC\Activity\EventMerger(
709
-				$c->getL10N('lib')
710
-			);
711
-		});
712
-		$this->registerAlias(IValidator::class, Validator::class);
713
-
714
-		$this->registerService(AvatarManager::class, function (Server $c) {
715
-			return new AvatarManager(
716
-				$c->query(\OC\User\Manager::class),
717
-				$c->getAppDataDir('avatar'),
718
-				$c->getL10N('lib'),
719
-				$c->getLogger(),
720
-				$c->getConfig()
721
-			);
722
-		});
723
-		$this->registerAlias(IAvatarManager::class, AvatarManager::class);
724
-		$this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
725
-
726
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
727
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
728
-
729
-		$this->registerService(\OC\Log::class, function (Server $c) {
730
-			$logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file');
731
-			$factory = new LogFactory($c, $this->getSystemConfig());
732
-			$logger = $factory->get($logType);
733
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
734
-
735
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
736
-		});
737
-		$this->registerAlias(ILogger::class, \OC\Log::class);
738
-		$this->registerDeprecatedAlias('Logger', \OC\Log::class);
739
-		// PSR-3 logger
740
-		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
741
-
742
-		$this->registerService(ILogFactory::class, function (Server $c) {
743
-			return new LogFactory($c, $this->getSystemConfig());
744
-		});
745
-
746
-		$this->registerService(IJobList::class, function (Server $c) {
747
-			$config = $c->getConfig();
748
-			return new \OC\BackgroundJob\JobList(
749
-				$c->getDatabaseConnection(),
750
-				$config,
751
-				new TimeFactory()
752
-			);
753
-		});
754
-		$this->registerDeprecatedAlias('JobList', IJobList::class);
755
-
756
-		$this->registerService(IRouter::class, function (Server $c) {
757
-			$cacheFactory = $c->getMemCacheFactory();
758
-			$logger = $c->getLogger();
759
-			if ($cacheFactory->isLocalCacheAvailable()) {
760
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
761
-			} else {
762
-				$router = new \OC\Route\Router($logger);
763
-			}
764
-			return $router;
765
-		});
766
-		$this->registerDeprecatedAlias('Router', IRouter::class);
767
-
768
-		$this->registerService(ISearch::class, function ($c) {
769
-			return new Search();
770
-		});
771
-		$this->registerDeprecatedAlias('Search', ISearch::class);
772
-
773
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
774
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
775
-				$this->getMemCacheFactory(),
776
-				new \OC\AppFramework\Utility\TimeFactory()
777
-			);
778
-		});
779
-
780
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
781
-			return new SecureRandom();
782
-		});
783
-		$this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
784
-
785
-		$this->registerService(ICrypto::class, function (Server $c) {
786
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
787
-		});
788
-		$this->registerDeprecatedAlias('Crypto', ICrypto::class);
789
-
790
-		$this->registerService(IHasher::class, function (Server $c) {
791
-			return new Hasher($c->getConfig());
792
-		});
793
-		$this->registerDeprecatedAlias('Hasher', IHasher::class);
794
-
795
-		$this->registerService(ICredentialsManager::class, function (Server $c) {
796
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
797
-		});
798
-		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
799
-
800
-		$this->registerService(IDBConnection::class, function (Server $c) {
801
-			$systemConfig = $c->getSystemConfig();
802
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
803
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
804
-			if (!$factory->isValidType($type)) {
805
-				throw new \OC\DatabaseException('Invalid database type');
806
-			}
807
-			$connectionParams = $factory->createConnectionParams();
808
-			$connection = $factory->getConnection($type, $connectionParams);
809
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
810
-			return $connection;
811
-		});
812
-		$this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
813
-
814
-
815
-		$this->registerService(IClientService::class, function (Server $c) {
816
-			$user = \OC_User::getUser();
817
-			$uid = $user ? $user : null;
818
-			return new ClientService(
819
-				$c->getConfig(),
820
-				$c->getLogger(),
821
-				new \OC\Security\CertificateManager(
822
-					$uid,
823
-					new View(),
824
-					$c->getConfig(),
825
-					$c->getLogger(),
826
-					$c->getSecureRandom()
827
-				)
828
-			);
829
-		});
830
-		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
831
-		$this->registerService(IEventLogger::class, function (Server $c) {
832
-			$eventLogger = new EventLogger();
833
-			if ($c->getSystemConfig()->getValue('debug', false)) {
834
-				// In debug mode, module is being activated by default
835
-				$eventLogger->activate();
836
-			}
837
-			return $eventLogger;
838
-		});
839
-		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
840
-
841
-		$this->registerService(IQueryLogger::class, function (Server $c) {
842
-			$queryLogger = new QueryLogger();
843
-			if ($c->getSystemConfig()->getValue('debug', false)) {
844
-				// In debug mode, module is being activated by default
845
-				$queryLogger->activate();
846
-			}
847
-			return $queryLogger;
848
-		});
849
-		$this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
850
-
851
-		$this->registerService(TempManager::class, function (Server $c) {
852
-			return new TempManager(
853
-				$c->getLogger(),
854
-				$c->getConfig()
855
-			);
856
-		});
857
-		$this->registerDeprecatedAlias('TempManager', TempManager::class);
858
-		$this->registerAlias(ITempManager::class, TempManager::class);
859
-
860
-		$this->registerService(AppManager::class, function (Server $c) {
861
-			return new \OC\App\AppManager(
862
-				$c->getUserSession(),
863
-				$c->getConfig(),
864
-				$c->query(\OC\AppConfig::class),
865
-				$c->getGroupManager(),
866
-				$c->getMemCacheFactory(),
867
-				$c->getEventDispatcher(),
868
-				$c->getLogger()
869
-			);
870
-		});
871
-		$this->registerDeprecatedAlias('AppManager', AppManager::class);
872
-		$this->registerAlias(IAppManager::class, AppManager::class);
873
-
874
-		$this->registerService(IDateTimeZone::class, function (Server $c) {
875
-			return new DateTimeZone(
876
-				$c->getConfig(),
877
-				$c->getSession()
878
-			);
879
-		});
880
-		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
881
-
882
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
883
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
884
-
885
-			return new DateTimeFormatter(
886
-				$c->getDateTimeZone()->getTimeZone(),
887
-				$c->getL10N('lib', $language)
888
-			);
889
-		});
890
-		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
891
-
892
-		$this->registerService(IUserMountCache::class, function (Server $c) {
893
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
894
-			$listener = new UserMountCacheListener($mountCache);
895
-			$listener->listen($c->getUserManager());
896
-			return $mountCache;
897
-		});
898
-		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
899
-
900
-		$this->registerService(IMountProviderCollection::class, function (Server $c) {
901
-			$loader = \OC\Files\Filesystem::getLoader();
902
-			$mountCache = $c->query(IUserMountCache::class);
903
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
904
-
905
-			// builtin providers
906
-
907
-			$config = $c->getConfig();
908
-			$logger = $c->getLogger();
909
-			$manager->registerProvider(new CacheMountProvider($config));
910
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
911
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
912
-			$manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
913
-
914
-			return $manager;
915
-		});
916
-		$this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
917
-
918
-		$this->registerService('IniWrapper', function ($c) {
919
-			return new IniGetWrapper();
920
-		});
921
-		$this->registerService('AsyncCommandBus', function (Server $c) {
922
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
923
-			if ($busClass) {
924
-				[$app, $class] = explode('::', $busClass, 2);
925
-				if ($c->getAppManager()->isInstalled($app)) {
926
-					\OC_App::loadApp($app);
927
-					return $c->query($class);
928
-				} else {
929
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
930
-				}
931
-			} else {
932
-				$jobList = $c->getJobList();
933
-				return new CronBus($jobList);
934
-			}
935
-		});
936
-		$this->registerAlias(IBus::class, 'AsyncCommandBus');
937
-		$this->registerService('TrustedDomainHelper', function ($c) {
938
-			return new TrustedDomainHelper($this->getConfig());
939
-		});
940
-		$this->registerService(Throttler::class, function (Server $c) {
941
-			return new Throttler(
942
-				$c->getDatabaseConnection(),
943
-				new TimeFactory(),
944
-				$c->getLogger(),
945
-				$c->getConfig()
946
-			);
947
-		});
948
-		$this->registerDeprecatedAlias('Throttler', Throttler::class);
949
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
950
-			// IConfig and IAppManager requires a working database. This code
951
-			// might however be called when ownCloud is not yet setup.
952
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
953
-				$config = $c->getConfig();
954
-				$appManager = $c->getAppManager();
955
-			} else {
956
-				$config = null;
957
-				$appManager = null;
958
-			}
959
-
960
-			return new Checker(
961
-				new EnvironmentHelper(),
962
-				new FileAccessHelper(),
963
-				new AppLocator(),
964
-				$config,
965
-				$c->getMemCacheFactory(),
966
-				$appManager,
967
-				$c->getTempManager(),
968
-				$c->getMimeTypeDetector()
969
-			);
970
-		});
971
-		$this->registerService(\OCP\IRequest::class, function ($c) {
972
-			if (isset($this['urlParams'])) {
973
-				$urlParams = $this['urlParams'];
974
-			} else {
975
-				$urlParams = [];
976
-			}
977
-
978
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
979
-				&& in_array('fakeinput', stream_get_wrappers())
980
-			) {
981
-				$stream = 'fakeinput://data';
982
-			} else {
983
-				$stream = 'php://input';
984
-			}
985
-
986
-			return new Request(
987
-				[
988
-					'get' => $_GET,
989
-					'post' => $_POST,
990
-					'files' => $_FILES,
991
-					'server' => $_SERVER,
992
-					'env' => $_ENV,
993
-					'cookies' => $_COOKIE,
994
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
995
-						? $_SERVER['REQUEST_METHOD']
996
-						: '',
997
-					'urlParams' => $urlParams,
998
-				],
999
-				$this->getSecureRandom(),
1000
-				$this->getConfig(),
1001
-				$this->getCsrfTokenManager(),
1002
-				$stream
1003
-			);
1004
-		});
1005
-		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
1006
-
1007
-		$this->registerService(IMailer::class, function (Server $c) {
1008
-			return new Mailer(
1009
-				$c->getConfig(),
1010
-				$c->getLogger(),
1011
-				$c->query(Defaults::class),
1012
-				$c->getURLGenerator(),
1013
-				$c->getL10N('lib'),
1014
-				$c->query(IEventDispatcher::class),
1015
-				$c->getL10NFactory()
1016
-			);
1017
-		});
1018
-		$this->registerDeprecatedAlias('Mailer', IMailer::class);
1019
-
1020
-		$this->registerService('LDAPProvider', function (Server $c) {
1021
-			$config = $c->getConfig();
1022
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1023
-			if (is_null($factoryClass)) {
1024
-				throw new \Exception('ldapProviderFactory not set');
1025
-			}
1026
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1027
-			$factory = new $factoryClass($this);
1028
-			return $factory->getLDAPProvider();
1029
-		});
1030
-		$this->registerService(ILockingProvider::class, function (Server $c) {
1031
-			$ini = $c->getIniWrapper();
1032
-			$config = $c->getConfig();
1033
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1034
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1035
-				/** @var \OC\Memcache\Factory $memcacheFactory */
1036
-				$memcacheFactory = $c->getMemCacheFactory();
1037
-				$memcache = $memcacheFactory->createLocking('lock');
1038
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
1039
-					return new MemcacheLockingProvider($memcache, $ttl);
1040
-				}
1041
-				return new DBLockingProvider(
1042
-					$c->getDatabaseConnection(),
1043
-					$c->getLogger(),
1044
-					new TimeFactory(),
1045
-					$ttl,
1046
-					!\OC::$CLI
1047
-				);
1048
-			}
1049
-			return new NoopLockingProvider();
1050
-		});
1051
-		$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1052
-
1053
-		$this->registerService(IMountManager::class, function () {
1054
-			return new \OC\Files\Mount\Manager();
1055
-		});
1056
-		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1057
-
1058
-		$this->registerService(IMimeTypeDetector::class, function (Server $c) {
1059
-			return new \OC\Files\Type\Detection(
1060
-				$c->getURLGenerator(),
1061
-				$c->getLogger(),
1062
-				\OC::$configDir,
1063
-				\OC::$SERVERROOT . '/resources/config/'
1064
-			);
1065
-		});
1066
-		$this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1067
-
1068
-		$this->registerService(IMimeTypeLoader::class, function (Server $c) {
1069
-			return new \OC\Files\Type\Loader(
1070
-				$c->getDatabaseConnection()
1071
-			);
1072
-		});
1073
-		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1074
-		$this->registerService(BundleFetcher::class, function () {
1075
-			return new BundleFetcher($this->getL10N('lib'));
1076
-		});
1077
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
1078
-			return new Manager(
1079
-				$c->query(IValidator::class),
1080
-				$c->getLogger()
1081
-			);
1082
-		});
1083
-		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1084
-
1085
-		$this->registerService(CapabilitiesManager::class, function (Server $c) {
1086
-			$manager = new CapabilitiesManager($c->getLogger());
1087
-			$manager->registerCapability(function () use ($c) {
1088
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
1089
-			});
1090
-			$manager->registerCapability(function () use ($c) {
1091
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
1092
-			});
1093
-			return $manager;
1094
-		});
1095
-		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1096
-
1097
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1098
-			$config = $c->getConfig();
1099
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1100
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1101
-			$factory = new $factoryClass($this);
1102
-			$manager = $factory->getManager();
1103
-
1104
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1105
-				$manager = $c->getUserManager();
1106
-				$user = $manager->get($id);
1107
-				if (is_null($user)) {
1108
-					$l = $c->getL10N('core');
1109
-					$displayName = $l->t('Unknown user');
1110
-				} else {
1111
-					$displayName = $user->getDisplayName();
1112
-				}
1113
-				return $displayName;
1114
-			});
1115
-
1116
-			return $manager;
1117
-		});
1118
-		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1119
-
1120
-		$this->registerService('ThemingDefaults', function (Server $c) {
1121
-			/*
248
+    /** @var string */
249
+    private $webRoot;
250
+
251
+    /**
252
+     * @param string $webRoot
253
+     * @param \OC\Config $config
254
+     */
255
+    public function __construct($webRoot, \OC\Config $config) {
256
+        parent::__construct();
257
+        $this->webRoot = $webRoot;
258
+
259
+        // To find out if we are running from CLI or not
260
+        $this->registerParameter('isCLI', \OC::$CLI);
261
+
262
+        $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
263
+            return $c;
264
+        });
265
+        $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
266
+            return $c;
267
+        });
268
+
269
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
270
+        $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
271
+
272
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
273
+        $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
274
+
275
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
276
+        $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
277
+
278
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
279
+        $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
280
+
281
+        $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
282
+
283
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
284
+
285
+
286
+        $this->registerService(IPreview::class, function (Server $c) {
287
+            return new PreviewManager(
288
+                $c->getConfig(),
289
+                $c->getRootFolder(),
290
+                new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig(), 'preview'),
291
+                $c->getEventDispatcher(),
292
+                $c->getGeneratorHelper(),
293
+                $c->getSession()->get('user_id')
294
+            );
295
+        });
296
+        $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
297
+
298
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
299
+            return new \OC\Preview\Watcher(
300
+                new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig(), 'preview')
301
+            );
302
+        });
303
+
304
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
305
+            $view = new View();
306
+            $util = new Encryption\Util(
307
+                $view,
308
+                $c->getUserManager(),
309
+                $c->getGroupManager(),
310
+                $c->getConfig()
311
+            );
312
+            return new Encryption\Manager(
313
+                $c->getConfig(),
314
+                $c->getLogger(),
315
+                $c->getL10N('core'),
316
+                new View(),
317
+                $util,
318
+                new ArrayCache()
319
+            );
320
+        });
321
+        $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
322
+
323
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
324
+            $util = new Encryption\Util(
325
+                new View(),
326
+                $c->getUserManager(),
327
+                $c->getGroupManager(),
328
+                $c->getConfig()
329
+            );
330
+            return new Encryption\File(
331
+                $util,
332
+                $c->getRootFolder(),
333
+                $c->getShareManager()
334
+            );
335
+        });
336
+
337
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
338
+            $view = new View();
339
+            $util = new Encryption\Util(
340
+                $view,
341
+                $c->getUserManager(),
342
+                $c->getGroupManager(),
343
+                $c->getConfig()
344
+            );
345
+
346
+            return new Encryption\Keys\Storage($view, $util);
347
+        });
348
+        $this->registerService('TagMapper', function (Server $c) {
349
+            return new TagMapper($c->getDatabaseConnection());
350
+        });
351
+
352
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
353
+            $tagMapper = $c->query('TagMapper');
354
+            return new TagManager($tagMapper, $c->getUserSession());
355
+        });
356
+        $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
357
+
358
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
359
+            $config = $c->getConfig();
360
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
361
+            return new $factoryClass($this);
362
+        });
363
+        $this->registerService(ISystemTagManager::class, function (Server $c) {
364
+            return $c->query('SystemTagManagerFactory')->getManager();
365
+        });
366
+        $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
367
+
368
+        $this->registerService(ISystemTagObjectMapper::class, function (Server $c) {
369
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
370
+        });
371
+        $this->registerService('RootFolder', function (Server $c) {
372
+            $manager = \OC\Files\Filesystem::getMountManager(null);
373
+            $view = new View();
374
+            $root = new Root(
375
+                $manager,
376
+                $view,
377
+                null,
378
+                $c->getUserMountCache(),
379
+                $this->getLogger(),
380
+                $this->getUserManager()
381
+            );
382
+
383
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
384
+            $previewConnector->connectWatcher();
385
+
386
+            return $root;
387
+        });
388
+        $this->registerService(HookConnector::class, function (Server $c) {
389
+            return new HookConnector(
390
+                $c->query(IRootFolder::class),
391
+                new View(),
392
+                $c->query(\OC\EventDispatcher\SymfonyAdapter::class),
393
+                $c->query(IEventDispatcher::class)
394
+            );
395
+        });
396
+
397
+        $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
398
+
399
+        $this->registerService(IRootFolder::class, function (Server $c) {
400
+            return new LazyRoot(function () use ($c) {
401
+                return $c->query('RootFolder');
402
+            });
403
+        });
404
+        $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
405
+
406
+        $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
407
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
408
+
409
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
410
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
411
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
412
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
413
+
414
+                /** @var IEventDispatcher $dispatcher */
415
+                $dispatcher = $this->query(IEventDispatcher::class);
416
+                $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
417
+            });
418
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
419
+                \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]);
420
+
421
+                /** @var IEventDispatcher $dispatcher */
422
+                $dispatcher = $this->query(IEventDispatcher::class);
423
+                $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
424
+            });
425
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
426
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
427
+
428
+                /** @var IEventDispatcher $dispatcher */
429
+                $dispatcher = $this->query(IEventDispatcher::class);
430
+                $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
431
+            });
432
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
433
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
434
+
435
+                /** @var IEventDispatcher $dispatcher */
436
+                $dispatcher = $this->query(IEventDispatcher::class);
437
+                $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
438
+            });
439
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
440
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
441
+
442
+                /** @var IEventDispatcher $dispatcher */
443
+                $dispatcher = $this->query(IEventDispatcher::class);
444
+                $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
445
+            });
446
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
447
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
448
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
449
+                \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
450
+
451
+                /** @var IEventDispatcher $dispatcher */
452
+                $dispatcher = $this->query(IEventDispatcher::class);
453
+                $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
454
+            });
455
+            $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
456
+                /** @var IEventDispatcher $dispatcher */
457
+                $dispatcher = $this->query(IEventDispatcher::class);
458
+                $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
459
+            });
460
+            $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
461
+                /** @var IEventDispatcher $dispatcher */
462
+                $dispatcher = $this->query(IEventDispatcher::class);
463
+                $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
464
+            });
465
+            return $groupManager;
466
+        });
467
+        $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
468
+
469
+        $this->registerService(Store::class, function (Server $c) {
470
+            $session = $c->getSession();
471
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
472
+                $tokenProvider = $c->query(IProvider::class);
473
+            } else {
474
+                $tokenProvider = null;
475
+            }
476
+            $logger = $c->getLogger();
477
+            return new Store($session, $logger, $tokenProvider);
478
+        });
479
+        $this->registerAlias(IStore::class, Store::class);
480
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
481
+            $dbConnection = $c->getDatabaseConnection();
482
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
483
+        });
484
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
485
+
486
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
487
+            $manager = $c->getUserManager();
488
+            $session = new \OC\Session\Memory('');
489
+            $timeFactory = new TimeFactory();
490
+            // Token providers might require a working database. This code
491
+            // might however be called when ownCloud is not yet setup.
492
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
493
+                $defaultTokenProvider = $c->query(IProvider::class);
494
+            } else {
495
+                $defaultTokenProvider = null;
496
+            }
497
+
498
+            $legacyDispatcher = $c->getEventDispatcher();
499
+
500
+            $userSession = new \OC\User\Session(
501
+                $manager,
502
+                $session,
503
+                $timeFactory,
504
+                $defaultTokenProvider,
505
+                $c->getConfig(),
506
+                $c->getSecureRandom(),
507
+                $c->getLockdownManager(),
508
+                $c->getLogger(),
509
+                $c->query(IEventDispatcher::class)
510
+            );
511
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
512
+                \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
513
+
514
+                /** @var IEventDispatcher $dispatcher */
515
+                $dispatcher = $this->query(IEventDispatcher::class);
516
+                $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password));
517
+            });
518
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
519
+                /** @var $user \OC\User\User */
520
+                \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
521
+
522
+                /** @var IEventDispatcher $dispatcher */
523
+                $dispatcher = $this->query(IEventDispatcher::class);
524
+                $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
525
+            });
526
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
527
+                /** @var $user \OC\User\User */
528
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
529
+                $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
530
+
531
+                /** @var IEventDispatcher $dispatcher */
532
+                $dispatcher = $this->query(IEventDispatcher::class);
533
+                $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user));
534
+            });
535
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
536
+                /** @var $user \OC\User\User */
537
+                \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
538
+
539
+                /** @var IEventDispatcher $dispatcher */
540
+                $dispatcher = $this->query(IEventDispatcher::class);
541
+                $dispatcher->dispatchTyped(new UserDeletedEvent($user));
542
+            });
543
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
544
+                /** @var $user \OC\User\User */
545
+                \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
546
+
547
+                /** @var IEventDispatcher $dispatcher */
548
+                $dispatcher = $this->query(IEventDispatcher::class);
549
+                $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
550
+            });
551
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
552
+                /** @var $user \OC\User\User */
553
+                \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
554
+
555
+                /** @var IEventDispatcher $dispatcher */
556
+                $dispatcher = $this->query(IEventDispatcher::class);
557
+                $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
558
+            });
559
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
560
+                \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
561
+
562
+                /** @var IEventDispatcher $dispatcher */
563
+                $dispatcher = $this->query(IEventDispatcher::class);
564
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
565
+            });
566
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
567
+                /** @var $user \OC\User\User */
568
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
569
+
570
+                /** @var IEventDispatcher $dispatcher */
571
+                $dispatcher = $this->query(IEventDispatcher::class);
572
+                $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin));
573
+            });
574
+            $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
575
+                /** @var IEventDispatcher $dispatcher */
576
+                $dispatcher = $this->query(IEventDispatcher::class);
577
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
578
+            });
579
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
580
+                /** @var $user \OC\User\User */
581
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
582
+
583
+                /** @var IEventDispatcher $dispatcher */
584
+                $dispatcher = $this->query(IEventDispatcher::class);
585
+                $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
586
+            });
587
+            $userSession->listen('\OC\User', 'logout', function ($user) {
588
+                \OC_Hook::emit('OC_User', 'logout', []);
589
+
590
+                /** @var IEventDispatcher $dispatcher */
591
+                $dispatcher = $this->query(IEventDispatcher::class);
592
+                $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
593
+            });
594
+            $userSession->listen('\OC\User', 'postLogout', function ($user) {
595
+                /** @var IEventDispatcher $dispatcher */
596
+                $dispatcher = $this->query(IEventDispatcher::class);
597
+                $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
598
+            });
599
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
600
+                /** @var $user \OC\User\User */
601
+                \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
602
+
603
+                /** @var IEventDispatcher $dispatcher */
604
+                $dispatcher = $this->query(IEventDispatcher::class);
605
+                $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
606
+            });
607
+            return $userSession;
608
+        });
609
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
610
+        $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
611
+
612
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
613
+
614
+        $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
615
+        $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
616
+
617
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
618
+            return new \OC\AllConfig(
619
+                $c->getSystemConfig()
620
+            );
621
+        });
622
+        $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
623
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
624
+
625
+        $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
626
+            return new \OC\SystemConfig($config);
627
+        });
628
+        $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
629
+
630
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
631
+            return new \OC\AppConfig($c->getDatabaseConnection());
632
+        });
633
+        $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
634
+        $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
635
+
636
+        $this->registerService(IFactory::class, function (Server $c) {
637
+            return new \OC\L10N\Factory(
638
+                $c->getConfig(),
639
+                $c->getRequest(),
640
+                $c->getUserSession(),
641
+                \OC::$SERVERROOT
642
+            );
643
+        });
644
+        $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
645
+
646
+        $this->registerService(IURLGenerator::class, function (Server $c) {
647
+            $config = $c->getConfig();
648
+            $cacheFactory = $c->getMemCacheFactory();
649
+            $request = $c->getRequest();
650
+            return new \OC\URLGenerator(
651
+                $config,
652
+                $cacheFactory,
653
+                $request
654
+            );
655
+        });
656
+        $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
657
+
658
+        $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
659
+        $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
660
+
661
+        $this->registerService(ICache::class, function ($c) {
662
+            return new Cache\File();
663
+        });
664
+        $this->registerDeprecatedAlias('UserCache', ICache::class);
665
+
666
+        $this->registerService(Factory::class, function (Server $c) {
667
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
668
+                ArrayCache::class,
669
+                ArrayCache::class,
670
+                ArrayCache::class
671
+            );
672
+            $config = $c->getConfig();
673
+
674
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
675
+                $v = \OC_App::getAppVersions();
676
+                $v['core'] = implode(',', \OC_Util::getVersion());
677
+                $version = implode(',', $v);
678
+                $instanceId = \OC_Util::getInstanceId();
679
+                $path = \OC::$SERVERROOT;
680
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
681
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
682
+                    $config->getSystemValue('memcache.local', null),
683
+                    $config->getSystemValue('memcache.distributed', null),
684
+                    $config->getSystemValue('memcache.locking', null)
685
+                );
686
+            }
687
+            return $arrayCacheFactory;
688
+        });
689
+        $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
690
+        $this->registerAlias(ICacheFactory::class, Factory::class);
691
+
692
+        $this->registerService('RedisFactory', function (Server $c) {
693
+            $systemConfig = $c->getSystemConfig();
694
+            return new RedisFactory($systemConfig);
695
+        });
696
+
697
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
698
+            return new \OC\Activity\Manager(
699
+                $c->getRequest(),
700
+                $c->getUserSession(),
701
+                $c->getConfig(),
702
+                $c->query(IValidator::class)
703
+            );
704
+        });
705
+        $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
706
+
707
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
708
+            return new \OC\Activity\EventMerger(
709
+                $c->getL10N('lib')
710
+            );
711
+        });
712
+        $this->registerAlias(IValidator::class, Validator::class);
713
+
714
+        $this->registerService(AvatarManager::class, function (Server $c) {
715
+            return new AvatarManager(
716
+                $c->query(\OC\User\Manager::class),
717
+                $c->getAppDataDir('avatar'),
718
+                $c->getL10N('lib'),
719
+                $c->getLogger(),
720
+                $c->getConfig()
721
+            );
722
+        });
723
+        $this->registerAlias(IAvatarManager::class, AvatarManager::class);
724
+        $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
725
+
726
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
727
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
728
+
729
+        $this->registerService(\OC\Log::class, function (Server $c) {
730
+            $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file');
731
+            $factory = new LogFactory($c, $this->getSystemConfig());
732
+            $logger = $factory->get($logType);
733
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
734
+
735
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
736
+        });
737
+        $this->registerAlias(ILogger::class, \OC\Log::class);
738
+        $this->registerDeprecatedAlias('Logger', \OC\Log::class);
739
+        // PSR-3 logger
740
+        $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
741
+
742
+        $this->registerService(ILogFactory::class, function (Server $c) {
743
+            return new LogFactory($c, $this->getSystemConfig());
744
+        });
745
+
746
+        $this->registerService(IJobList::class, function (Server $c) {
747
+            $config = $c->getConfig();
748
+            return new \OC\BackgroundJob\JobList(
749
+                $c->getDatabaseConnection(),
750
+                $config,
751
+                new TimeFactory()
752
+            );
753
+        });
754
+        $this->registerDeprecatedAlias('JobList', IJobList::class);
755
+
756
+        $this->registerService(IRouter::class, function (Server $c) {
757
+            $cacheFactory = $c->getMemCacheFactory();
758
+            $logger = $c->getLogger();
759
+            if ($cacheFactory->isLocalCacheAvailable()) {
760
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
761
+            } else {
762
+                $router = new \OC\Route\Router($logger);
763
+            }
764
+            return $router;
765
+        });
766
+        $this->registerDeprecatedAlias('Router', IRouter::class);
767
+
768
+        $this->registerService(ISearch::class, function ($c) {
769
+            return new Search();
770
+        });
771
+        $this->registerDeprecatedAlias('Search', ISearch::class);
772
+
773
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
774
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
775
+                $this->getMemCacheFactory(),
776
+                new \OC\AppFramework\Utility\TimeFactory()
777
+            );
778
+        });
779
+
780
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
781
+            return new SecureRandom();
782
+        });
783
+        $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
784
+
785
+        $this->registerService(ICrypto::class, function (Server $c) {
786
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
787
+        });
788
+        $this->registerDeprecatedAlias('Crypto', ICrypto::class);
789
+
790
+        $this->registerService(IHasher::class, function (Server $c) {
791
+            return new Hasher($c->getConfig());
792
+        });
793
+        $this->registerDeprecatedAlias('Hasher', IHasher::class);
794
+
795
+        $this->registerService(ICredentialsManager::class, function (Server $c) {
796
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
797
+        });
798
+        $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
799
+
800
+        $this->registerService(IDBConnection::class, function (Server $c) {
801
+            $systemConfig = $c->getSystemConfig();
802
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
803
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
804
+            if (!$factory->isValidType($type)) {
805
+                throw new \OC\DatabaseException('Invalid database type');
806
+            }
807
+            $connectionParams = $factory->createConnectionParams();
808
+            $connection = $factory->getConnection($type, $connectionParams);
809
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
810
+            return $connection;
811
+        });
812
+        $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
813
+
814
+
815
+        $this->registerService(IClientService::class, function (Server $c) {
816
+            $user = \OC_User::getUser();
817
+            $uid = $user ? $user : null;
818
+            return new ClientService(
819
+                $c->getConfig(),
820
+                $c->getLogger(),
821
+                new \OC\Security\CertificateManager(
822
+                    $uid,
823
+                    new View(),
824
+                    $c->getConfig(),
825
+                    $c->getLogger(),
826
+                    $c->getSecureRandom()
827
+                )
828
+            );
829
+        });
830
+        $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
831
+        $this->registerService(IEventLogger::class, function (Server $c) {
832
+            $eventLogger = new EventLogger();
833
+            if ($c->getSystemConfig()->getValue('debug', false)) {
834
+                // In debug mode, module is being activated by default
835
+                $eventLogger->activate();
836
+            }
837
+            return $eventLogger;
838
+        });
839
+        $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
840
+
841
+        $this->registerService(IQueryLogger::class, function (Server $c) {
842
+            $queryLogger = new QueryLogger();
843
+            if ($c->getSystemConfig()->getValue('debug', false)) {
844
+                // In debug mode, module is being activated by default
845
+                $queryLogger->activate();
846
+            }
847
+            return $queryLogger;
848
+        });
849
+        $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
850
+
851
+        $this->registerService(TempManager::class, function (Server $c) {
852
+            return new TempManager(
853
+                $c->getLogger(),
854
+                $c->getConfig()
855
+            );
856
+        });
857
+        $this->registerDeprecatedAlias('TempManager', TempManager::class);
858
+        $this->registerAlias(ITempManager::class, TempManager::class);
859
+
860
+        $this->registerService(AppManager::class, function (Server $c) {
861
+            return new \OC\App\AppManager(
862
+                $c->getUserSession(),
863
+                $c->getConfig(),
864
+                $c->query(\OC\AppConfig::class),
865
+                $c->getGroupManager(),
866
+                $c->getMemCacheFactory(),
867
+                $c->getEventDispatcher(),
868
+                $c->getLogger()
869
+            );
870
+        });
871
+        $this->registerDeprecatedAlias('AppManager', AppManager::class);
872
+        $this->registerAlias(IAppManager::class, AppManager::class);
873
+
874
+        $this->registerService(IDateTimeZone::class, function (Server $c) {
875
+            return new DateTimeZone(
876
+                $c->getConfig(),
877
+                $c->getSession()
878
+            );
879
+        });
880
+        $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
881
+
882
+        $this->registerService(IDateTimeFormatter::class, function (Server $c) {
883
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
884
+
885
+            return new DateTimeFormatter(
886
+                $c->getDateTimeZone()->getTimeZone(),
887
+                $c->getL10N('lib', $language)
888
+            );
889
+        });
890
+        $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
891
+
892
+        $this->registerService(IUserMountCache::class, function (Server $c) {
893
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
894
+            $listener = new UserMountCacheListener($mountCache);
895
+            $listener->listen($c->getUserManager());
896
+            return $mountCache;
897
+        });
898
+        $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
899
+
900
+        $this->registerService(IMountProviderCollection::class, function (Server $c) {
901
+            $loader = \OC\Files\Filesystem::getLoader();
902
+            $mountCache = $c->query(IUserMountCache::class);
903
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
904
+
905
+            // builtin providers
906
+
907
+            $config = $c->getConfig();
908
+            $logger = $c->getLogger();
909
+            $manager->registerProvider(new CacheMountProvider($config));
910
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
911
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
912
+            $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
913
+
914
+            return $manager;
915
+        });
916
+        $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
917
+
918
+        $this->registerService('IniWrapper', function ($c) {
919
+            return new IniGetWrapper();
920
+        });
921
+        $this->registerService('AsyncCommandBus', function (Server $c) {
922
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
923
+            if ($busClass) {
924
+                [$app, $class] = explode('::', $busClass, 2);
925
+                if ($c->getAppManager()->isInstalled($app)) {
926
+                    \OC_App::loadApp($app);
927
+                    return $c->query($class);
928
+                } else {
929
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
930
+                }
931
+            } else {
932
+                $jobList = $c->getJobList();
933
+                return new CronBus($jobList);
934
+            }
935
+        });
936
+        $this->registerAlias(IBus::class, 'AsyncCommandBus');
937
+        $this->registerService('TrustedDomainHelper', function ($c) {
938
+            return new TrustedDomainHelper($this->getConfig());
939
+        });
940
+        $this->registerService(Throttler::class, function (Server $c) {
941
+            return new Throttler(
942
+                $c->getDatabaseConnection(),
943
+                new TimeFactory(),
944
+                $c->getLogger(),
945
+                $c->getConfig()
946
+            );
947
+        });
948
+        $this->registerDeprecatedAlias('Throttler', Throttler::class);
949
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
950
+            // IConfig and IAppManager requires a working database. This code
951
+            // might however be called when ownCloud is not yet setup.
952
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
953
+                $config = $c->getConfig();
954
+                $appManager = $c->getAppManager();
955
+            } else {
956
+                $config = null;
957
+                $appManager = null;
958
+            }
959
+
960
+            return new Checker(
961
+                new EnvironmentHelper(),
962
+                new FileAccessHelper(),
963
+                new AppLocator(),
964
+                $config,
965
+                $c->getMemCacheFactory(),
966
+                $appManager,
967
+                $c->getTempManager(),
968
+                $c->getMimeTypeDetector()
969
+            );
970
+        });
971
+        $this->registerService(\OCP\IRequest::class, function ($c) {
972
+            if (isset($this['urlParams'])) {
973
+                $urlParams = $this['urlParams'];
974
+            } else {
975
+                $urlParams = [];
976
+            }
977
+
978
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
979
+                && in_array('fakeinput', stream_get_wrappers())
980
+            ) {
981
+                $stream = 'fakeinput://data';
982
+            } else {
983
+                $stream = 'php://input';
984
+            }
985
+
986
+            return new Request(
987
+                [
988
+                    'get' => $_GET,
989
+                    'post' => $_POST,
990
+                    'files' => $_FILES,
991
+                    'server' => $_SERVER,
992
+                    'env' => $_ENV,
993
+                    'cookies' => $_COOKIE,
994
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
995
+                        ? $_SERVER['REQUEST_METHOD']
996
+                        : '',
997
+                    'urlParams' => $urlParams,
998
+                ],
999
+                $this->getSecureRandom(),
1000
+                $this->getConfig(),
1001
+                $this->getCsrfTokenManager(),
1002
+                $stream
1003
+            );
1004
+        });
1005
+        $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
1006
+
1007
+        $this->registerService(IMailer::class, function (Server $c) {
1008
+            return new Mailer(
1009
+                $c->getConfig(),
1010
+                $c->getLogger(),
1011
+                $c->query(Defaults::class),
1012
+                $c->getURLGenerator(),
1013
+                $c->getL10N('lib'),
1014
+                $c->query(IEventDispatcher::class),
1015
+                $c->getL10NFactory()
1016
+            );
1017
+        });
1018
+        $this->registerDeprecatedAlias('Mailer', IMailer::class);
1019
+
1020
+        $this->registerService('LDAPProvider', function (Server $c) {
1021
+            $config = $c->getConfig();
1022
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1023
+            if (is_null($factoryClass)) {
1024
+                throw new \Exception('ldapProviderFactory not set');
1025
+            }
1026
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1027
+            $factory = new $factoryClass($this);
1028
+            return $factory->getLDAPProvider();
1029
+        });
1030
+        $this->registerService(ILockingProvider::class, function (Server $c) {
1031
+            $ini = $c->getIniWrapper();
1032
+            $config = $c->getConfig();
1033
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1034
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1035
+                /** @var \OC\Memcache\Factory $memcacheFactory */
1036
+                $memcacheFactory = $c->getMemCacheFactory();
1037
+                $memcache = $memcacheFactory->createLocking('lock');
1038
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
1039
+                    return new MemcacheLockingProvider($memcache, $ttl);
1040
+                }
1041
+                return new DBLockingProvider(
1042
+                    $c->getDatabaseConnection(),
1043
+                    $c->getLogger(),
1044
+                    new TimeFactory(),
1045
+                    $ttl,
1046
+                    !\OC::$CLI
1047
+                );
1048
+            }
1049
+            return new NoopLockingProvider();
1050
+        });
1051
+        $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1052
+
1053
+        $this->registerService(IMountManager::class, function () {
1054
+            return new \OC\Files\Mount\Manager();
1055
+        });
1056
+        $this->registerDeprecatedAlias('MountManager', IMountManager::class);
1057
+
1058
+        $this->registerService(IMimeTypeDetector::class, function (Server $c) {
1059
+            return new \OC\Files\Type\Detection(
1060
+                $c->getURLGenerator(),
1061
+                $c->getLogger(),
1062
+                \OC::$configDir,
1063
+                \OC::$SERVERROOT . '/resources/config/'
1064
+            );
1065
+        });
1066
+        $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1067
+
1068
+        $this->registerService(IMimeTypeLoader::class, function (Server $c) {
1069
+            return new \OC\Files\Type\Loader(
1070
+                $c->getDatabaseConnection()
1071
+            );
1072
+        });
1073
+        $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1074
+        $this->registerService(BundleFetcher::class, function () {
1075
+            return new BundleFetcher($this->getL10N('lib'));
1076
+        });
1077
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
1078
+            return new Manager(
1079
+                $c->query(IValidator::class),
1080
+                $c->getLogger()
1081
+            );
1082
+        });
1083
+        $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1084
+
1085
+        $this->registerService(CapabilitiesManager::class, function (Server $c) {
1086
+            $manager = new CapabilitiesManager($c->getLogger());
1087
+            $manager->registerCapability(function () use ($c) {
1088
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
1089
+            });
1090
+            $manager->registerCapability(function () use ($c) {
1091
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
1092
+            });
1093
+            return $manager;
1094
+        });
1095
+        $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1096
+
1097
+        $this->registerService(ICommentsManager::class, function (Server $c) {
1098
+            $config = $c->getConfig();
1099
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1100
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
1101
+            $factory = new $factoryClass($this);
1102
+            $manager = $factory->getManager();
1103
+
1104
+            $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1105
+                $manager = $c->getUserManager();
1106
+                $user = $manager->get($id);
1107
+                if (is_null($user)) {
1108
+                    $l = $c->getL10N('core');
1109
+                    $displayName = $l->t('Unknown user');
1110
+                } else {
1111
+                    $displayName = $user->getDisplayName();
1112
+                }
1113
+                return $displayName;
1114
+            });
1115
+
1116
+            return $manager;
1117
+        });
1118
+        $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1119
+
1120
+        $this->registerService('ThemingDefaults', function (Server $c) {
1121
+            /*
1122 1122
 			 * Dark magic for autoloader.
1123 1123
 			 * If we do a class_exists it will try to load the class which will
1124 1124
 			 * make composer cache the result. Resulting in errors when enabling
1125 1125
 			 * the theming app.
1126 1126
 			 */
1127
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1128
-			if (isset($prefixes['OCA\\Theming\\'])) {
1129
-				$classExists = true;
1130
-			} else {
1131
-				$classExists = false;
1132
-			}
1133
-
1134
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1135
-				return new ThemingDefaults(
1136
-					$c->getConfig(),
1137
-					$c->getL10N('theming'),
1138
-					$c->getURLGenerator(),
1139
-					$c->getMemCacheFactory(),
1140
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
1141
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
1142
-					$c->getAppManager(),
1143
-					$c->getNavigationManager()
1144
-				);
1145
-			}
1146
-			return new \OC_Defaults();
1147
-		});
1148
-		$this->registerService(SCSSCacher::class, function (Server $c) {
1149
-			return new SCSSCacher(
1150
-				$c->getLogger(),
1151
-				$c->query(\OC\Files\AppData\Factory::class),
1152
-				$c->getURLGenerator(),
1153
-				$c->getConfig(),
1154
-				$c->getThemingDefaults(),
1155
-				\OC::$SERVERROOT,
1156
-				$this->getMemCacheFactory(),
1157
-				$c->query(IconsCacher::class),
1158
-				new TimeFactory()
1159
-			);
1160
-		});
1161
-		$this->registerService(JSCombiner::class, function (Server $c) {
1162
-			return new JSCombiner(
1163
-				$c->getAppDataDir('js'),
1164
-				$c->getURLGenerator(),
1165
-				$this->getMemCacheFactory(),
1166
-				$c->getSystemConfig(),
1167
-				$c->getLogger()
1168
-			);
1169
-		});
1170
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1171
-		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1172
-		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1173
-
1174
-		$this->registerService('CryptoWrapper', function (Server $c) {
1175
-			// FIXME: Instantiiated here due to cyclic dependency
1176
-			$request = new Request(
1177
-				[
1178
-					'get' => $_GET,
1179
-					'post' => $_POST,
1180
-					'files' => $_FILES,
1181
-					'server' => $_SERVER,
1182
-					'env' => $_ENV,
1183
-					'cookies' => $_COOKIE,
1184
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1185
-						? $_SERVER['REQUEST_METHOD']
1186
-						: null,
1187
-				],
1188
-				$c->getSecureRandom(),
1189
-				$c->getConfig()
1190
-			);
1191
-
1192
-			return new CryptoWrapper(
1193
-				$c->getConfig(),
1194
-				$c->getCrypto(),
1195
-				$c->getSecureRandom(),
1196
-				$request
1197
-			);
1198
-		});
1199
-		$this->registerService(CsrfTokenManager::class, function (Server $c) {
1200
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1201
-
1202
-			return new CsrfTokenManager(
1203
-				$tokenGenerator,
1204
-				$c->query(SessionStorage::class)
1205
-			);
1206
-		});
1207
-		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1208
-		$this->registerService(SessionStorage::class, function (Server $c) {
1209
-			return new SessionStorage($c->getSession());
1210
-		});
1211
-		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1212
-		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1213
-
1214
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1215
-			return new ContentSecurityPolicyNonceManager(
1216
-				$c->getCsrfTokenManager(),
1217
-				$c->getRequest()
1218
-			);
1219
-		});
1220
-
1221
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1222
-			$config = $c->getConfig();
1223
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1224
-			/** @var \OCP\Share\IProviderFactory $factory */
1225
-			$factory = new $factoryClass($this);
1226
-
1227
-			$manager = new \OC\Share20\Manager(
1228
-				$c->getLogger(),
1229
-				$c->getConfig(),
1230
-				$c->getSecureRandom(),
1231
-				$c->getHasher(),
1232
-				$c->getMountManager(),
1233
-				$c->getGroupManager(),
1234
-				$c->getL10N('lib'),
1235
-				$c->getL10NFactory(),
1236
-				$factory,
1237
-				$c->getUserManager(),
1238
-				$c->getLazyRootFolder(),
1239
-				$c->getEventDispatcher(),
1240
-				$c->getMailer(),
1241
-				$c->getURLGenerator(),
1242
-				$c->getThemingDefaults(),
1243
-				$c->query(IEventDispatcher::class)
1244
-			);
1245
-
1246
-			return $manager;
1247
-		});
1248
-		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1249
-
1250
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1251
-			$instance = new Collaboration\Collaborators\Search($c);
1252
-
1253
-			// register default plugins
1254
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1255
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1256
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1257
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1258
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1259
-
1260
-			return $instance;
1261
-		});
1262
-		$this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1263
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1264
-
1265
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1266
-
1267
-		$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1268
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1269
-
1270
-		$this->registerService('SettingsManager', function (Server $c) {
1271
-			$manager = new \OC\Settings\Manager(
1272
-				$c->getLogger(),
1273
-				$c->getL10NFactory(),
1274
-				$c->getURLGenerator(),
1275
-				$c
1276
-			);
1277
-			return $manager;
1278
-		});
1279
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1280
-			return new \OC\Files\AppData\Factory(
1281
-				$c->getRootFolder(),
1282
-				$c->getSystemConfig()
1283
-			);
1284
-		});
1285
-
1286
-		$this->registerService('LockdownManager', function (Server $c) {
1287
-			return new LockdownManager(function () use ($c) {
1288
-				return $c->getSession();
1289
-			});
1290
-		});
1291
-
1292
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1293
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1294
-		});
1295
-
1296
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1297
-			return new CloudIdManager();
1298
-		});
1299
-
1300
-		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1301
-
1302
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1303
-			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1304
-		});
1305
-
1306
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1307
-			return new CloudFederationFactory();
1308
-		});
1309
-
1310
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1311
-		$this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1312
-
1313
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1314
-		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1315
-
1316
-		$this->registerService(Defaults::class, function (Server $c) {
1317
-			return new Defaults(
1318
-				$c->getThemingDefaults()
1319
-			);
1320
-		});
1321
-		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1322
-
1323
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1324
-			return $c->query(\OCP\IUserSession::class)->getSession();
1325
-		});
1326
-
1327
-		$this->registerService(IShareHelper::class, function (Server $c) {
1328
-			return new ShareHelper(
1329
-				$c->query(\OCP\Share\IManager::class)
1330
-			);
1331
-		});
1332
-
1333
-		$this->registerService(Installer::class, function (Server $c) {
1334
-			return new Installer(
1335
-				$c->getAppFetcher(),
1336
-				$c->getHTTPClientService(),
1337
-				$c->getTempManager(),
1338
-				$c->getLogger(),
1339
-				$c->getConfig(),
1340
-				\OC::$CLI
1341
-			);
1342
-		});
1343
-
1344
-		$this->registerService(IApiFactory::class, function (Server $c) {
1345
-			return new ApiFactory($c->getHTTPClientService());
1346
-		});
1347
-
1348
-		$this->registerService(IInstanceFactory::class, function (Server $c) {
1349
-			$memcacheFactory = $c->getMemCacheFactory();
1350
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1351
-		});
1352
-
1353
-		$this->registerService(IContactsStore::class, function (Server $c) {
1354
-			return new ContactsStore(
1355
-				$c->getContactsManager(),
1356
-				$c->getConfig(),
1357
-				$c->getUserManager(),
1358
-				$c->getGroupManager()
1359
-			);
1360
-		});
1361
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1362
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1363
-
1364
-		$this->registerService(IStorageFactory::class, function () {
1365
-			return new StorageFactory();
1366
-		});
1367
-
1368
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1369
-		$this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1370
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1371
-
1372
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1373
-
1374
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1375
-
1376
-		$this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1377
-
1378
-		$this->connectDispatcher();
1379
-	}
1380
-
1381
-	public function boot() {
1382
-		/** @var HookConnector $hookConnector */
1383
-		$hookConnector = $this->query(HookConnector::class);
1384
-		$hookConnector->viewToNode();
1385
-	}
1386
-
1387
-	/**
1388
-	 * @return \OCP\Calendar\IManager
1389
-	 * @deprecated
1390
-	 */
1391
-	public function getCalendarManager() {
1392
-		return $this->query(\OC\Calendar\Manager::class);
1393
-	}
1394
-
1395
-	/**
1396
-	 * @return \OCP\Calendar\Resource\IManager
1397
-	 * @deprecated
1398
-	 */
1399
-	public function getCalendarResourceBackendManager() {
1400
-		return $this->query(\OC\Calendar\Resource\Manager::class);
1401
-	}
1402
-
1403
-	/**
1404
-	 * @return \OCP\Calendar\Room\IManager
1405
-	 * @deprecated
1406
-	 */
1407
-	public function getCalendarRoomBackendManager() {
1408
-		return $this->query(\OC\Calendar\Room\Manager::class);
1409
-	}
1410
-
1411
-	private function connectDispatcher() {
1412
-		$dispatcher = $this->getEventDispatcher();
1413
-
1414
-		// Delete avatar on user deletion
1415
-		$dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1416
-			$logger = $this->getLogger();
1417
-			$manager = $this->getAvatarManager();
1418
-			/** @var IUser $user */
1419
-			$user = $e->getSubject();
1420
-
1421
-			try {
1422
-				$avatar = $manager->getAvatar($user->getUID());
1423
-				$avatar->remove();
1424
-			} catch (NotFoundException $e) {
1425
-				// no avatar to remove
1426
-			} catch (\Exception $e) {
1427
-				// Ignore exceptions
1428
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1429
-			}
1430
-		});
1431
-
1432
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1433
-			$manager = $this->getAvatarManager();
1434
-			/** @var IUser $user */
1435
-			$user = $e->getSubject();
1436
-			$feature = $e->getArgument('feature');
1437
-			$oldValue = $e->getArgument('oldValue');
1438
-			$value = $e->getArgument('value');
1439
-
1440
-			// We only change the avatar on display name changes
1441
-			if ($feature !== 'displayName') {
1442
-				return;
1443
-			}
1444
-
1445
-			try {
1446
-				$avatar = $manager->getAvatar($user->getUID());
1447
-				$avatar->userChanged($feature, $oldValue, $value);
1448
-			} catch (NotFoundException $e) {
1449
-				// no avatar to remove
1450
-			}
1451
-		});
1452
-
1453
-		/** @var IEventDispatcher $eventDispatched */
1454
-		$eventDispatched = $this->query(IEventDispatcher::class);
1455
-		$eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1456
-	}
1457
-
1458
-	/**
1459
-	 * @return \OCP\Contacts\IManager
1460
-	 * @deprecated
1461
-	 */
1462
-	public function getContactsManager() {
1463
-		return $this->query(\OCP\Contacts\IManager::class);
1464
-	}
1465
-
1466
-	/**
1467
-	 * @return \OC\Encryption\Manager
1468
-	 * @deprecated
1469
-	 */
1470
-	public function getEncryptionManager() {
1471
-		return $this->query(\OCP\Encryption\IManager::class);
1472
-	}
1473
-
1474
-	/**
1475
-	 * @return \OC\Encryption\File
1476
-	 * @deprecated
1477
-	 */
1478
-	public function getEncryptionFilesHelper() {
1479
-		return $this->query('EncryptionFileHelper');
1480
-	}
1481
-
1482
-	/**
1483
-	 * @return \OCP\Encryption\Keys\IStorage
1484
-	 * @deprecated
1485
-	 */
1486
-	public function getEncryptionKeyStorage() {
1487
-		return $this->query('EncryptionKeyStorage');
1488
-	}
1489
-
1490
-	/**
1491
-	 * The current request object holding all information about the request
1492
-	 * currently being processed is returned from this method.
1493
-	 * In case the current execution was not initiated by a web request null is returned
1494
-	 *
1495
-	 * @return \OCP\IRequest
1496
-	 * @deprecated
1497
-	 */
1498
-	public function getRequest() {
1499
-		return $this->query(IRequest::class);
1500
-	}
1501
-
1502
-	/**
1503
-	 * Returns the preview manager which can create preview images for a given file
1504
-	 *
1505
-	 * @return IPreview
1506
-	 * @deprecated
1507
-	 */
1508
-	public function getPreviewManager() {
1509
-		return $this->query(IPreview::class);
1510
-	}
1511
-
1512
-	/**
1513
-	 * Returns the tag manager which can get and set tags for different object types
1514
-	 *
1515
-	 * @see \OCP\ITagManager::load()
1516
-	 * @return ITagManager
1517
-	 * @deprecated
1518
-	 */
1519
-	public function getTagManager() {
1520
-		return $this->query(ITagManager::class);
1521
-	}
1522
-
1523
-	/**
1524
-	 * Returns the system-tag manager
1525
-	 *
1526
-	 * @return ISystemTagManager
1527
-	 *
1528
-	 * @since 9.0.0
1529
-	 * @deprecated
1530
-	 */
1531
-	public function getSystemTagManager() {
1532
-		return $this->query(ISystemTagManager::class);
1533
-	}
1534
-
1535
-	/**
1536
-	 * Returns the system-tag object mapper
1537
-	 *
1538
-	 * @return ISystemTagObjectMapper
1539
-	 *
1540
-	 * @since 9.0.0
1541
-	 * @deprecated
1542
-	 */
1543
-	public function getSystemTagObjectMapper() {
1544
-		return $this->query(ISystemTagObjectMapper::class);
1545
-	}
1546
-
1547
-	/**
1548
-	 * Returns the avatar manager, used for avatar functionality
1549
-	 *
1550
-	 * @return IAvatarManager
1551
-	 * @deprecated
1552
-	 */
1553
-	public function getAvatarManager() {
1554
-		return $this->query(IAvatarManager::class);
1555
-	}
1556
-
1557
-	/**
1558
-	 * Returns the root folder of ownCloud's data directory
1559
-	 *
1560
-	 * @return IRootFolder
1561
-	 * @deprecated
1562
-	 */
1563
-	public function getRootFolder() {
1564
-		return $this->query(IRootFolder::class);
1565
-	}
1566
-
1567
-	/**
1568
-	 * Returns the root folder of ownCloud's data directory
1569
-	 * This is the lazy variant so this gets only initialized once it
1570
-	 * is actually used.
1571
-	 *
1572
-	 * @return IRootFolder
1573
-	 */
1574
-	public function getLazyRootFolder() {
1575
-		return $this->query(IRootFolder::class);
1576
-	}
1577
-
1578
-	/**
1579
-	 * Returns a view to ownCloud's files folder
1580
-	 *
1581
-	 * @param string $userId user ID
1582
-	 * @return \OCP\Files\Folder|null
1583
-	 * @deprecated
1584
-	 */
1585
-	public function getUserFolder($userId = null) {
1586
-		if ($userId === null) {
1587
-			$user = $this->getUserSession()->getUser();
1588
-			if (!$user) {
1589
-				return null;
1590
-			}
1591
-			$userId = $user->getUID();
1592
-		}
1593
-		$root = $this->getRootFolder();
1594
-		return $root->getUserFolder($userId);
1595
-	}
1596
-
1597
-	/**
1598
-	 * @return \OC\User\Manager
1599
-	 * @deprecated
1600
-	 */
1601
-	public function getUserManager() {
1602
-		return $this->query(IUserManager::class);
1603
-	}
1604
-
1605
-	/**
1606
-	 * @return \OC\Group\Manager
1607
-	 * @deprecated
1608
-	 */
1609
-	public function getGroupManager() {
1610
-		return $this->query(IGroupManager::class);
1611
-	}
1612
-
1613
-	/**
1614
-	 * @return \OC\User\Session
1615
-	 * @deprecated
1616
-	 */
1617
-	public function getUserSession() {
1618
-		return $this->query(IUserSession::class);
1619
-	}
1620
-
1621
-	/**
1622
-	 * @return \OCP\ISession
1623
-	 * @deprecated
1624
-	 */
1625
-	public function getSession() {
1626
-		return $this->getUserSession()->getSession();
1627
-	}
1628
-
1629
-	/**
1630
-	 * @param \OCP\ISession $session
1631
-	 */
1632
-	public function setSession(\OCP\ISession $session) {
1633
-		$this->query(SessionStorage::class)->setSession($session);
1634
-		$this->getUserSession()->setSession($session);
1635
-		$this->query(Store::class)->setSession($session);
1636
-	}
1637
-
1638
-	/**
1639
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1640
-	 * @deprecated
1641
-	 */
1642
-	public function getTwoFactorAuthManager() {
1643
-		return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class);
1644
-	}
1645
-
1646
-	/**
1647
-	 * @return \OC\NavigationManager
1648
-	 * @deprecated
1649
-	 */
1650
-	public function getNavigationManager() {
1651
-		return $this->query(INavigationManager::class);
1652
-	}
1653
-
1654
-	/**
1655
-	 * @return \OCP\IConfig
1656
-	 * @deprecated
1657
-	 */
1658
-	public function getConfig() {
1659
-		return $this->query(AllConfig::class);
1660
-	}
1661
-
1662
-	/**
1663
-	 * @return \OC\SystemConfig
1664
-	 * @deprecated
1665
-	 */
1666
-	public function getSystemConfig() {
1667
-		return $this->query(SystemConfig::class);
1668
-	}
1669
-
1670
-	/**
1671
-	 * Returns the app config manager
1672
-	 *
1673
-	 * @return IAppConfig
1674
-	 * @deprecated
1675
-	 */
1676
-	public function getAppConfig() {
1677
-		return $this->query(IAppConfig::class);
1678
-	}
1679
-
1680
-	/**
1681
-	 * @return IFactory
1682
-	 * @deprecated
1683
-	 */
1684
-	public function getL10NFactory() {
1685
-		return $this->query(IFactory::class);
1686
-	}
1687
-
1688
-	/**
1689
-	 * get an L10N instance
1690
-	 *
1691
-	 * @param string $app appid
1692
-	 * @param string $lang
1693
-	 * @return IL10N
1694
-	 * @deprecated
1695
-	 */
1696
-	public function getL10N($app, $lang = null) {
1697
-		return $this->getL10NFactory()->get($app, $lang);
1698
-	}
1699
-
1700
-	/**
1701
-	 * @return IURLGenerator
1702
-	 * @deprecated
1703
-	 */
1704
-	public function getURLGenerator() {
1705
-		return $this->query(IURLGenerator::class);
1706
-	}
1707
-
1708
-	/**
1709
-	 * @return AppFetcher
1710
-	 * @deprecated
1711
-	 */
1712
-	public function getAppFetcher() {
1713
-		return $this->query(AppFetcher::class);
1714
-	}
1715
-
1716
-	/**
1717
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1718
-	 * getMemCacheFactory() instead.
1719
-	 *
1720
-	 * @return ICache
1721
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1722
-	 */
1723
-	public function getCache() {
1724
-		return $this->query(ICache::class);
1725
-	}
1726
-
1727
-	/**
1728
-	 * Returns an \OCP\CacheFactory instance
1729
-	 *
1730
-	 * @return \OCP\ICacheFactory
1731
-	 * @deprecated
1732
-	 */
1733
-	public function getMemCacheFactory() {
1734
-		return $this->query(Factory::class);
1735
-	}
1736
-
1737
-	/**
1738
-	 * Returns an \OC\RedisFactory instance
1739
-	 *
1740
-	 * @return \OC\RedisFactory
1741
-	 * @deprecated
1742
-	 */
1743
-	public function getGetRedisFactory() {
1744
-		return $this->query('RedisFactory');
1745
-	}
1746
-
1747
-
1748
-	/**
1749
-	 * Returns the current session
1750
-	 *
1751
-	 * @return \OCP\IDBConnection
1752
-	 * @deprecated
1753
-	 */
1754
-	public function getDatabaseConnection() {
1755
-		return $this->query(IDBConnection::class);
1756
-	}
1757
-
1758
-	/**
1759
-	 * Returns the activity manager
1760
-	 *
1761
-	 * @return \OCP\Activity\IManager
1762
-	 * @deprecated
1763
-	 */
1764
-	public function getActivityManager() {
1765
-		return $this->query(\OCP\Activity\IManager::class);
1766
-	}
1767
-
1768
-	/**
1769
-	 * Returns an job list for controlling background jobs
1770
-	 *
1771
-	 * @return IJobList
1772
-	 * @deprecated
1773
-	 */
1774
-	public function getJobList() {
1775
-		return $this->query(IJobList::class);
1776
-	}
1777
-
1778
-	/**
1779
-	 * Returns a logger instance
1780
-	 *
1781
-	 * @return ILogger
1782
-	 * @deprecated
1783
-	 */
1784
-	public function getLogger() {
1785
-		return $this->query(ILogger::class);
1786
-	}
1787
-
1788
-	/**
1789
-	 * @return ILogFactory
1790
-	 * @throws \OCP\AppFramework\QueryException
1791
-	 * @deprecated
1792
-	 */
1793
-	public function getLogFactory() {
1794
-		return $this->query(ILogFactory::class);
1795
-	}
1796
-
1797
-	/**
1798
-	 * Returns a router for generating and matching urls
1799
-	 *
1800
-	 * @return IRouter
1801
-	 * @deprecated
1802
-	 */
1803
-	public function getRouter() {
1804
-		return $this->query(IRouter::class);
1805
-	}
1806
-
1807
-	/**
1808
-	 * Returns a search instance
1809
-	 *
1810
-	 * @return ISearch
1811
-	 * @deprecated
1812
-	 */
1813
-	public function getSearch() {
1814
-		return $this->query(ISearch::class);
1815
-	}
1816
-
1817
-	/**
1818
-	 * Returns a SecureRandom instance
1819
-	 *
1820
-	 * @return \OCP\Security\ISecureRandom
1821
-	 * @deprecated
1822
-	 */
1823
-	public function getSecureRandom() {
1824
-		return $this->query(ISecureRandom::class);
1825
-	}
1826
-
1827
-	/**
1828
-	 * Returns a Crypto instance
1829
-	 *
1830
-	 * @return ICrypto
1831
-	 * @deprecated
1832
-	 */
1833
-	public function getCrypto() {
1834
-		return $this->query(ICrypto::class);
1835
-	}
1836
-
1837
-	/**
1838
-	 * Returns a Hasher instance
1839
-	 *
1840
-	 * @return IHasher
1841
-	 * @deprecated
1842
-	 */
1843
-	public function getHasher() {
1844
-		return $this->query(IHasher::class);
1845
-	}
1846
-
1847
-	/**
1848
-	 * Returns a CredentialsManager instance
1849
-	 *
1850
-	 * @return ICredentialsManager
1851
-	 * @deprecated
1852
-	 */
1853
-	public function getCredentialsManager() {
1854
-		return $this->query(ICredentialsManager::class);
1855
-	}
1856
-
1857
-	/**
1858
-	 * Get the certificate manager for the user
1859
-	 *
1860
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1861
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1862
-	 * @deprecated
1863
-	 */
1864
-	public function getCertificateManager($userId = '') {
1865
-		if ($userId === '') {
1866
-			$userSession = $this->getUserSession();
1867
-			$user = $userSession->getUser();
1868
-			if (is_null($user)) {
1869
-				return null;
1870
-			}
1871
-			$userId = $user->getUID();
1872
-		}
1873
-		return new CertificateManager(
1874
-			$userId,
1875
-			new View(),
1876
-			$this->getConfig(),
1877
-			$this->getLogger(),
1878
-			$this->getSecureRandom()
1879
-		);
1880
-	}
1881
-
1882
-	/**
1883
-	 * Returns an instance of the HTTP client service
1884
-	 *
1885
-	 * @return IClientService
1886
-	 * @deprecated
1887
-	 */
1888
-	public function getHTTPClientService() {
1889
-		return $this->query(IClientService::class);
1890
-	}
1891
-
1892
-	/**
1893
-	 * Create a new event source
1894
-	 *
1895
-	 * @return \OCP\IEventSource
1896
-	 * @deprecated
1897
-	 */
1898
-	public function createEventSource() {
1899
-		return new \OC_EventSource();
1900
-	}
1901
-
1902
-	/**
1903
-	 * Get the active event logger
1904
-	 *
1905
-	 * The returned logger only logs data when debug mode is enabled
1906
-	 *
1907
-	 * @return IEventLogger
1908
-	 * @deprecated
1909
-	 */
1910
-	public function getEventLogger() {
1911
-		return $this->query(IEventLogger::class);
1912
-	}
1913
-
1914
-	/**
1915
-	 * Get the active query logger
1916
-	 *
1917
-	 * The returned logger only logs data when debug mode is enabled
1918
-	 *
1919
-	 * @return IQueryLogger
1920
-	 * @deprecated
1921
-	 */
1922
-	public function getQueryLogger() {
1923
-		return $this->query(IQueryLogger::class);
1924
-	}
1925
-
1926
-	/**
1927
-	 * Get the manager for temporary files and folders
1928
-	 *
1929
-	 * @return \OCP\ITempManager
1930
-	 * @deprecated
1931
-	 */
1932
-	public function getTempManager() {
1933
-		return $this->query(ITempManager::class);
1934
-	}
1935
-
1936
-	/**
1937
-	 * Get the app manager
1938
-	 *
1939
-	 * @return \OCP\App\IAppManager
1940
-	 * @deprecated
1941
-	 */
1942
-	public function getAppManager() {
1943
-		return $this->query(IAppManager::class);
1944
-	}
1945
-
1946
-	/**
1947
-	 * Creates a new mailer
1948
-	 *
1949
-	 * @return IMailer
1950
-	 * @deprecated
1951
-	 */
1952
-	public function getMailer() {
1953
-		return $this->query(IMailer::class);
1954
-	}
1955
-
1956
-	/**
1957
-	 * Get the webroot
1958
-	 *
1959
-	 * @return string
1960
-	 * @deprecated
1961
-	 */
1962
-	public function getWebRoot() {
1963
-		return $this->webRoot;
1964
-	}
1965
-
1966
-	/**
1967
-	 * @return \OC\OCSClient
1968
-	 * @deprecated
1969
-	 */
1970
-	public function getOcsClient() {
1971
-		return $this->query('OcsClient');
1972
-	}
1973
-
1974
-	/**
1975
-	 * @return IDateTimeZone
1976
-	 * @deprecated
1977
-	 */
1978
-	public function getDateTimeZone() {
1979
-		return $this->query(IDateTimeZone::class);
1980
-	}
1981
-
1982
-	/**
1983
-	 * @return IDateTimeFormatter
1984
-	 * @deprecated
1985
-	 */
1986
-	public function getDateTimeFormatter() {
1987
-		return $this->query(IDateTimeFormatter::class);
1988
-	}
1989
-
1990
-	/**
1991
-	 * @return IMountProviderCollection
1992
-	 * @deprecated
1993
-	 */
1994
-	public function getMountProviderCollection() {
1995
-		return $this->query(IMountProviderCollection::class);
1996
-	}
1997
-
1998
-	/**
1999
-	 * Get the IniWrapper
2000
-	 *
2001
-	 * @return IniGetWrapper
2002
-	 * @deprecated
2003
-	 */
2004
-	public function getIniWrapper() {
2005
-		return $this->query('IniWrapper');
2006
-	}
2007
-
2008
-	/**
2009
-	 * @return \OCP\Command\IBus
2010
-	 * @deprecated
2011
-	 */
2012
-	public function getCommandBus() {
2013
-		return $this->query('AsyncCommandBus');
2014
-	}
2015
-
2016
-	/**
2017
-	 * Get the trusted domain helper
2018
-	 *
2019
-	 * @return TrustedDomainHelper
2020
-	 * @deprecated
2021
-	 */
2022
-	public function getTrustedDomainHelper() {
2023
-		return $this->query('TrustedDomainHelper');
2024
-	}
2025
-
2026
-	/**
2027
-	 * Get the locking provider
2028
-	 *
2029
-	 * @return ILockingProvider
2030
-	 * @since 8.1.0
2031
-	 * @deprecated
2032
-	 */
2033
-	public function getLockingProvider() {
2034
-		return $this->query(ILockingProvider::class);
2035
-	}
2036
-
2037
-	/**
2038
-	 * @return IMountManager
2039
-	 * @deprecated
2040
-	 **/
2041
-	public function getMountManager() {
2042
-		return $this->query(IMountManager::class);
2043
-	}
2044
-
2045
-	/**
2046
-	 * @return IUserMountCache
2047
-	 * @deprecated
2048
-	 */
2049
-	public function getUserMountCache() {
2050
-		return $this->query(IUserMountCache::class);
2051
-	}
2052
-
2053
-	/**
2054
-	 * Get the MimeTypeDetector
2055
-	 *
2056
-	 * @return IMimeTypeDetector
2057
-	 * @deprecated
2058
-	 */
2059
-	public function getMimeTypeDetector() {
2060
-		return $this->query(IMimeTypeDetector::class);
2061
-	}
2062
-
2063
-	/**
2064
-	 * Get the MimeTypeLoader
2065
-	 *
2066
-	 * @return IMimeTypeLoader
2067
-	 * @deprecated
2068
-	 */
2069
-	public function getMimeTypeLoader() {
2070
-		return $this->query(IMimeTypeLoader::class);
2071
-	}
2072
-
2073
-	/**
2074
-	 * Get the manager of all the capabilities
2075
-	 *
2076
-	 * @return CapabilitiesManager
2077
-	 * @deprecated
2078
-	 */
2079
-	public function getCapabilitiesManager() {
2080
-		return $this->query(CapabilitiesManager::class);
2081
-	}
2082
-
2083
-	/**
2084
-	 * Get the EventDispatcher
2085
-	 *
2086
-	 * @return EventDispatcherInterface
2087
-	 * @since 8.2.0
2088
-	 * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2089
-	 */
2090
-	public function getEventDispatcher() {
2091
-		return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
2092
-	}
2093
-
2094
-	/**
2095
-	 * Get the Notification Manager
2096
-	 *
2097
-	 * @return \OCP\Notification\IManager
2098
-	 * @since 8.2.0
2099
-	 * @deprecated
2100
-	 */
2101
-	public function getNotificationManager() {
2102
-		return $this->query(\OCP\Notification\IManager::class);
2103
-	}
2104
-
2105
-	/**
2106
-	 * @return ICommentsManager
2107
-	 * @deprecated
2108
-	 */
2109
-	public function getCommentsManager() {
2110
-		return $this->query(ICommentsManager::class);
2111
-	}
2112
-
2113
-	/**
2114
-	 * @return \OCA\Theming\ThemingDefaults
2115
-	 * @deprecated
2116
-	 */
2117
-	public function getThemingDefaults() {
2118
-		return $this->query('ThemingDefaults');
2119
-	}
2120
-
2121
-	/**
2122
-	 * @return \OC\IntegrityCheck\Checker
2123
-	 * @deprecated
2124
-	 */
2125
-	public function getIntegrityCodeChecker() {
2126
-		return $this->query('IntegrityCodeChecker');
2127
-	}
2128
-
2129
-	/**
2130
-	 * @return \OC\Session\CryptoWrapper
2131
-	 * @deprecated
2132
-	 */
2133
-	public function getSessionCryptoWrapper() {
2134
-		return $this->query('CryptoWrapper');
2135
-	}
2136
-
2137
-	/**
2138
-	 * @return CsrfTokenManager
2139
-	 * @deprecated
2140
-	 */
2141
-	public function getCsrfTokenManager() {
2142
-		return $this->query(CsrfTokenManager::class);
2143
-	}
2144
-
2145
-	/**
2146
-	 * @return Throttler
2147
-	 * @deprecated
2148
-	 */
2149
-	public function getBruteForceThrottler() {
2150
-		return $this->query(Throttler::class);
2151
-	}
2152
-
2153
-	/**
2154
-	 * @return IContentSecurityPolicyManager
2155
-	 * @deprecated
2156
-	 */
2157
-	public function getContentSecurityPolicyManager() {
2158
-		return $this->query(ContentSecurityPolicyManager::class);
2159
-	}
2160
-
2161
-	/**
2162
-	 * @return ContentSecurityPolicyNonceManager
2163
-	 * @deprecated
2164
-	 */
2165
-	public function getContentSecurityPolicyNonceManager() {
2166
-		return $this->query('ContentSecurityPolicyNonceManager');
2167
-	}
2168
-
2169
-	/**
2170
-	 * Not a public API as of 8.2, wait for 9.0
2171
-	 *
2172
-	 * @return \OCA\Files_External\Service\BackendService
2173
-	 * @deprecated
2174
-	 */
2175
-	public function getStoragesBackendService() {
2176
-		return $this->query(BackendService::class);
2177
-	}
2178
-
2179
-	/**
2180
-	 * Not a public API as of 8.2, wait for 9.0
2181
-	 *
2182
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
2183
-	 * @deprecated
2184
-	 */
2185
-	public function getGlobalStoragesService() {
2186
-		return $this->query(GlobalStoragesService::class);
2187
-	}
2188
-
2189
-	/**
2190
-	 * Not a public API as of 8.2, wait for 9.0
2191
-	 *
2192
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
2193
-	 * @deprecated
2194
-	 */
2195
-	public function getUserGlobalStoragesService() {
2196
-		return $this->query(UserGlobalStoragesService::class);
2197
-	}
2198
-
2199
-	/**
2200
-	 * Not a public API as of 8.2, wait for 9.0
2201
-	 *
2202
-	 * @return \OCA\Files_External\Service\UserStoragesService
2203
-	 * @deprecated
2204
-	 */
2205
-	public function getUserStoragesService() {
2206
-		return $this->query(UserStoragesService::class);
2207
-	}
2208
-
2209
-	/**
2210
-	 * @return \OCP\Share\IManager
2211
-	 * @deprecated
2212
-	 */
2213
-	public function getShareManager() {
2214
-		return $this->query(\OCP\Share\IManager::class);
2215
-	}
2216
-
2217
-	/**
2218
-	 * @return \OCP\Collaboration\Collaborators\ISearch
2219
-	 * @deprecated
2220
-	 */
2221
-	public function getCollaboratorSearch() {
2222
-		return $this->query(\OCP\Collaboration\Collaborators\ISearch::class);
2223
-	}
2224
-
2225
-	/**
2226
-	 * @return \OCP\Collaboration\AutoComplete\IManager
2227
-	 * @deprecated
2228
-	 */
2229
-	public function getAutoCompleteManager() {
2230
-		return $this->query(IManager::class);
2231
-	}
2232
-
2233
-	/**
2234
-	 * Returns the LDAP Provider
2235
-	 *
2236
-	 * @return \OCP\LDAP\ILDAPProvider
2237
-	 * @deprecated
2238
-	 */
2239
-	public function getLDAPProvider() {
2240
-		return $this->query('LDAPProvider');
2241
-	}
2242
-
2243
-	/**
2244
-	 * @return \OCP\Settings\IManager
2245
-	 * @deprecated
2246
-	 */
2247
-	public function getSettingsManager() {
2248
-		return $this->query('SettingsManager');
2249
-	}
2250
-
2251
-	/**
2252
-	 * @return \OCP\Files\IAppData
2253
-	 * @deprecated
2254
-	 */
2255
-	public function getAppDataDir($app) {
2256
-		/** @var \OC\Files\AppData\Factory $factory */
2257
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
2258
-		return $factory->get($app);
2259
-	}
2260
-
2261
-	/**
2262
-	 * @return \OCP\Lockdown\ILockdownManager
2263
-	 * @deprecated
2264
-	 */
2265
-	public function getLockdownManager() {
2266
-		return $this->query('LockdownManager');
2267
-	}
2268
-
2269
-	/**
2270
-	 * @return \OCP\Federation\ICloudIdManager
2271
-	 * @deprecated
2272
-	 */
2273
-	public function getCloudIdManager() {
2274
-		return $this->query(ICloudIdManager::class);
2275
-	}
2276
-
2277
-	/**
2278
-	 * @return \OCP\GlobalScale\IConfig
2279
-	 * @deprecated
2280
-	 */
2281
-	public function getGlobalScaleConfig() {
2282
-		return $this->query(IConfig::class);
2283
-	}
2284
-
2285
-	/**
2286
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2287
-	 * @deprecated
2288
-	 */
2289
-	public function getCloudFederationProviderManager() {
2290
-		return $this->query(ICloudFederationProviderManager::class);
2291
-	}
2292
-
2293
-	/**
2294
-	 * @return \OCP\Remote\Api\IApiFactory
2295
-	 * @deprecated
2296
-	 */
2297
-	public function getRemoteApiFactory() {
2298
-		return $this->query(IApiFactory::class);
2299
-	}
2300
-
2301
-	/**
2302
-	 * @return \OCP\Federation\ICloudFederationFactory
2303
-	 * @deprecated
2304
-	 */
2305
-	public function getCloudFederationFactory() {
2306
-		return $this->query(ICloudFederationFactory::class);
2307
-	}
2308
-
2309
-	/**
2310
-	 * @return \OCP\Remote\IInstanceFactory
2311
-	 * @deprecated
2312
-	 */
2313
-	public function getRemoteInstanceFactory() {
2314
-		return $this->query(IInstanceFactory::class);
2315
-	}
2316
-
2317
-	/**
2318
-	 * @return IStorageFactory
2319
-	 * @deprecated
2320
-	 */
2321
-	public function getStorageFactory() {
2322
-		return $this->query(IStorageFactory::class);
2323
-	}
2324
-
2325
-	/**
2326
-	 * Get the Preview GeneratorHelper
2327
-	 *
2328
-	 * @return GeneratorHelper
2329
-	 * @since 17.0.0
2330
-	 * @deprecated
2331
-	 */
2332
-	public function getGeneratorHelper() {
2333
-		return $this->query(\OC\Preview\GeneratorHelper::class);
2334
-	}
2335
-
2336
-	private function registerDeprecatedAlias(string $alias, string $target) {
2337
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2338
-			try {
2339
-				/** @var ILogger $logger */
2340
-				$logger = $container->get(ILogger::class);
2341
-				$logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2342
-			} catch (ContainerExceptionInterface $e) {
2343
-				// Could not get logger. Continue
2344
-			}
2345
-
2346
-			return $container->get($target);
2347
-		}, false);
2348
-	}
1127
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1128
+            if (isset($prefixes['OCA\\Theming\\'])) {
1129
+                $classExists = true;
1130
+            } else {
1131
+                $classExists = false;
1132
+            }
1133
+
1134
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1135
+                return new ThemingDefaults(
1136
+                    $c->getConfig(),
1137
+                    $c->getL10N('theming'),
1138
+                    $c->getURLGenerator(),
1139
+                    $c->getMemCacheFactory(),
1140
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
1141
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
1142
+                    $c->getAppManager(),
1143
+                    $c->getNavigationManager()
1144
+                );
1145
+            }
1146
+            return new \OC_Defaults();
1147
+        });
1148
+        $this->registerService(SCSSCacher::class, function (Server $c) {
1149
+            return new SCSSCacher(
1150
+                $c->getLogger(),
1151
+                $c->query(\OC\Files\AppData\Factory::class),
1152
+                $c->getURLGenerator(),
1153
+                $c->getConfig(),
1154
+                $c->getThemingDefaults(),
1155
+                \OC::$SERVERROOT,
1156
+                $this->getMemCacheFactory(),
1157
+                $c->query(IconsCacher::class),
1158
+                new TimeFactory()
1159
+            );
1160
+        });
1161
+        $this->registerService(JSCombiner::class, function (Server $c) {
1162
+            return new JSCombiner(
1163
+                $c->getAppDataDir('js'),
1164
+                $c->getURLGenerator(),
1165
+                $this->getMemCacheFactory(),
1166
+                $c->getSystemConfig(),
1167
+                $c->getLogger()
1168
+            );
1169
+        });
1170
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1171
+        $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1172
+        $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1173
+
1174
+        $this->registerService('CryptoWrapper', function (Server $c) {
1175
+            // FIXME: Instantiiated here due to cyclic dependency
1176
+            $request = new Request(
1177
+                [
1178
+                    'get' => $_GET,
1179
+                    'post' => $_POST,
1180
+                    'files' => $_FILES,
1181
+                    'server' => $_SERVER,
1182
+                    'env' => $_ENV,
1183
+                    'cookies' => $_COOKIE,
1184
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1185
+                        ? $_SERVER['REQUEST_METHOD']
1186
+                        : null,
1187
+                ],
1188
+                $c->getSecureRandom(),
1189
+                $c->getConfig()
1190
+            );
1191
+
1192
+            return new CryptoWrapper(
1193
+                $c->getConfig(),
1194
+                $c->getCrypto(),
1195
+                $c->getSecureRandom(),
1196
+                $request
1197
+            );
1198
+        });
1199
+        $this->registerService(CsrfTokenManager::class, function (Server $c) {
1200
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1201
+
1202
+            return new CsrfTokenManager(
1203
+                $tokenGenerator,
1204
+                $c->query(SessionStorage::class)
1205
+            );
1206
+        });
1207
+        $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1208
+        $this->registerService(SessionStorage::class, function (Server $c) {
1209
+            return new SessionStorage($c->getSession());
1210
+        });
1211
+        $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1212
+        $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1213
+
1214
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1215
+            return new ContentSecurityPolicyNonceManager(
1216
+                $c->getCsrfTokenManager(),
1217
+                $c->getRequest()
1218
+            );
1219
+        });
1220
+
1221
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1222
+            $config = $c->getConfig();
1223
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1224
+            /** @var \OCP\Share\IProviderFactory $factory */
1225
+            $factory = new $factoryClass($this);
1226
+
1227
+            $manager = new \OC\Share20\Manager(
1228
+                $c->getLogger(),
1229
+                $c->getConfig(),
1230
+                $c->getSecureRandom(),
1231
+                $c->getHasher(),
1232
+                $c->getMountManager(),
1233
+                $c->getGroupManager(),
1234
+                $c->getL10N('lib'),
1235
+                $c->getL10NFactory(),
1236
+                $factory,
1237
+                $c->getUserManager(),
1238
+                $c->getLazyRootFolder(),
1239
+                $c->getEventDispatcher(),
1240
+                $c->getMailer(),
1241
+                $c->getURLGenerator(),
1242
+                $c->getThemingDefaults(),
1243
+                $c->query(IEventDispatcher::class)
1244
+            );
1245
+
1246
+            return $manager;
1247
+        });
1248
+        $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1249
+
1250
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1251
+            $instance = new Collaboration\Collaborators\Search($c);
1252
+
1253
+            // register default plugins
1254
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1255
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1256
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1257
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1258
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1259
+
1260
+            return $instance;
1261
+        });
1262
+        $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1263
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1264
+
1265
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1266
+
1267
+        $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1268
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1269
+
1270
+        $this->registerService('SettingsManager', function (Server $c) {
1271
+            $manager = new \OC\Settings\Manager(
1272
+                $c->getLogger(),
1273
+                $c->getL10NFactory(),
1274
+                $c->getURLGenerator(),
1275
+                $c
1276
+            );
1277
+            return $manager;
1278
+        });
1279
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1280
+            return new \OC\Files\AppData\Factory(
1281
+                $c->getRootFolder(),
1282
+                $c->getSystemConfig()
1283
+            );
1284
+        });
1285
+
1286
+        $this->registerService('LockdownManager', function (Server $c) {
1287
+            return new LockdownManager(function () use ($c) {
1288
+                return $c->getSession();
1289
+            });
1290
+        });
1291
+
1292
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1293
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1294
+        });
1295
+
1296
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1297
+            return new CloudIdManager();
1298
+        });
1299
+
1300
+        $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1301
+
1302
+        $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1303
+            return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1304
+        });
1305
+
1306
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1307
+            return new CloudFederationFactory();
1308
+        });
1309
+
1310
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1311
+        $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1312
+
1313
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1314
+        $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1315
+
1316
+        $this->registerService(Defaults::class, function (Server $c) {
1317
+            return new Defaults(
1318
+                $c->getThemingDefaults()
1319
+            );
1320
+        });
1321
+        $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1322
+
1323
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1324
+            return $c->query(\OCP\IUserSession::class)->getSession();
1325
+        });
1326
+
1327
+        $this->registerService(IShareHelper::class, function (Server $c) {
1328
+            return new ShareHelper(
1329
+                $c->query(\OCP\Share\IManager::class)
1330
+            );
1331
+        });
1332
+
1333
+        $this->registerService(Installer::class, function (Server $c) {
1334
+            return new Installer(
1335
+                $c->getAppFetcher(),
1336
+                $c->getHTTPClientService(),
1337
+                $c->getTempManager(),
1338
+                $c->getLogger(),
1339
+                $c->getConfig(),
1340
+                \OC::$CLI
1341
+            );
1342
+        });
1343
+
1344
+        $this->registerService(IApiFactory::class, function (Server $c) {
1345
+            return new ApiFactory($c->getHTTPClientService());
1346
+        });
1347
+
1348
+        $this->registerService(IInstanceFactory::class, function (Server $c) {
1349
+            $memcacheFactory = $c->getMemCacheFactory();
1350
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1351
+        });
1352
+
1353
+        $this->registerService(IContactsStore::class, function (Server $c) {
1354
+            return new ContactsStore(
1355
+                $c->getContactsManager(),
1356
+                $c->getConfig(),
1357
+                $c->getUserManager(),
1358
+                $c->getGroupManager()
1359
+            );
1360
+        });
1361
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1362
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1363
+
1364
+        $this->registerService(IStorageFactory::class, function () {
1365
+            return new StorageFactory();
1366
+        });
1367
+
1368
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1369
+        $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1370
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1371
+
1372
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1373
+
1374
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1375
+
1376
+        $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1377
+
1378
+        $this->connectDispatcher();
1379
+    }
1380
+
1381
+    public function boot() {
1382
+        /** @var HookConnector $hookConnector */
1383
+        $hookConnector = $this->query(HookConnector::class);
1384
+        $hookConnector->viewToNode();
1385
+    }
1386
+
1387
+    /**
1388
+     * @return \OCP\Calendar\IManager
1389
+     * @deprecated
1390
+     */
1391
+    public function getCalendarManager() {
1392
+        return $this->query(\OC\Calendar\Manager::class);
1393
+    }
1394
+
1395
+    /**
1396
+     * @return \OCP\Calendar\Resource\IManager
1397
+     * @deprecated
1398
+     */
1399
+    public function getCalendarResourceBackendManager() {
1400
+        return $this->query(\OC\Calendar\Resource\Manager::class);
1401
+    }
1402
+
1403
+    /**
1404
+     * @return \OCP\Calendar\Room\IManager
1405
+     * @deprecated
1406
+     */
1407
+    public function getCalendarRoomBackendManager() {
1408
+        return $this->query(\OC\Calendar\Room\Manager::class);
1409
+    }
1410
+
1411
+    private function connectDispatcher() {
1412
+        $dispatcher = $this->getEventDispatcher();
1413
+
1414
+        // Delete avatar on user deletion
1415
+        $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1416
+            $logger = $this->getLogger();
1417
+            $manager = $this->getAvatarManager();
1418
+            /** @var IUser $user */
1419
+            $user = $e->getSubject();
1420
+
1421
+            try {
1422
+                $avatar = $manager->getAvatar($user->getUID());
1423
+                $avatar->remove();
1424
+            } catch (NotFoundException $e) {
1425
+                // no avatar to remove
1426
+            } catch (\Exception $e) {
1427
+                // Ignore exceptions
1428
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1429
+            }
1430
+        });
1431
+
1432
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1433
+            $manager = $this->getAvatarManager();
1434
+            /** @var IUser $user */
1435
+            $user = $e->getSubject();
1436
+            $feature = $e->getArgument('feature');
1437
+            $oldValue = $e->getArgument('oldValue');
1438
+            $value = $e->getArgument('value');
1439
+
1440
+            // We only change the avatar on display name changes
1441
+            if ($feature !== 'displayName') {
1442
+                return;
1443
+            }
1444
+
1445
+            try {
1446
+                $avatar = $manager->getAvatar($user->getUID());
1447
+                $avatar->userChanged($feature, $oldValue, $value);
1448
+            } catch (NotFoundException $e) {
1449
+                // no avatar to remove
1450
+            }
1451
+        });
1452
+
1453
+        /** @var IEventDispatcher $eventDispatched */
1454
+        $eventDispatched = $this->query(IEventDispatcher::class);
1455
+        $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1456
+    }
1457
+
1458
+    /**
1459
+     * @return \OCP\Contacts\IManager
1460
+     * @deprecated
1461
+     */
1462
+    public function getContactsManager() {
1463
+        return $this->query(\OCP\Contacts\IManager::class);
1464
+    }
1465
+
1466
+    /**
1467
+     * @return \OC\Encryption\Manager
1468
+     * @deprecated
1469
+     */
1470
+    public function getEncryptionManager() {
1471
+        return $this->query(\OCP\Encryption\IManager::class);
1472
+    }
1473
+
1474
+    /**
1475
+     * @return \OC\Encryption\File
1476
+     * @deprecated
1477
+     */
1478
+    public function getEncryptionFilesHelper() {
1479
+        return $this->query('EncryptionFileHelper');
1480
+    }
1481
+
1482
+    /**
1483
+     * @return \OCP\Encryption\Keys\IStorage
1484
+     * @deprecated
1485
+     */
1486
+    public function getEncryptionKeyStorage() {
1487
+        return $this->query('EncryptionKeyStorage');
1488
+    }
1489
+
1490
+    /**
1491
+     * The current request object holding all information about the request
1492
+     * currently being processed is returned from this method.
1493
+     * In case the current execution was not initiated by a web request null is returned
1494
+     *
1495
+     * @return \OCP\IRequest
1496
+     * @deprecated
1497
+     */
1498
+    public function getRequest() {
1499
+        return $this->query(IRequest::class);
1500
+    }
1501
+
1502
+    /**
1503
+     * Returns the preview manager which can create preview images for a given file
1504
+     *
1505
+     * @return IPreview
1506
+     * @deprecated
1507
+     */
1508
+    public function getPreviewManager() {
1509
+        return $this->query(IPreview::class);
1510
+    }
1511
+
1512
+    /**
1513
+     * Returns the tag manager which can get and set tags for different object types
1514
+     *
1515
+     * @see \OCP\ITagManager::load()
1516
+     * @return ITagManager
1517
+     * @deprecated
1518
+     */
1519
+    public function getTagManager() {
1520
+        return $this->query(ITagManager::class);
1521
+    }
1522
+
1523
+    /**
1524
+     * Returns the system-tag manager
1525
+     *
1526
+     * @return ISystemTagManager
1527
+     *
1528
+     * @since 9.0.0
1529
+     * @deprecated
1530
+     */
1531
+    public function getSystemTagManager() {
1532
+        return $this->query(ISystemTagManager::class);
1533
+    }
1534
+
1535
+    /**
1536
+     * Returns the system-tag object mapper
1537
+     *
1538
+     * @return ISystemTagObjectMapper
1539
+     *
1540
+     * @since 9.0.0
1541
+     * @deprecated
1542
+     */
1543
+    public function getSystemTagObjectMapper() {
1544
+        return $this->query(ISystemTagObjectMapper::class);
1545
+    }
1546
+
1547
+    /**
1548
+     * Returns the avatar manager, used for avatar functionality
1549
+     *
1550
+     * @return IAvatarManager
1551
+     * @deprecated
1552
+     */
1553
+    public function getAvatarManager() {
1554
+        return $this->query(IAvatarManager::class);
1555
+    }
1556
+
1557
+    /**
1558
+     * Returns the root folder of ownCloud's data directory
1559
+     *
1560
+     * @return IRootFolder
1561
+     * @deprecated
1562
+     */
1563
+    public function getRootFolder() {
1564
+        return $this->query(IRootFolder::class);
1565
+    }
1566
+
1567
+    /**
1568
+     * Returns the root folder of ownCloud's data directory
1569
+     * This is the lazy variant so this gets only initialized once it
1570
+     * is actually used.
1571
+     *
1572
+     * @return IRootFolder
1573
+     */
1574
+    public function getLazyRootFolder() {
1575
+        return $this->query(IRootFolder::class);
1576
+    }
1577
+
1578
+    /**
1579
+     * Returns a view to ownCloud's files folder
1580
+     *
1581
+     * @param string $userId user ID
1582
+     * @return \OCP\Files\Folder|null
1583
+     * @deprecated
1584
+     */
1585
+    public function getUserFolder($userId = null) {
1586
+        if ($userId === null) {
1587
+            $user = $this->getUserSession()->getUser();
1588
+            if (!$user) {
1589
+                return null;
1590
+            }
1591
+            $userId = $user->getUID();
1592
+        }
1593
+        $root = $this->getRootFolder();
1594
+        return $root->getUserFolder($userId);
1595
+    }
1596
+
1597
+    /**
1598
+     * @return \OC\User\Manager
1599
+     * @deprecated
1600
+     */
1601
+    public function getUserManager() {
1602
+        return $this->query(IUserManager::class);
1603
+    }
1604
+
1605
+    /**
1606
+     * @return \OC\Group\Manager
1607
+     * @deprecated
1608
+     */
1609
+    public function getGroupManager() {
1610
+        return $this->query(IGroupManager::class);
1611
+    }
1612
+
1613
+    /**
1614
+     * @return \OC\User\Session
1615
+     * @deprecated
1616
+     */
1617
+    public function getUserSession() {
1618
+        return $this->query(IUserSession::class);
1619
+    }
1620
+
1621
+    /**
1622
+     * @return \OCP\ISession
1623
+     * @deprecated
1624
+     */
1625
+    public function getSession() {
1626
+        return $this->getUserSession()->getSession();
1627
+    }
1628
+
1629
+    /**
1630
+     * @param \OCP\ISession $session
1631
+     */
1632
+    public function setSession(\OCP\ISession $session) {
1633
+        $this->query(SessionStorage::class)->setSession($session);
1634
+        $this->getUserSession()->setSession($session);
1635
+        $this->query(Store::class)->setSession($session);
1636
+    }
1637
+
1638
+    /**
1639
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1640
+     * @deprecated
1641
+     */
1642
+    public function getTwoFactorAuthManager() {
1643
+        return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class);
1644
+    }
1645
+
1646
+    /**
1647
+     * @return \OC\NavigationManager
1648
+     * @deprecated
1649
+     */
1650
+    public function getNavigationManager() {
1651
+        return $this->query(INavigationManager::class);
1652
+    }
1653
+
1654
+    /**
1655
+     * @return \OCP\IConfig
1656
+     * @deprecated
1657
+     */
1658
+    public function getConfig() {
1659
+        return $this->query(AllConfig::class);
1660
+    }
1661
+
1662
+    /**
1663
+     * @return \OC\SystemConfig
1664
+     * @deprecated
1665
+     */
1666
+    public function getSystemConfig() {
1667
+        return $this->query(SystemConfig::class);
1668
+    }
1669
+
1670
+    /**
1671
+     * Returns the app config manager
1672
+     *
1673
+     * @return IAppConfig
1674
+     * @deprecated
1675
+     */
1676
+    public function getAppConfig() {
1677
+        return $this->query(IAppConfig::class);
1678
+    }
1679
+
1680
+    /**
1681
+     * @return IFactory
1682
+     * @deprecated
1683
+     */
1684
+    public function getL10NFactory() {
1685
+        return $this->query(IFactory::class);
1686
+    }
1687
+
1688
+    /**
1689
+     * get an L10N instance
1690
+     *
1691
+     * @param string $app appid
1692
+     * @param string $lang
1693
+     * @return IL10N
1694
+     * @deprecated
1695
+     */
1696
+    public function getL10N($app, $lang = null) {
1697
+        return $this->getL10NFactory()->get($app, $lang);
1698
+    }
1699
+
1700
+    /**
1701
+     * @return IURLGenerator
1702
+     * @deprecated
1703
+     */
1704
+    public function getURLGenerator() {
1705
+        return $this->query(IURLGenerator::class);
1706
+    }
1707
+
1708
+    /**
1709
+     * @return AppFetcher
1710
+     * @deprecated
1711
+     */
1712
+    public function getAppFetcher() {
1713
+        return $this->query(AppFetcher::class);
1714
+    }
1715
+
1716
+    /**
1717
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1718
+     * getMemCacheFactory() instead.
1719
+     *
1720
+     * @return ICache
1721
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1722
+     */
1723
+    public function getCache() {
1724
+        return $this->query(ICache::class);
1725
+    }
1726
+
1727
+    /**
1728
+     * Returns an \OCP\CacheFactory instance
1729
+     *
1730
+     * @return \OCP\ICacheFactory
1731
+     * @deprecated
1732
+     */
1733
+    public function getMemCacheFactory() {
1734
+        return $this->query(Factory::class);
1735
+    }
1736
+
1737
+    /**
1738
+     * Returns an \OC\RedisFactory instance
1739
+     *
1740
+     * @return \OC\RedisFactory
1741
+     * @deprecated
1742
+     */
1743
+    public function getGetRedisFactory() {
1744
+        return $this->query('RedisFactory');
1745
+    }
1746
+
1747
+
1748
+    /**
1749
+     * Returns the current session
1750
+     *
1751
+     * @return \OCP\IDBConnection
1752
+     * @deprecated
1753
+     */
1754
+    public function getDatabaseConnection() {
1755
+        return $this->query(IDBConnection::class);
1756
+    }
1757
+
1758
+    /**
1759
+     * Returns the activity manager
1760
+     *
1761
+     * @return \OCP\Activity\IManager
1762
+     * @deprecated
1763
+     */
1764
+    public function getActivityManager() {
1765
+        return $this->query(\OCP\Activity\IManager::class);
1766
+    }
1767
+
1768
+    /**
1769
+     * Returns an job list for controlling background jobs
1770
+     *
1771
+     * @return IJobList
1772
+     * @deprecated
1773
+     */
1774
+    public function getJobList() {
1775
+        return $this->query(IJobList::class);
1776
+    }
1777
+
1778
+    /**
1779
+     * Returns a logger instance
1780
+     *
1781
+     * @return ILogger
1782
+     * @deprecated
1783
+     */
1784
+    public function getLogger() {
1785
+        return $this->query(ILogger::class);
1786
+    }
1787
+
1788
+    /**
1789
+     * @return ILogFactory
1790
+     * @throws \OCP\AppFramework\QueryException
1791
+     * @deprecated
1792
+     */
1793
+    public function getLogFactory() {
1794
+        return $this->query(ILogFactory::class);
1795
+    }
1796
+
1797
+    /**
1798
+     * Returns a router for generating and matching urls
1799
+     *
1800
+     * @return IRouter
1801
+     * @deprecated
1802
+     */
1803
+    public function getRouter() {
1804
+        return $this->query(IRouter::class);
1805
+    }
1806
+
1807
+    /**
1808
+     * Returns a search instance
1809
+     *
1810
+     * @return ISearch
1811
+     * @deprecated
1812
+     */
1813
+    public function getSearch() {
1814
+        return $this->query(ISearch::class);
1815
+    }
1816
+
1817
+    /**
1818
+     * Returns a SecureRandom instance
1819
+     *
1820
+     * @return \OCP\Security\ISecureRandom
1821
+     * @deprecated
1822
+     */
1823
+    public function getSecureRandom() {
1824
+        return $this->query(ISecureRandom::class);
1825
+    }
1826
+
1827
+    /**
1828
+     * Returns a Crypto instance
1829
+     *
1830
+     * @return ICrypto
1831
+     * @deprecated
1832
+     */
1833
+    public function getCrypto() {
1834
+        return $this->query(ICrypto::class);
1835
+    }
1836
+
1837
+    /**
1838
+     * Returns a Hasher instance
1839
+     *
1840
+     * @return IHasher
1841
+     * @deprecated
1842
+     */
1843
+    public function getHasher() {
1844
+        return $this->query(IHasher::class);
1845
+    }
1846
+
1847
+    /**
1848
+     * Returns a CredentialsManager instance
1849
+     *
1850
+     * @return ICredentialsManager
1851
+     * @deprecated
1852
+     */
1853
+    public function getCredentialsManager() {
1854
+        return $this->query(ICredentialsManager::class);
1855
+    }
1856
+
1857
+    /**
1858
+     * Get the certificate manager for the user
1859
+     *
1860
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1861
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1862
+     * @deprecated
1863
+     */
1864
+    public function getCertificateManager($userId = '') {
1865
+        if ($userId === '') {
1866
+            $userSession = $this->getUserSession();
1867
+            $user = $userSession->getUser();
1868
+            if (is_null($user)) {
1869
+                return null;
1870
+            }
1871
+            $userId = $user->getUID();
1872
+        }
1873
+        return new CertificateManager(
1874
+            $userId,
1875
+            new View(),
1876
+            $this->getConfig(),
1877
+            $this->getLogger(),
1878
+            $this->getSecureRandom()
1879
+        );
1880
+    }
1881
+
1882
+    /**
1883
+     * Returns an instance of the HTTP client service
1884
+     *
1885
+     * @return IClientService
1886
+     * @deprecated
1887
+     */
1888
+    public function getHTTPClientService() {
1889
+        return $this->query(IClientService::class);
1890
+    }
1891
+
1892
+    /**
1893
+     * Create a new event source
1894
+     *
1895
+     * @return \OCP\IEventSource
1896
+     * @deprecated
1897
+     */
1898
+    public function createEventSource() {
1899
+        return new \OC_EventSource();
1900
+    }
1901
+
1902
+    /**
1903
+     * Get the active event logger
1904
+     *
1905
+     * The returned logger only logs data when debug mode is enabled
1906
+     *
1907
+     * @return IEventLogger
1908
+     * @deprecated
1909
+     */
1910
+    public function getEventLogger() {
1911
+        return $this->query(IEventLogger::class);
1912
+    }
1913
+
1914
+    /**
1915
+     * Get the active query logger
1916
+     *
1917
+     * The returned logger only logs data when debug mode is enabled
1918
+     *
1919
+     * @return IQueryLogger
1920
+     * @deprecated
1921
+     */
1922
+    public function getQueryLogger() {
1923
+        return $this->query(IQueryLogger::class);
1924
+    }
1925
+
1926
+    /**
1927
+     * Get the manager for temporary files and folders
1928
+     *
1929
+     * @return \OCP\ITempManager
1930
+     * @deprecated
1931
+     */
1932
+    public function getTempManager() {
1933
+        return $this->query(ITempManager::class);
1934
+    }
1935
+
1936
+    /**
1937
+     * Get the app manager
1938
+     *
1939
+     * @return \OCP\App\IAppManager
1940
+     * @deprecated
1941
+     */
1942
+    public function getAppManager() {
1943
+        return $this->query(IAppManager::class);
1944
+    }
1945
+
1946
+    /**
1947
+     * Creates a new mailer
1948
+     *
1949
+     * @return IMailer
1950
+     * @deprecated
1951
+     */
1952
+    public function getMailer() {
1953
+        return $this->query(IMailer::class);
1954
+    }
1955
+
1956
+    /**
1957
+     * Get the webroot
1958
+     *
1959
+     * @return string
1960
+     * @deprecated
1961
+     */
1962
+    public function getWebRoot() {
1963
+        return $this->webRoot;
1964
+    }
1965
+
1966
+    /**
1967
+     * @return \OC\OCSClient
1968
+     * @deprecated
1969
+     */
1970
+    public function getOcsClient() {
1971
+        return $this->query('OcsClient');
1972
+    }
1973
+
1974
+    /**
1975
+     * @return IDateTimeZone
1976
+     * @deprecated
1977
+     */
1978
+    public function getDateTimeZone() {
1979
+        return $this->query(IDateTimeZone::class);
1980
+    }
1981
+
1982
+    /**
1983
+     * @return IDateTimeFormatter
1984
+     * @deprecated
1985
+     */
1986
+    public function getDateTimeFormatter() {
1987
+        return $this->query(IDateTimeFormatter::class);
1988
+    }
1989
+
1990
+    /**
1991
+     * @return IMountProviderCollection
1992
+     * @deprecated
1993
+     */
1994
+    public function getMountProviderCollection() {
1995
+        return $this->query(IMountProviderCollection::class);
1996
+    }
1997
+
1998
+    /**
1999
+     * Get the IniWrapper
2000
+     *
2001
+     * @return IniGetWrapper
2002
+     * @deprecated
2003
+     */
2004
+    public function getIniWrapper() {
2005
+        return $this->query('IniWrapper');
2006
+    }
2007
+
2008
+    /**
2009
+     * @return \OCP\Command\IBus
2010
+     * @deprecated
2011
+     */
2012
+    public function getCommandBus() {
2013
+        return $this->query('AsyncCommandBus');
2014
+    }
2015
+
2016
+    /**
2017
+     * Get the trusted domain helper
2018
+     *
2019
+     * @return TrustedDomainHelper
2020
+     * @deprecated
2021
+     */
2022
+    public function getTrustedDomainHelper() {
2023
+        return $this->query('TrustedDomainHelper');
2024
+    }
2025
+
2026
+    /**
2027
+     * Get the locking provider
2028
+     *
2029
+     * @return ILockingProvider
2030
+     * @since 8.1.0
2031
+     * @deprecated
2032
+     */
2033
+    public function getLockingProvider() {
2034
+        return $this->query(ILockingProvider::class);
2035
+    }
2036
+
2037
+    /**
2038
+     * @return IMountManager
2039
+     * @deprecated
2040
+     **/
2041
+    public function getMountManager() {
2042
+        return $this->query(IMountManager::class);
2043
+    }
2044
+
2045
+    /**
2046
+     * @return IUserMountCache
2047
+     * @deprecated
2048
+     */
2049
+    public function getUserMountCache() {
2050
+        return $this->query(IUserMountCache::class);
2051
+    }
2052
+
2053
+    /**
2054
+     * Get the MimeTypeDetector
2055
+     *
2056
+     * @return IMimeTypeDetector
2057
+     * @deprecated
2058
+     */
2059
+    public function getMimeTypeDetector() {
2060
+        return $this->query(IMimeTypeDetector::class);
2061
+    }
2062
+
2063
+    /**
2064
+     * Get the MimeTypeLoader
2065
+     *
2066
+     * @return IMimeTypeLoader
2067
+     * @deprecated
2068
+     */
2069
+    public function getMimeTypeLoader() {
2070
+        return $this->query(IMimeTypeLoader::class);
2071
+    }
2072
+
2073
+    /**
2074
+     * Get the manager of all the capabilities
2075
+     *
2076
+     * @return CapabilitiesManager
2077
+     * @deprecated
2078
+     */
2079
+    public function getCapabilitiesManager() {
2080
+        return $this->query(CapabilitiesManager::class);
2081
+    }
2082
+
2083
+    /**
2084
+     * Get the EventDispatcher
2085
+     *
2086
+     * @return EventDispatcherInterface
2087
+     * @since 8.2.0
2088
+     * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2089
+     */
2090
+    public function getEventDispatcher() {
2091
+        return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
2092
+    }
2093
+
2094
+    /**
2095
+     * Get the Notification Manager
2096
+     *
2097
+     * @return \OCP\Notification\IManager
2098
+     * @since 8.2.0
2099
+     * @deprecated
2100
+     */
2101
+    public function getNotificationManager() {
2102
+        return $this->query(\OCP\Notification\IManager::class);
2103
+    }
2104
+
2105
+    /**
2106
+     * @return ICommentsManager
2107
+     * @deprecated
2108
+     */
2109
+    public function getCommentsManager() {
2110
+        return $this->query(ICommentsManager::class);
2111
+    }
2112
+
2113
+    /**
2114
+     * @return \OCA\Theming\ThemingDefaults
2115
+     * @deprecated
2116
+     */
2117
+    public function getThemingDefaults() {
2118
+        return $this->query('ThemingDefaults');
2119
+    }
2120
+
2121
+    /**
2122
+     * @return \OC\IntegrityCheck\Checker
2123
+     * @deprecated
2124
+     */
2125
+    public function getIntegrityCodeChecker() {
2126
+        return $this->query('IntegrityCodeChecker');
2127
+    }
2128
+
2129
+    /**
2130
+     * @return \OC\Session\CryptoWrapper
2131
+     * @deprecated
2132
+     */
2133
+    public function getSessionCryptoWrapper() {
2134
+        return $this->query('CryptoWrapper');
2135
+    }
2136
+
2137
+    /**
2138
+     * @return CsrfTokenManager
2139
+     * @deprecated
2140
+     */
2141
+    public function getCsrfTokenManager() {
2142
+        return $this->query(CsrfTokenManager::class);
2143
+    }
2144
+
2145
+    /**
2146
+     * @return Throttler
2147
+     * @deprecated
2148
+     */
2149
+    public function getBruteForceThrottler() {
2150
+        return $this->query(Throttler::class);
2151
+    }
2152
+
2153
+    /**
2154
+     * @return IContentSecurityPolicyManager
2155
+     * @deprecated
2156
+     */
2157
+    public function getContentSecurityPolicyManager() {
2158
+        return $this->query(ContentSecurityPolicyManager::class);
2159
+    }
2160
+
2161
+    /**
2162
+     * @return ContentSecurityPolicyNonceManager
2163
+     * @deprecated
2164
+     */
2165
+    public function getContentSecurityPolicyNonceManager() {
2166
+        return $this->query('ContentSecurityPolicyNonceManager');
2167
+    }
2168
+
2169
+    /**
2170
+     * Not a public API as of 8.2, wait for 9.0
2171
+     *
2172
+     * @return \OCA\Files_External\Service\BackendService
2173
+     * @deprecated
2174
+     */
2175
+    public function getStoragesBackendService() {
2176
+        return $this->query(BackendService::class);
2177
+    }
2178
+
2179
+    /**
2180
+     * Not a public API as of 8.2, wait for 9.0
2181
+     *
2182
+     * @return \OCA\Files_External\Service\GlobalStoragesService
2183
+     * @deprecated
2184
+     */
2185
+    public function getGlobalStoragesService() {
2186
+        return $this->query(GlobalStoragesService::class);
2187
+    }
2188
+
2189
+    /**
2190
+     * Not a public API as of 8.2, wait for 9.0
2191
+     *
2192
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
2193
+     * @deprecated
2194
+     */
2195
+    public function getUserGlobalStoragesService() {
2196
+        return $this->query(UserGlobalStoragesService::class);
2197
+    }
2198
+
2199
+    /**
2200
+     * Not a public API as of 8.2, wait for 9.0
2201
+     *
2202
+     * @return \OCA\Files_External\Service\UserStoragesService
2203
+     * @deprecated
2204
+     */
2205
+    public function getUserStoragesService() {
2206
+        return $this->query(UserStoragesService::class);
2207
+    }
2208
+
2209
+    /**
2210
+     * @return \OCP\Share\IManager
2211
+     * @deprecated
2212
+     */
2213
+    public function getShareManager() {
2214
+        return $this->query(\OCP\Share\IManager::class);
2215
+    }
2216
+
2217
+    /**
2218
+     * @return \OCP\Collaboration\Collaborators\ISearch
2219
+     * @deprecated
2220
+     */
2221
+    public function getCollaboratorSearch() {
2222
+        return $this->query(\OCP\Collaboration\Collaborators\ISearch::class);
2223
+    }
2224
+
2225
+    /**
2226
+     * @return \OCP\Collaboration\AutoComplete\IManager
2227
+     * @deprecated
2228
+     */
2229
+    public function getAutoCompleteManager() {
2230
+        return $this->query(IManager::class);
2231
+    }
2232
+
2233
+    /**
2234
+     * Returns the LDAP Provider
2235
+     *
2236
+     * @return \OCP\LDAP\ILDAPProvider
2237
+     * @deprecated
2238
+     */
2239
+    public function getLDAPProvider() {
2240
+        return $this->query('LDAPProvider');
2241
+    }
2242
+
2243
+    /**
2244
+     * @return \OCP\Settings\IManager
2245
+     * @deprecated
2246
+     */
2247
+    public function getSettingsManager() {
2248
+        return $this->query('SettingsManager');
2249
+    }
2250
+
2251
+    /**
2252
+     * @return \OCP\Files\IAppData
2253
+     * @deprecated
2254
+     */
2255
+    public function getAppDataDir($app) {
2256
+        /** @var \OC\Files\AppData\Factory $factory */
2257
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
2258
+        return $factory->get($app);
2259
+    }
2260
+
2261
+    /**
2262
+     * @return \OCP\Lockdown\ILockdownManager
2263
+     * @deprecated
2264
+     */
2265
+    public function getLockdownManager() {
2266
+        return $this->query('LockdownManager');
2267
+    }
2268
+
2269
+    /**
2270
+     * @return \OCP\Federation\ICloudIdManager
2271
+     * @deprecated
2272
+     */
2273
+    public function getCloudIdManager() {
2274
+        return $this->query(ICloudIdManager::class);
2275
+    }
2276
+
2277
+    /**
2278
+     * @return \OCP\GlobalScale\IConfig
2279
+     * @deprecated
2280
+     */
2281
+    public function getGlobalScaleConfig() {
2282
+        return $this->query(IConfig::class);
2283
+    }
2284
+
2285
+    /**
2286
+     * @return \OCP\Federation\ICloudFederationProviderManager
2287
+     * @deprecated
2288
+     */
2289
+    public function getCloudFederationProviderManager() {
2290
+        return $this->query(ICloudFederationProviderManager::class);
2291
+    }
2292
+
2293
+    /**
2294
+     * @return \OCP\Remote\Api\IApiFactory
2295
+     * @deprecated
2296
+     */
2297
+    public function getRemoteApiFactory() {
2298
+        return $this->query(IApiFactory::class);
2299
+    }
2300
+
2301
+    /**
2302
+     * @return \OCP\Federation\ICloudFederationFactory
2303
+     * @deprecated
2304
+     */
2305
+    public function getCloudFederationFactory() {
2306
+        return $this->query(ICloudFederationFactory::class);
2307
+    }
2308
+
2309
+    /**
2310
+     * @return \OCP\Remote\IInstanceFactory
2311
+     * @deprecated
2312
+     */
2313
+    public function getRemoteInstanceFactory() {
2314
+        return $this->query(IInstanceFactory::class);
2315
+    }
2316
+
2317
+    /**
2318
+     * @return IStorageFactory
2319
+     * @deprecated
2320
+     */
2321
+    public function getStorageFactory() {
2322
+        return $this->query(IStorageFactory::class);
2323
+    }
2324
+
2325
+    /**
2326
+     * Get the Preview GeneratorHelper
2327
+     *
2328
+     * @return GeneratorHelper
2329
+     * @since 17.0.0
2330
+     * @deprecated
2331
+     */
2332
+    public function getGeneratorHelper() {
2333
+        return $this->query(\OC\Preview\GeneratorHelper::class);
2334
+    }
2335
+
2336
+    private function registerDeprecatedAlias(string $alias, string $target) {
2337
+        $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2338
+            try {
2339
+                /** @var ILogger $logger */
2340
+                $logger = $container->get(ILogger::class);
2341
+                $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2342
+            } catch (ContainerExceptionInterface $e) {
2343
+                // Could not get logger. Continue
2344
+            }
2345
+
2346
+            return $container->get($target);
2347
+        }, false);
2348
+    }
2349 2349
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@
 block discarded – undo
27 27
 
28 28
 class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage {
29 29
 
30
-	/** @var string */
31
-	private $internalId;
30
+    /** @var string */
31
+    private $internalId;
32 32
 
33
-	public function __construct($params) {
34
-		if (!isset($params['internal-id'])) {
35
-			throw new \Exception('missing id in parameters');
36
-		}
37
-		$this->internalId = (string)$params['internal-id'];
38
-		parent::__construct($params);
39
-	}
33
+    public function __construct($params) {
34
+        if (!isset($params['internal-id'])) {
35
+            throw new \Exception('missing id in parameters');
36
+        }
37
+        $this->internalId = (string)$params['internal-id'];
38
+        parent::__construct($params);
39
+    }
40 40
 
41
-	public function getId() {
42
-		return 'object::appdata::preview:' . $this->internalId;
43
-	}
41
+    public function getId() {
42
+        return 'object::appdata::preview:' . $this->internalId;
43
+    }
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,11 +34,11 @@
 block discarded – undo
34 34
 		if (!isset($params['internal-id'])) {
35 35
 			throw new \Exception('missing id in parameters');
36 36
 		}
37
-		$this->internalId = (string)$params['internal-id'];
37
+		$this->internalId = (string) $params['internal-id'];
38 38
 		parent::__construct($params);
39 39
 	}
40 40
 
41 41
 	public function getId() {
42
-		return 'object::appdata::preview:' . $this->internalId;
42
+		return 'object::appdata::preview:'.$this->internalId;
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -37,114 +37,114 @@
 block discarded – undo
37 37
  * Mount provider for object store app data folder for previews
38 38
  */
39 39
 class ObjectStorePreviewCacheMountProvider implements IRootMountProvider {
40
-	/** @var ILogger */
41
-	private $logger;
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	public function __construct(ILogger $logger, IConfig $config) {
46
-		$this->logger = $logger;
47
-		$this->config = $config;
48
-	}
49
-
50
-	/**
51
-	 * @return MountPoint[]
52
-	 * @throws \Exception
53
-	 */
54
-	public function getRootMounts(IStorageFactory $loader): array {
55
-		if (!is_array($this->config->getSystemValue('objectstore_multibucket'))) {
56
-			return [];
57
-		}
58
-		if ($this->config->getSystemValue('objectstore.multibucket.preview-distribution', false) !== true) {
59
-			return [];
60
-		}
61
-
62
-		$instanceId = $this->config->getSystemValueString('instanceid', '');
63
-		$mountPoints = [];
64
-		$directoryRange = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
65
-		$i = 0;
66
-		foreach ($directoryRange as $parent) {
67
-			foreach ($directoryRange as $child) {
68
-				$mountPoints[] = new MountPoint(
69
-					AppdataPreviewObjectStoreStorage::class,
70
-					'/appdata_' . $instanceId . '/preview/' . $parent . '/' . $child,
71
-					$this->getMultiBucketObjectStore($i),
72
-					$loader
73
-				);
74
-				$i++;
75
-			}
76
-		}
77
-
78
-		$rootStorageArguments = $this->getMultiBucketObjectStoreForRoot();
79
-		$fakeRootStorage = new ObjectStoreStorage($rootStorageArguments);
80
-		$fakeRootStorageJail = new Jail([
81
-			'storage' => $fakeRootStorage,
82
-			'root' => '/appdata_' . $instanceId . '/preview',
83
-		]);
84
-
85
-		// add a fallback location to be able to fetch existing previews from the old bucket
86
-		$mountPoints[] = new MountPoint(
87
-			$fakeRootStorageJail,
88
-			'/appdata_' . $instanceId . '/preview/old-multibucket',
89
-			null,
90
-			$loader
91
-		);
92
-
93
-		return $mountPoints;
94
-	}
95
-
96
-	protected function getMultiBucketObjectStore(int $number): array {
97
-		$config = $this->config->getSystemValue('objectstore_multibucket');
98
-
99
-		// sanity checks
100
-		if (empty($config['class'])) {
101
-			$this->logger->error('No class given for objectstore', ['app' => 'files']);
102
-		}
103
-		if (!isset($config['arguments'])) {
104
-			$config['arguments'] = [];
105
-		}
106
-
107
-		/*
40
+    /** @var ILogger */
41
+    private $logger;
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    public function __construct(ILogger $logger, IConfig $config) {
46
+        $this->logger = $logger;
47
+        $this->config = $config;
48
+    }
49
+
50
+    /**
51
+     * @return MountPoint[]
52
+     * @throws \Exception
53
+     */
54
+    public function getRootMounts(IStorageFactory $loader): array {
55
+        if (!is_array($this->config->getSystemValue('objectstore_multibucket'))) {
56
+            return [];
57
+        }
58
+        if ($this->config->getSystemValue('objectstore.multibucket.preview-distribution', false) !== true) {
59
+            return [];
60
+        }
61
+
62
+        $instanceId = $this->config->getSystemValueString('instanceid', '');
63
+        $mountPoints = [];
64
+        $directoryRange = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
65
+        $i = 0;
66
+        foreach ($directoryRange as $parent) {
67
+            foreach ($directoryRange as $child) {
68
+                $mountPoints[] = new MountPoint(
69
+                    AppdataPreviewObjectStoreStorage::class,
70
+                    '/appdata_' . $instanceId . '/preview/' . $parent . '/' . $child,
71
+                    $this->getMultiBucketObjectStore($i),
72
+                    $loader
73
+                );
74
+                $i++;
75
+            }
76
+        }
77
+
78
+        $rootStorageArguments = $this->getMultiBucketObjectStoreForRoot();
79
+        $fakeRootStorage = new ObjectStoreStorage($rootStorageArguments);
80
+        $fakeRootStorageJail = new Jail([
81
+            'storage' => $fakeRootStorage,
82
+            'root' => '/appdata_' . $instanceId . '/preview',
83
+        ]);
84
+
85
+        // add a fallback location to be able to fetch existing previews from the old bucket
86
+        $mountPoints[] = new MountPoint(
87
+            $fakeRootStorageJail,
88
+            '/appdata_' . $instanceId . '/preview/old-multibucket',
89
+            null,
90
+            $loader
91
+        );
92
+
93
+        return $mountPoints;
94
+    }
95
+
96
+    protected function getMultiBucketObjectStore(int $number): array {
97
+        $config = $this->config->getSystemValue('objectstore_multibucket');
98
+
99
+        // sanity checks
100
+        if (empty($config['class'])) {
101
+            $this->logger->error('No class given for objectstore', ['app' => 'files']);
102
+        }
103
+        if (!isset($config['arguments'])) {
104
+            $config['arguments'] = [];
105
+        }
106
+
107
+        /*
108 108
 		 * Use any provided bucket argument as prefix
109 109
 		 * and add the mapping from parent/child => bucket
110 110
 		 */
111
-		if (!isset($config['arguments']['bucket'])) {
112
-			$config['arguments']['bucket'] = '';
113
-		}
111
+        if (!isset($config['arguments']['bucket'])) {
112
+            $config['arguments']['bucket'] = '';
113
+        }
114 114
 
115
-		$config['arguments']['bucket'] .= "-preview-$number";
115
+        $config['arguments']['bucket'] .= "-preview-$number";
116 116
 
117
-		// instantiate object store implementation
118
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
117
+        // instantiate object store implementation
118
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
119 119
 
120
-		$config['arguments']['internal-id'] = $number;
120
+        $config['arguments']['internal-id'] = $number;
121 121
 
122
-		return $config['arguments'];
123
-	}
122
+        return $config['arguments'];
123
+    }
124 124
 
125
-	protected function getMultiBucketObjectStoreForRoot(): array {
126
-		$config = $this->config->getSystemValue('objectstore_multibucket');
125
+    protected function getMultiBucketObjectStoreForRoot(): array {
126
+        $config = $this->config->getSystemValue('objectstore_multibucket');
127 127
 
128
-		// sanity checks
129
-		if (empty($config['class'])) {
130
-			$this->logger->error('No class given for objectstore', ['app' => 'files']);
131
-		}
132
-		if (!isset($config['arguments'])) {
133
-			$config['arguments'] = [];
134
-		}
128
+        // sanity checks
129
+        if (empty($config['class'])) {
130
+            $this->logger->error('No class given for objectstore', ['app' => 'files']);
131
+        }
132
+        if (!isset($config['arguments'])) {
133
+            $config['arguments'] = [];
134
+        }
135 135
 
136
-		/*
136
+        /*
137 137
 		 * Use any provided bucket argument as prefix
138 138
 		 * and add the mapping from parent/child => bucket
139 139
 		 */
140
-		if (!isset($config['arguments']['bucket'])) {
141
-			$config['arguments']['bucket'] = '';
142
-		}
143
-		$config['arguments']['bucket'] .= '0';
140
+        if (!isset($config['arguments']['bucket'])) {
141
+            $config['arguments']['bucket'] = '';
142
+        }
143
+        $config['arguments']['bucket'] .= '0';
144 144
 
145
-		// instantiate object store implementation
146
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
145
+        // instantiate object store implementation
146
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
147 147
 
148
-		return $config['arguments'];
149
-	}
148
+        return $config['arguments'];
149
+    }
150 150
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 			foreach ($directoryRange as $child) {
68 68
 				$mountPoints[] = new MountPoint(
69 69
 					AppdataPreviewObjectStoreStorage::class,
70
-					'/appdata_' . $instanceId . '/preview/' . $parent . '/' . $child,
70
+					'/appdata_'.$instanceId.'/preview/'.$parent.'/'.$child,
71 71
 					$this->getMultiBucketObjectStore($i),
72 72
 					$loader
73 73
 				);
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
 		$fakeRootStorage = new ObjectStoreStorage($rootStorageArguments);
80 80
 		$fakeRootStorageJail = new Jail([
81 81
 			'storage' => $fakeRootStorage,
82
-			'root' => '/appdata_' . $instanceId . '/preview',
82
+			'root' => '/appdata_'.$instanceId.'/preview',
83 83
 		]);
84 84
 
85 85
 		// add a fallback location to be able to fetch existing previews from the old bucket
86 86
 		$mountPoints[] = new MountPoint(
87 87
 			$fakeRootStorageJail,
88
-			'/appdata_' . $instanceId . '/preview/old-multibucket',
88
+			'/appdata_'.$instanceId.'/preview/old-multibucket',
89 89
 			null,
90 90
 			$loader
91 91
 		);
Please login to merge, or discard this patch.
lib/private/Files/Config/MountProviderCollection.php 2 patches
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -38,183 +38,183 @@
 block discarded – undo
38 38
 use OCP\IUser;
39 39
 
40 40
 class MountProviderCollection implements IMountProviderCollection, Emitter {
41
-	use EmitterTrait;
42
-
43
-	/**
44
-	 * @var \OCP\Files\Config\IHomeMountProvider[]
45
-	 */
46
-	private $homeProviders = [];
47
-
48
-	/**
49
-	 * @var \OCP\Files\Config\IMountProvider[]
50
-	 */
51
-	private $providers = [];
52
-
53
-	/** @var \OCP\Files\Config\IRootMountProvider[] */
54
-	private $rootProviders = [];
55
-
56
-	/**
57
-	 * @var \OCP\Files\Storage\IStorageFactory
58
-	 */
59
-	private $loader;
60
-
61
-	/**
62
-	 * @var \OCP\Files\Config\IUserMountCache
63
-	 */
64
-	private $mountCache;
65
-
66
-	/** @var callable[] */
67
-	private $mountFilters = [];
68
-
69
-	/**
70
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
71
-	 * @param IUserMountCache $mountCache
72
-	 */
73
-	public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
74
-		$this->loader = $loader;
75
-		$this->mountCache = $mountCache;
76
-	}
77
-
78
-	/**
79
-	 * Get all configured mount points for the user
80
-	 *
81
-	 * @param \OCP\IUser $user
82
-	 * @return \OCP\Files\Mount\IMountPoint[]
83
-	 */
84
-	public function getMountsForUser(IUser $user) {
85
-		$loader = $this->loader;
86
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
87
-			return $provider->getMountsForUser($user, $loader);
88
-		}, $this->providers);
89
-		$mounts = array_filter($mounts, function ($result) {
90
-			return is_array($result);
91
-		});
92
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
93
-			return array_merge($mounts, $providerMounts);
94
-		}, []);
95
-		return $this->filterMounts($user, $mounts);
96
-	}
97
-
98
-	public function addMountForUser(IUser $user, IMountManager $mountManager) {
99
-		// shared mount provider gets to go last since it needs to know existing files
100
-		// to check for name collisions
101
-		$firstMounts = [];
102
-		$firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
103
-			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
104
-		});
105
-		$lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
106
-			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
107
-		});
108
-		foreach ($firstProviders as $provider) {
109
-			$mounts = $provider->getMountsForUser($user, $this->loader);
110
-			if (is_array($mounts)) {
111
-				$firstMounts = array_merge($firstMounts, $mounts);
112
-			}
113
-		}
114
-		$firstMounts = $this->filterMounts($user, $firstMounts);
115
-		array_walk($firstMounts, [$mountManager, 'addMount']);
116
-
117
-		$lateMounts = [];
118
-		foreach ($lastProviders as $provider) {
119
-			$mounts = $provider->getMountsForUser($user, $this->loader);
120
-			if (is_array($mounts)) {
121
-				$lateMounts = array_merge($lateMounts, $mounts);
122
-			}
123
-		}
124
-
125
-		$lateMounts = $this->filterMounts($user, $lateMounts);
126
-		array_walk($lateMounts, [$mountManager, 'addMount']);
127
-
128
-		return array_merge($lateMounts, $firstMounts);
129
-	}
130
-
131
-	/**
132
-	 * Get the configured home mount for this user
133
-	 *
134
-	 * @param \OCP\IUser $user
135
-	 * @return \OCP\Files\Mount\IMountPoint
136
-	 * @since 9.1.0
137
-	 */
138
-	public function getHomeMountForUser(IUser $user) {
139
-		/** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
140
-		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
141
-		foreach ($providers as $homeProvider) {
142
-			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
143
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
144
-				return $mount;
145
-			}
146
-		}
147
-		throw new \Exception('No home storage configured for user ' . $user);
148
-	}
149
-
150
-	/**
151
-	 * Add a provider for mount points
152
-	 *
153
-	 * @param \OCP\Files\Config\IMountProvider $provider
154
-	 */
155
-	public function registerProvider(IMountProvider $provider) {
156
-		$this->providers[] = $provider;
157
-
158
-		$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
159
-	}
160
-
161
-	public function registerMountFilter(callable $filter) {
162
-		$this->mountFilters[] = $filter;
163
-	}
164
-
165
-	private function filterMounts(IUser $user, array $mountPoints) {
166
-		return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
167
-			foreach ($this->mountFilters as $filter) {
168
-				if ($filter($mountPoint, $user) === false) {
169
-					return false;
170
-				}
171
-			}
172
-			return true;
173
-		});
174
-	}
175
-
176
-	/**
177
-	 * Add a provider for home mount points
178
-	 *
179
-	 * @param \OCP\Files\Config\IHomeMountProvider $provider
180
-	 * @since 9.1.0
181
-	 */
182
-	public function registerHomeProvider(IHomeMountProvider $provider) {
183
-		$this->homeProviders[] = $provider;
184
-		$this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
185
-	}
186
-
187
-	/**
188
-	 * Cache mounts for user
189
-	 *
190
-	 * @param IUser $user
191
-	 * @param IMountPoint[] $mountPoints
192
-	 */
193
-	public function registerMounts(IUser $user, array $mountPoints) {
194
-		$this->mountCache->registerMounts($user, $mountPoints);
195
-	}
196
-
197
-	/**
198
-	 * Get the mount cache which can be used to search for mounts without setting up the filesystem
199
-	 *
200
-	 * @return IUserMountCache
201
-	 */
202
-	public function getMountCache() {
203
-		return $this->mountCache;
204
-	}
205
-
206
-	public function registerRootProvider(IRootMountProvider $provider) {
207
-		$this->rootProviders[] = $provider;
208
-	}
209
-
210
-	public function getRootMounts(): array {
211
-		$loader = $this->loader;
212
-		$mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
213
-			return $provider->getRootMounts($loader);
214
-		}, $this->rootProviders);
215
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
216
-			return array_merge($mounts, $providerMounts);
217
-		}, []);
218
-		return $mounts;
219
-	}
41
+    use EmitterTrait;
42
+
43
+    /**
44
+     * @var \OCP\Files\Config\IHomeMountProvider[]
45
+     */
46
+    private $homeProviders = [];
47
+
48
+    /**
49
+     * @var \OCP\Files\Config\IMountProvider[]
50
+     */
51
+    private $providers = [];
52
+
53
+    /** @var \OCP\Files\Config\IRootMountProvider[] */
54
+    private $rootProviders = [];
55
+
56
+    /**
57
+     * @var \OCP\Files\Storage\IStorageFactory
58
+     */
59
+    private $loader;
60
+
61
+    /**
62
+     * @var \OCP\Files\Config\IUserMountCache
63
+     */
64
+    private $mountCache;
65
+
66
+    /** @var callable[] */
67
+    private $mountFilters = [];
68
+
69
+    /**
70
+     * @param \OCP\Files\Storage\IStorageFactory $loader
71
+     * @param IUserMountCache $mountCache
72
+     */
73
+    public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
74
+        $this->loader = $loader;
75
+        $this->mountCache = $mountCache;
76
+    }
77
+
78
+    /**
79
+     * Get all configured mount points for the user
80
+     *
81
+     * @param \OCP\IUser $user
82
+     * @return \OCP\Files\Mount\IMountPoint[]
83
+     */
84
+    public function getMountsForUser(IUser $user) {
85
+        $loader = $this->loader;
86
+        $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
87
+            return $provider->getMountsForUser($user, $loader);
88
+        }, $this->providers);
89
+        $mounts = array_filter($mounts, function ($result) {
90
+            return is_array($result);
91
+        });
92
+        $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
93
+            return array_merge($mounts, $providerMounts);
94
+        }, []);
95
+        return $this->filterMounts($user, $mounts);
96
+    }
97
+
98
+    public function addMountForUser(IUser $user, IMountManager $mountManager) {
99
+        // shared mount provider gets to go last since it needs to know existing files
100
+        // to check for name collisions
101
+        $firstMounts = [];
102
+        $firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
103
+            return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
104
+        });
105
+        $lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
106
+            return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
107
+        });
108
+        foreach ($firstProviders as $provider) {
109
+            $mounts = $provider->getMountsForUser($user, $this->loader);
110
+            if (is_array($mounts)) {
111
+                $firstMounts = array_merge($firstMounts, $mounts);
112
+            }
113
+        }
114
+        $firstMounts = $this->filterMounts($user, $firstMounts);
115
+        array_walk($firstMounts, [$mountManager, 'addMount']);
116
+
117
+        $lateMounts = [];
118
+        foreach ($lastProviders as $provider) {
119
+            $mounts = $provider->getMountsForUser($user, $this->loader);
120
+            if (is_array($mounts)) {
121
+                $lateMounts = array_merge($lateMounts, $mounts);
122
+            }
123
+        }
124
+
125
+        $lateMounts = $this->filterMounts($user, $lateMounts);
126
+        array_walk($lateMounts, [$mountManager, 'addMount']);
127
+
128
+        return array_merge($lateMounts, $firstMounts);
129
+    }
130
+
131
+    /**
132
+     * Get the configured home mount for this user
133
+     *
134
+     * @param \OCP\IUser $user
135
+     * @return \OCP\Files\Mount\IMountPoint
136
+     * @since 9.1.0
137
+     */
138
+    public function getHomeMountForUser(IUser $user) {
139
+        /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
140
+        $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
141
+        foreach ($providers as $homeProvider) {
142
+            if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
143
+                $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
144
+                return $mount;
145
+            }
146
+        }
147
+        throw new \Exception('No home storage configured for user ' . $user);
148
+    }
149
+
150
+    /**
151
+     * Add a provider for mount points
152
+     *
153
+     * @param \OCP\Files\Config\IMountProvider $provider
154
+     */
155
+    public function registerProvider(IMountProvider $provider) {
156
+        $this->providers[] = $provider;
157
+
158
+        $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
159
+    }
160
+
161
+    public function registerMountFilter(callable $filter) {
162
+        $this->mountFilters[] = $filter;
163
+    }
164
+
165
+    private function filterMounts(IUser $user, array $mountPoints) {
166
+        return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
167
+            foreach ($this->mountFilters as $filter) {
168
+                if ($filter($mountPoint, $user) === false) {
169
+                    return false;
170
+                }
171
+            }
172
+            return true;
173
+        });
174
+    }
175
+
176
+    /**
177
+     * Add a provider for home mount points
178
+     *
179
+     * @param \OCP\Files\Config\IHomeMountProvider $provider
180
+     * @since 9.1.0
181
+     */
182
+    public function registerHomeProvider(IHomeMountProvider $provider) {
183
+        $this->homeProviders[] = $provider;
184
+        $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
185
+    }
186
+
187
+    /**
188
+     * Cache mounts for user
189
+     *
190
+     * @param IUser $user
191
+     * @param IMountPoint[] $mountPoints
192
+     */
193
+    public function registerMounts(IUser $user, array $mountPoints) {
194
+        $this->mountCache->registerMounts($user, $mountPoints);
195
+    }
196
+
197
+    /**
198
+     * Get the mount cache which can be used to search for mounts without setting up the filesystem
199
+     *
200
+     * @return IUserMountCache
201
+     */
202
+    public function getMountCache() {
203
+        return $this->mountCache;
204
+    }
205
+
206
+    public function registerRootProvider(IRootMountProvider $provider) {
207
+        $this->rootProviders[] = $provider;
208
+    }
209
+
210
+    public function getRootMounts(): array {
211
+        $loader = $this->loader;
212
+        $mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
213
+            return $provider->getRootMounts($loader);
214
+        }, $this->rootProviders);
215
+        $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
216
+            return array_merge($mounts, $providerMounts);
217
+        }, []);
218
+        return $mounts;
219
+    }
220 220
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function getMountsForUser(IUser $user) {
85 85
 		$loader = $this->loader;
86
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
86
+		$mounts = array_map(function(IMountProvider $provider) use ($user, $loader) {
87 87
 			return $provider->getMountsForUser($user, $loader);
88 88
 		}, $this->providers);
89
-		$mounts = array_filter($mounts, function ($result) {
89
+		$mounts = array_filter($mounts, function($result) {
90 90
 			return is_array($result);
91 91
 		});
92
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
92
+		$mounts = array_reduce($mounts, function(array $mounts, array $providerMounts) {
93 93
 			return array_merge($mounts, $providerMounts);
94 94
 		}, []);
95 95
 		return $this->filterMounts($user, $mounts);
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
 		// shared mount provider gets to go last since it needs to know existing files
100 100
 		// to check for name collisions
101 101
 		$firstMounts = [];
102
-		$firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
102
+		$firstProviders = array_filter($this->providers, function(IMountProvider $provider) {
103 103
 			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
104 104
 		});
105
-		$lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
105
+		$lastProviders = array_filter($this->providers, function(IMountProvider $provider) {
106 106
 			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
107 107
 		});
108 108
 		foreach ($firstProviders as $provider) {
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
141 141
 		foreach ($providers as $homeProvider) {
142 142
 			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
143
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
143
+				$mount->setMountPoint('/'.$user->getUID()); //make sure the mountpoint is what we expect
144 144
 				return $mount;
145 145
 			}
146 146
 		}
147
-		throw new \Exception('No home storage configured for user ' . $user);
147
+		throw new \Exception('No home storage configured for user '.$user);
148 148
 	}
149 149
 
150 150
 	/**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	}
164 164
 
165 165
 	private function filterMounts(IUser $user, array $mountPoints) {
166
-		return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
166
+		return array_filter($mountPoints, function(IMountPoint $mountPoint) use ($user) {
167 167
 			foreach ($this->mountFilters as $filter) {
168 168
 				if ($filter($mountPoint, $user) === false) {
169 169
 					return false;
@@ -209,10 +209,10 @@  discard block
 block discarded – undo
209 209
 
210 210
 	public function getRootMounts(): array {
211 211
 		$loader = $this->loader;
212
-		$mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
212
+		$mounts = array_map(function(IRootMountProvider $provider) use ($loader) {
213 213
 			return $provider->getRootMounts($loader);
214 214
 		}, $this->rootProviders);
215
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
215
+		$mounts = array_reduce($mounts, function(array $mounts, array $providerMounts) {
216 216
 			return array_merge($mounts, $providerMounts);
217 217
 		}, []);
218 218
 		return $mounts;
Please login to merge, or discard this patch.
lib/private/legacy/OC_Util.php 1 patch
Indentation   +1405 added lines, -1405 removed lines patch added patch discarded remove patch
@@ -71,1414 +71,1414 @@
 block discarded – undo
71 71
 use OCP\IUserSession;
72 72
 
73 73
 class OC_Util {
74
-	public static $scripts = [];
75
-	public static $styles = [];
76
-	public static $headers = [];
77
-	private static $rootMounted = false;
78
-	private static $fsSetup = false;
79
-
80
-	/** @var array Local cache of version.php */
81
-	private static $versionCache = null;
82
-
83
-	protected static function getAppManager() {
84
-		return \OC::$server->getAppManager();
85
-	}
86
-
87
-	private static function initLocalStorageRootFS() {
88
-		// mount local file backend as root
89
-		$configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data");
90
-		//first set up the local "root" storage
91
-		\OC\Files\Filesystem::initMountManager();
92
-		if (!self::$rootMounted) {
93
-			\OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/');
94
-			self::$rootMounted = true;
95
-		}
96
-	}
97
-
98
-	/**
99
-	 * mounting an object storage as the root fs will in essence remove the
100
-	 * necessity of a data folder being present.
101
-	 * TODO make home storage aware of this and use the object storage instead of local disk access
102
-	 *
103
-	 * @param array $config containing 'class' and optional 'arguments'
104
-	 * @suppress PhanDeprecatedFunction
105
-	 */
106
-	private static function initObjectStoreRootFS($config) {
107
-		// check misconfiguration
108
-		if (empty($config['class'])) {
109
-			\OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
110
-		}
111
-		if (!isset($config['arguments'])) {
112
-			$config['arguments'] = [];
113
-		}
114
-
115
-		// instantiate object store implementation
116
-		$name = $config['class'];
117
-		if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
118
-			$segments = explode('\\', $name);
119
-			OC_App::loadApp(strtolower($segments[1]));
120
-		}
121
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
122
-		// mount with plain / root object store implementation
123
-		$config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
124
-
125
-		// mount object storage as root
126
-		\OC\Files\Filesystem::initMountManager();
127
-		if (!self::$rootMounted) {
128
-			\OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
129
-			self::$rootMounted = true;
130
-		}
131
-	}
132
-
133
-	/**
134
-	 * mounting an object storage as the root fs will in essence remove the
135
-	 * necessity of a data folder being present.
136
-	 *
137
-	 * @param array $config containing 'class' and optional 'arguments'
138
-	 * @suppress PhanDeprecatedFunction
139
-	 */
140
-	private static function initObjectStoreMultibucketRootFS($config) {
141
-		// check misconfiguration
142
-		if (empty($config['class'])) {
143
-			\OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
144
-		}
145
-		if (!isset($config['arguments'])) {
146
-			$config['arguments'] = [];
147
-		}
148
-
149
-		// instantiate object store implementation
150
-		$name = $config['class'];
151
-		if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
152
-			$segments = explode('\\', $name);
153
-			OC_App::loadApp(strtolower($segments[1]));
154
-		}
155
-
156
-		if (!isset($config['arguments']['bucket'])) {
157
-			$config['arguments']['bucket'] = '';
158
-		}
159
-		// put the root FS always in first bucket for multibucket configuration
160
-		$config['arguments']['bucket'] .= '0';
161
-
162
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
163
-		// mount with plain / root object store implementation
164
-		$config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
165
-
166
-		// mount object storage as root
167
-		\OC\Files\Filesystem::initMountManager();
168
-		if (!self::$rootMounted) {
169
-			\OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
170
-			self::$rootMounted = true;
171
-		}
172
-	}
173
-
174
-	/**
175
-	 * Can be set up
176
-	 *
177
-	 * @param string $user
178
-	 * @return boolean
179
-	 * @description configure the initial filesystem based on the configuration
180
-	 * @suppress PhanDeprecatedFunction
181
-	 * @suppress PhanAccessMethodInternal
182
-	 */
183
-	public static function setupFS($user = '') {
184
-		//setting up the filesystem twice can only lead to trouble
185
-		if (self::$fsSetup) {
186
-			return false;
187
-		}
188
-
189
-		\OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
190
-
191
-		// If we are not forced to load a specific user we load the one that is logged in
192
-		if ($user === null) {
193
-			$user = '';
194
-		} elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
195
-			$user = OC_User::getUser();
196
-		}
197
-
198
-		// load all filesystem apps before, so no setup-hook gets lost
199
-		OC_App::loadApps(['filesystem']);
200
-
201
-		// the filesystem will finish when $user is not empty,
202
-		// mark fs setup here to avoid doing the setup from loading
203
-		// OC_Filesystem
204
-		if ($user != '') {
205
-			self::$fsSetup = true;
206
-		}
207
-
208
-		\OC\Files\Filesystem::initMountManager();
209
-
210
-		$prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
211
-		\OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
212
-			if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
213
-				/** @var \OC\Files\Storage\Common $storage */
214
-				$storage->setMountOptions($mount->getOptions());
215
-			}
216
-			return $storage;
217
-		});
218
-
219
-		\OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) {
220
-			if (!$mount->getOption('enable_sharing', true)) {
221
-				return new \OC\Files\Storage\Wrapper\PermissionsMask([
222
-					'storage' => $storage,
223
-					'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE
224
-				]);
225
-			}
226
-			return $storage;
227
-		});
228
-
229
-		// install storage availability wrapper, before most other wrappers
230
-		\OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) {
231
-			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
232
-				return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
233
-			}
234
-			return $storage;
235
-		});
236
-
237
-		\OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
238
-			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
239
-				return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]);
240
-			}
241
-			return $storage;
242
-		});
243
-
244
-		\OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
245
-			// set up quota for home storages, even for other users
246
-			// which can happen when using sharing
247
-
248
-			/**
249
-			 * @var \OC\Files\Storage\Storage $storage
250
-			 */
251
-			if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
252
-				|| $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
253
-			) {
254
-				/** @var \OC\Files\Storage\Home $storage */
255
-				if (is_object($storage->getUser())) {
256
-					$quota = OC_Util::getUserQuota($storage->getUser());
257
-					if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
258
-						return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']);
259
-					}
260
-				}
261
-			}
262
-
263
-			return $storage;
264
-		});
265
-
266
-		\OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) {
267
-			/*
74
+    public static $scripts = [];
75
+    public static $styles = [];
76
+    public static $headers = [];
77
+    private static $rootMounted = false;
78
+    private static $fsSetup = false;
79
+
80
+    /** @var array Local cache of version.php */
81
+    private static $versionCache = null;
82
+
83
+    protected static function getAppManager() {
84
+        return \OC::$server->getAppManager();
85
+    }
86
+
87
+    private static function initLocalStorageRootFS() {
88
+        // mount local file backend as root
89
+        $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data");
90
+        //first set up the local "root" storage
91
+        \OC\Files\Filesystem::initMountManager();
92
+        if (!self::$rootMounted) {
93
+            \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/');
94
+            self::$rootMounted = true;
95
+        }
96
+    }
97
+
98
+    /**
99
+     * mounting an object storage as the root fs will in essence remove the
100
+     * necessity of a data folder being present.
101
+     * TODO make home storage aware of this and use the object storage instead of local disk access
102
+     *
103
+     * @param array $config containing 'class' and optional 'arguments'
104
+     * @suppress PhanDeprecatedFunction
105
+     */
106
+    private static function initObjectStoreRootFS($config) {
107
+        // check misconfiguration
108
+        if (empty($config['class'])) {
109
+            \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
110
+        }
111
+        if (!isset($config['arguments'])) {
112
+            $config['arguments'] = [];
113
+        }
114
+
115
+        // instantiate object store implementation
116
+        $name = $config['class'];
117
+        if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
118
+            $segments = explode('\\', $name);
119
+            OC_App::loadApp(strtolower($segments[1]));
120
+        }
121
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
122
+        // mount with plain / root object store implementation
123
+        $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
124
+
125
+        // mount object storage as root
126
+        \OC\Files\Filesystem::initMountManager();
127
+        if (!self::$rootMounted) {
128
+            \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
129
+            self::$rootMounted = true;
130
+        }
131
+    }
132
+
133
+    /**
134
+     * mounting an object storage as the root fs will in essence remove the
135
+     * necessity of a data folder being present.
136
+     *
137
+     * @param array $config containing 'class' and optional 'arguments'
138
+     * @suppress PhanDeprecatedFunction
139
+     */
140
+    private static function initObjectStoreMultibucketRootFS($config) {
141
+        // check misconfiguration
142
+        if (empty($config['class'])) {
143
+            \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
144
+        }
145
+        if (!isset($config['arguments'])) {
146
+            $config['arguments'] = [];
147
+        }
148
+
149
+        // instantiate object store implementation
150
+        $name = $config['class'];
151
+        if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
152
+            $segments = explode('\\', $name);
153
+            OC_App::loadApp(strtolower($segments[1]));
154
+        }
155
+
156
+        if (!isset($config['arguments']['bucket'])) {
157
+            $config['arguments']['bucket'] = '';
158
+        }
159
+        // put the root FS always in first bucket for multibucket configuration
160
+        $config['arguments']['bucket'] .= '0';
161
+
162
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
163
+        // mount with plain / root object store implementation
164
+        $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage';
165
+
166
+        // mount object storage as root
167
+        \OC\Files\Filesystem::initMountManager();
168
+        if (!self::$rootMounted) {
169
+            \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/');
170
+            self::$rootMounted = true;
171
+        }
172
+    }
173
+
174
+    /**
175
+     * Can be set up
176
+     *
177
+     * @param string $user
178
+     * @return boolean
179
+     * @description configure the initial filesystem based on the configuration
180
+     * @suppress PhanDeprecatedFunction
181
+     * @suppress PhanAccessMethodInternal
182
+     */
183
+    public static function setupFS($user = '') {
184
+        //setting up the filesystem twice can only lead to trouble
185
+        if (self::$fsSetup) {
186
+            return false;
187
+        }
188
+
189
+        \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
190
+
191
+        // If we are not forced to load a specific user we load the one that is logged in
192
+        if ($user === null) {
193
+            $user = '';
194
+        } elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) {
195
+            $user = OC_User::getUser();
196
+        }
197
+
198
+        // load all filesystem apps before, so no setup-hook gets lost
199
+        OC_App::loadApps(['filesystem']);
200
+
201
+        // the filesystem will finish when $user is not empty,
202
+        // mark fs setup here to avoid doing the setup from loading
203
+        // OC_Filesystem
204
+        if ($user != '') {
205
+            self::$fsSetup = true;
206
+        }
207
+
208
+        \OC\Files\Filesystem::initMountManager();
209
+
210
+        $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
211
+        \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
212
+            if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
213
+                /** @var \OC\Files\Storage\Common $storage */
214
+                $storage->setMountOptions($mount->getOptions());
215
+            }
216
+            return $storage;
217
+        });
218
+
219
+        \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) {
220
+            if (!$mount->getOption('enable_sharing', true)) {
221
+                return new \OC\Files\Storage\Wrapper\PermissionsMask([
222
+                    'storage' => $storage,
223
+                    'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE
224
+                ]);
225
+            }
226
+            return $storage;
227
+        });
228
+
229
+        // install storage availability wrapper, before most other wrappers
230
+        \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) {
231
+            if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
232
+                return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
233
+            }
234
+            return $storage;
235
+        });
236
+
237
+        \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
238
+            if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
239
+                return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]);
240
+            }
241
+            return $storage;
242
+        });
243
+
244
+        \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
245
+            // set up quota for home storages, even for other users
246
+            // which can happen when using sharing
247
+
248
+            /**
249
+             * @var \OC\Files\Storage\Storage $storage
250
+             */
251
+            if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
252
+                || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
253
+            ) {
254
+                /** @var \OC\Files\Storage\Home $storage */
255
+                if (is_object($storage->getUser())) {
256
+                    $quota = OC_Util::getUserQuota($storage->getUser());
257
+                    if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
258
+                        return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']);
259
+                    }
260
+                }
261
+            }
262
+
263
+            return $storage;
264
+        });
265
+
266
+        \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) {
267
+            /*
268 268
 			 * Do not allow any operations that modify the storage
269 269
 			 */
270
-			if ($mount->getOption('readonly', false)) {
271
-				return new \OC\Files\Storage\Wrapper\PermissionsMask([
272
-					'storage' => $storage,
273
-					'mask' => \OCP\Constants::PERMISSION_ALL & ~(
274
-						\OCP\Constants::PERMISSION_UPDATE |
275
-						\OCP\Constants::PERMISSION_CREATE |
276
-						\OCP\Constants::PERMISSION_DELETE
277
-					),
278
-				]);
279
-			}
280
-			return $storage;
281
-		});
282
-
283
-		OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]);
284
-
285
-		\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
286
-
287
-		//check if we are using an object storage
288
-		$objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
289
-		$objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null);
290
-
291
-		// use the same order as in ObjectHomeMountProvider
292
-		if (isset($objectStoreMultibucket)) {
293
-			self::initObjectStoreMultibucketRootFS($objectStoreMultibucket);
294
-		} elseif (isset($objectStore)) {
295
-			self::initObjectStoreRootFS($objectStore);
296
-		} else {
297
-			self::initLocalStorageRootFS();
298
-		}
299
-
300
-		/** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */
301
-		$mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class);
302
-		/** @var \OCP\Files\Mount\IMountPoint[] $rootMountProviders */
303
-		$rootMountProviders = $mountProviderCollection->getRootMounts();
304
-
305
-		/** @var \OC\Files\Mount\Manager $mountManager */
306
-		$mountManager = \OC\Files\Filesystem::getMountManager();
307
-		foreach ($rootMountProviders as $rootMountProvider) {
308
-			$mountManager->addMount($rootMountProvider);
309
-		}
310
-
311
-		if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) {
312
-			\OC::$server->getEventLogger()->end('setup_fs');
313
-			return false;
314
-		}
315
-
316
-		//if we aren't logged in, there is no use to set up the filesystem
317
-		if ($user != "") {
318
-			$userDir = '/' . $user . '/files';
319
-
320
-			//jail the user into his "home" directory
321
-			\OC\Files\Filesystem::init($user, $userDir);
322
-
323
-			OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]);
324
-		}
325
-		\OC::$server->getEventLogger()->end('setup_fs');
326
-		return true;
327
-	}
328
-
329
-	/**
330
-	 * check if a password is required for each public link
331
-	 *
332
-	 * @return boolean
333
-	 * @suppress PhanDeprecatedFunction
334
-	 */
335
-	public static function isPublicLinkPasswordRequired() {
336
-		$enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no');
337
-		return $enforcePassword === 'yes';
338
-	}
339
-
340
-	/**
341
-	 * check if sharing is disabled for the current user
342
-	 * @param IConfig $config
343
-	 * @param IGroupManager $groupManager
344
-	 * @param IUser|null $user
345
-	 * @return bool
346
-	 */
347
-	public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
348
-		if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
349
-			$groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
350
-			$excludedGroups = json_decode($groupsList);
351
-			if (is_null($excludedGroups)) {
352
-				$excludedGroups = explode(',', $groupsList);
353
-				$newValue = json_encode($excludedGroups);
354
-				$config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
355
-			}
356
-			$usersGroups = $groupManager->getUserGroupIds($user);
357
-			if (!empty($usersGroups)) {
358
-				$remainingGroups = array_diff($usersGroups, $excludedGroups);
359
-				// if the user is only in groups which are disabled for sharing then
360
-				// sharing is also disabled for the user
361
-				if (empty($remainingGroups)) {
362
-					return true;
363
-				}
364
-			}
365
-		}
366
-		return false;
367
-	}
368
-
369
-	/**
370
-	 * check if share API enforces a default expire date
371
-	 *
372
-	 * @return boolean
373
-	 * @suppress PhanDeprecatedFunction
374
-	 */
375
-	public static function isDefaultExpireDateEnforced() {
376
-		$isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no');
377
-		$enforceDefaultExpireDate = false;
378
-		if ($isDefaultExpireDateEnabled === 'yes') {
379
-			$value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no');
380
-			$enforceDefaultExpireDate = $value === 'yes';
381
-		}
382
-
383
-		return $enforceDefaultExpireDate;
384
-	}
385
-
386
-	/**
387
-	 * Get the quota of a user
388
-	 *
389
-	 * @param IUser|null $user
390
-	 * @return float Quota bytes
391
-	 */
392
-	public static function getUserQuota(?IUser $user) {
393
-		if (is_null($user)) {
394
-			return \OCP\Files\FileInfo::SPACE_UNLIMITED;
395
-		}
396
-		$userQuota = $user->getQuota();
397
-		if ($userQuota === 'none') {
398
-			return \OCP\Files\FileInfo::SPACE_UNLIMITED;
399
-		}
400
-		return OC_Helper::computerFileSize($userQuota);
401
-	}
402
-
403
-	/**
404
-	 * copies the skeleton to the users /files
405
-	 *
406
-	 * @param string $userId
407
-	 * @param \OCP\Files\Folder $userDirectory
408
-	 * @throws \OCP\Files\NotFoundException
409
-	 * @throws \OCP\Files\NotPermittedException
410
-	 * @suppress PhanDeprecatedFunction
411
-	 */
412
-	public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
413
-		$plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
414
-		$userLang = \OC::$server->getL10NFactory()->findLanguage();
415
-		$skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory);
416
-
417
-		if (!file_exists($skeletonDirectory)) {
418
-			$dialectStart = strpos($userLang, '_');
419
-			if ($dialectStart !== false) {
420
-				$skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory);
421
-			}
422
-			if ($dialectStart === false || !file_exists($skeletonDirectory)) {
423
-				$skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory);
424
-			}
425
-			if (!file_exists($skeletonDirectory)) {
426
-				$skeletonDirectory = '';
427
-			}
428
-		}
429
-
430
-		$instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
431
-
432
-		if ($instanceId === null) {
433
-			throw new \RuntimeException('no instance id!');
434
-		}
435
-		$appdata = 'appdata_' . $instanceId;
436
-		if ($userId === $appdata) {
437
-			throw new \RuntimeException('username is reserved name: ' . $appdata);
438
-		}
439
-
440
-		if (!empty($skeletonDirectory)) {
441
-			\OCP\Util::writeLog(
442
-				'files_skeleton',
443
-				'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
444
-				ILogger::DEBUG
445
-			);
446
-			self::copyr($skeletonDirectory, $userDirectory);
447
-			// update the file cache
448
-			$userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
449
-		}
450
-	}
451
-
452
-	/**
453
-	 * copies a directory recursively by using streams
454
-	 *
455
-	 * @param string $source
456
-	 * @param \OCP\Files\Folder $target
457
-	 * @return void
458
-	 */
459
-	public static function copyr($source, \OCP\Files\Folder $target) {
460
-		$logger = \OC::$server->getLogger();
461
-
462
-		// Verify if folder exists
463
-		$dir = opendir($source);
464
-		if ($dir === false) {
465
-			$logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
466
-			return;
467
-		}
468
-
469
-		// Copy the files
470
-		while (false !== ($file = readdir($dir))) {
471
-			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
472
-				if (is_dir($source . '/' . $file)) {
473
-					$child = $target->newFolder($file);
474
-					self::copyr($source . '/' . $file, $child);
475
-				} else {
476
-					$child = $target->newFile($file);
477
-					$sourceStream = fopen($source . '/' . $file, 'r');
478
-					if ($sourceStream === false) {
479
-						$logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
480
-						closedir($dir);
481
-						return;
482
-					}
483
-					stream_copy_to_stream($sourceStream, $child->fopen('w'));
484
-				}
485
-			}
486
-		}
487
-		closedir($dir);
488
-	}
489
-
490
-	/**
491
-	 * @return void
492
-	 * @suppress PhanUndeclaredMethod
493
-	 */
494
-	public static function tearDownFS() {
495
-		\OC\Files\Filesystem::tearDown();
496
-		\OC::$server->getRootFolder()->clearCache();
497
-		self::$fsSetup = false;
498
-		self::$rootMounted = false;
499
-	}
500
-
501
-	/**
502
-	 * get the current installed version of ownCloud
503
-	 *
504
-	 * @return array
505
-	 */
506
-	public static function getVersion() {
507
-		OC_Util::loadVersion();
508
-		return self::$versionCache['OC_Version'];
509
-	}
510
-
511
-	/**
512
-	 * get the current installed version string of ownCloud
513
-	 *
514
-	 * @return string
515
-	 */
516
-	public static function getVersionString() {
517
-		OC_Util::loadVersion();
518
-		return self::$versionCache['OC_VersionString'];
519
-	}
520
-
521
-	/**
522
-	 * @deprecated the value is of no use anymore
523
-	 * @return string
524
-	 */
525
-	public static function getEditionString() {
526
-		return '';
527
-	}
528
-
529
-	/**
530
-	 * @description get the update channel of the current installed of ownCloud.
531
-	 * @return string
532
-	 */
533
-	public static function getChannel() {
534
-		OC_Util::loadVersion();
535
-		return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']);
536
-	}
537
-
538
-	/**
539
-	 * @description get the build number of the current installed of ownCloud.
540
-	 * @return string
541
-	 */
542
-	public static function getBuild() {
543
-		OC_Util::loadVersion();
544
-		return self::$versionCache['OC_Build'];
545
-	}
546
-
547
-	/**
548
-	 * @description load the version.php into the session as cache
549
-	 * @suppress PhanUndeclaredVariable
550
-	 */
551
-	private static function loadVersion() {
552
-		if (self::$versionCache !== null) {
553
-			return;
554
-		}
555
-
556
-		$timestamp = filemtime(OC::$SERVERROOT . '/version.php');
557
-		require OC::$SERVERROOT . '/version.php';
558
-		/** @var $timestamp int */
559
-		self::$versionCache['OC_Version_Timestamp'] = $timestamp;
560
-		/** @var $OC_Version string */
561
-		self::$versionCache['OC_Version'] = $OC_Version;
562
-		/** @var $OC_VersionString string */
563
-		self::$versionCache['OC_VersionString'] = $OC_VersionString;
564
-		/** @var $OC_Build string */
565
-		self::$versionCache['OC_Build'] = $OC_Build;
566
-
567
-		/** @var $OC_Channel string */
568
-		self::$versionCache['OC_Channel'] = $OC_Channel;
569
-	}
570
-
571
-	/**
572
-	 * generates a path for JS/CSS files. If no application is provided it will create the path for core.
573
-	 *
574
-	 * @param string $application application to get the files from
575
-	 * @param string $directory directory within this application (css, js, vendor, etc)
576
-	 * @param string $file the file inside of the above folder
577
-	 * @return string the path
578
-	 */
579
-	private static function generatePath($application, $directory, $file) {
580
-		if (is_null($file)) {
581
-			$file = $application;
582
-			$application = "";
583
-		}
584
-		if (!empty($application)) {
585
-			return "$application/$directory/$file";
586
-		} else {
587
-			return "$directory/$file";
588
-		}
589
-	}
590
-
591
-	/**
592
-	 * add a javascript file
593
-	 *
594
-	 * @param string $application application id
595
-	 * @param string|null $file filename
596
-	 * @param bool $prepend prepend the Script to the beginning of the list
597
-	 * @return void
598
-	 */
599
-	public static function addScript($application, $file = null, $prepend = false) {
600
-		$path = OC_Util::generatePath($application, 'js', $file);
601
-
602
-		// core js files need separate handling
603
-		if ($application !== 'core' && $file !== null) {
604
-			self::addTranslations($application);
605
-		}
606
-		self::addExternalResource($application, $prepend, $path, "script");
607
-	}
608
-
609
-	/**
610
-	 * add a javascript file from the vendor sub folder
611
-	 *
612
-	 * @param string $application application id
613
-	 * @param string|null $file filename
614
-	 * @param bool $prepend prepend the Script to the beginning of the list
615
-	 * @return void
616
-	 */
617
-	public static function addVendorScript($application, $file = null, $prepend = false) {
618
-		$path = OC_Util::generatePath($application, 'vendor', $file);
619
-		self::addExternalResource($application, $prepend, $path, "script");
620
-	}
621
-
622
-	/**
623
-	 * add a translation JS file
624
-	 *
625
-	 * @param string $application application id
626
-	 * @param string|null $languageCode language code, defaults to the current language
627
-	 * @param bool|null $prepend prepend the Script to the beginning of the list
628
-	 */
629
-	public static function addTranslations($application, $languageCode = null, $prepend = false) {
630
-		if (is_null($languageCode)) {
631
-			$languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
632
-		}
633
-		if (!empty($application)) {
634
-			$path = "$application/l10n/$languageCode";
635
-		} else {
636
-			$path = "l10n/$languageCode";
637
-		}
638
-		self::addExternalResource($application, $prepend, $path, "script");
639
-	}
640
-
641
-	/**
642
-	 * add a css file
643
-	 *
644
-	 * @param string $application application id
645
-	 * @param string|null $file filename
646
-	 * @param bool $prepend prepend the Style to the beginning of the list
647
-	 * @return void
648
-	 */
649
-	public static function addStyle($application, $file = null, $prepend = false) {
650
-		$path = OC_Util::generatePath($application, 'css', $file);
651
-		self::addExternalResource($application, $prepend, $path, "style");
652
-	}
653
-
654
-	/**
655
-	 * add a css file from the vendor sub folder
656
-	 *
657
-	 * @param string $application application id
658
-	 * @param string|null $file filename
659
-	 * @param bool $prepend prepend the Style to the beginning of the list
660
-	 * @return void
661
-	 */
662
-	public static function addVendorStyle($application, $file = null, $prepend = false) {
663
-		$path = OC_Util::generatePath($application, 'vendor', $file);
664
-		self::addExternalResource($application, $prepend, $path, "style");
665
-	}
666
-
667
-	/**
668
-	 * add an external resource css/js file
669
-	 *
670
-	 * @param string $application application id
671
-	 * @param bool $prepend prepend the file to the beginning of the list
672
-	 * @param string $path
673
-	 * @param string $type (script or style)
674
-	 * @return void
675
-	 */
676
-	private static function addExternalResource($application, $prepend, $path, $type = "script") {
677
-		if ($type === "style") {
678
-			if (!in_array($path, self::$styles)) {
679
-				if ($prepend === true) {
680
-					array_unshift(self::$styles, $path);
681
-				} else {
682
-					self::$styles[] = $path;
683
-				}
684
-			}
685
-		} elseif ($type === "script") {
686
-			if (!in_array($path, self::$scripts)) {
687
-				if ($prepend === true) {
688
-					array_unshift(self::$scripts, $path);
689
-				} else {
690
-					self::$scripts [] = $path;
691
-				}
692
-			}
693
-		}
694
-	}
695
-
696
-	/**
697
-	 * Add a custom element to the header
698
-	 * If $text is null then the element will be written as empty element.
699
-	 * So use "" to get a closing tag.
700
-	 * @param string $tag tag name of the element
701
-	 * @param array $attributes array of attributes for the element
702
-	 * @param string $text the text content for the element
703
-	 * @param bool $prepend prepend the header to the beginning of the list
704
-	 */
705
-	public static function addHeader($tag, $attributes, $text = null, $prepend = false) {
706
-		$header = [
707
-			'tag' => $tag,
708
-			'attributes' => $attributes,
709
-			'text' => $text
710
-		];
711
-		if ($prepend === true) {
712
-			array_unshift(self::$headers, $header);
713
-		} else {
714
-			self::$headers[] = $header;
715
-		}
716
-	}
717
-
718
-	/**
719
-	 * check if the current server configuration is suitable for ownCloud
720
-	 *
721
-	 * @param \OC\SystemConfig $config
722
-	 * @return array arrays with error messages and hints
723
-	 */
724
-	public static function checkServer(\OC\SystemConfig $config) {
725
-		$l = \OC::$server->getL10N('lib');
726
-		$errors = [];
727
-		$CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
728
-
729
-		if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
730
-			// this check needs to be done every time
731
-			$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
732
-		}
733
-
734
-		// Assume that if checkServer() succeeded before in this session, then all is fine.
735
-		if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) {
736
-			return $errors;
737
-		}
738
-
739
-		$webServerRestart = false;
740
-		$setup = new \OC\Setup(
741
-			$config,
742
-			\OC::$server->getIniWrapper(),
743
-			\OC::$server->getL10N('lib'),
744
-			\OC::$server->query(\OCP\Defaults::class),
745
-			\OC::$server->getLogger(),
746
-			\OC::$server->getSecureRandom(),
747
-			\OC::$server->query(\OC\Installer::class)
748
-		);
749
-
750
-		$urlGenerator = \OC::$server->getURLGenerator();
751
-
752
-		$availableDatabases = $setup->getSupportedDatabases();
753
-		if (empty($availableDatabases)) {
754
-			$errors[] = [
755
-				'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
756
-				'hint' => '' //TODO: sane hint
757
-			];
758
-			$webServerRestart = true;
759
-		}
760
-
761
-		// Check if config folder is writable.
762
-		if (!OC_Helper::isReadOnlyConfigEnabled()) {
763
-			if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
764
-				$errors[] = [
765
-					'error' => $l->t('Cannot write into "config" directory'),
766
-					'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s',
767
-						[ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. '
768
-						. $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s',
769
-						[ $urlGenerator->linkToDocs('admin-config') ])
770
-				];
771
-			}
772
-		}
773
-
774
-		// Check if there is a writable install folder.
775
-		if ($config->getValue('appstoreenabled', true)) {
776
-			if (OC_App::getInstallPath() === null
777
-				|| !is_writable(OC_App::getInstallPath())
778
-				|| !is_readable(OC_App::getInstallPath())
779
-			) {
780
-				$errors[] = [
781
-					'error' => $l->t('Cannot write into "apps" directory'),
782
-					'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory'
783
-						. ' or disabling the appstore in the config file.')
784
-				];
785
-			}
786
-		}
787
-		// Create root dir.
788
-		if ($config->getValue('installed', false)) {
789
-			if (!is_dir($CONFIG_DATADIRECTORY)) {
790
-				$success = @mkdir($CONFIG_DATADIRECTORY);
791
-				if ($success) {
792
-					$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
793
-				} else {
794
-					$errors[] = [
795
-						'error' => $l->t('Cannot create "data" directory'),
796
-						'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s',
797
-							[$urlGenerator->linkToDocs('admin-dir_permissions')])
798
-					];
799
-				}
800
-			} elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
801
-				// is_writable doesn't work for NFS mounts, so try to write a file and check if it exists.
802
-				$testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_'));
803
-				$handle = fopen($testFile, 'w');
804
-				if (!$handle || fwrite($handle, 'Test write operation') === false) {
805
-					$permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.',
806
-						[$urlGenerator->linkToDocs('admin-dir_permissions')]);
807
-					$errors[] = [
808
-						'error' => 'Your data directory is not writable',
809
-						'hint' => $permissionsHint
810
-					];
811
-				} else {
812
-					fclose($handle);
813
-					unlink($testFile);
814
-				}
815
-			} else {
816
-				$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
817
-			}
818
-		}
819
-
820
-		if (!OC_Util::isSetLocaleWorking()) {
821
-			$errors[] = [
822
-				'error' => $l->t('Setting locale to %s failed',
823
-					['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
824
-						. 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']),
825
-				'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')
826
-			];
827
-		}
828
-
829
-		// Contains the dependencies that should be checked against
830
-		// classes = class_exists
831
-		// functions = function_exists
832
-		// defined = defined
833
-		// ini = ini_get
834
-		// If the dependency is not found the missing module name is shown to the EndUser
835
-		// When adding new checks always verify that they pass on Travis as well
836
-		// for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini
837
-		$dependencies = [
838
-			'classes' => [
839
-				'ZipArchive' => 'zip',
840
-				'DOMDocument' => 'dom',
841
-				'XMLWriter' => 'XMLWriter',
842
-				'XMLReader' => 'XMLReader',
843
-			],
844
-			'functions' => [
845
-				'xml_parser_create' => 'libxml',
846
-				'mb_strcut' => 'mbstring',
847
-				'ctype_digit' => 'ctype',
848
-				'json_encode' => 'JSON',
849
-				'gd_info' => 'GD',
850
-				'gzencode' => 'zlib',
851
-				'iconv' => 'iconv',
852
-				'simplexml_load_string' => 'SimpleXML',
853
-				'hash' => 'HASH Message Digest Framework',
854
-				'curl_init' => 'cURL',
855
-				'openssl_verify' => 'OpenSSL',
856
-			],
857
-			'defined' => [
858
-				'PDO::ATTR_DRIVER_NAME' => 'PDO'
859
-			],
860
-			'ini' => [
861
-				'default_charset' => 'UTF-8',
862
-			],
863
-		];
864
-		$missingDependencies = [];
865
-		$invalidIniSettings = [];
866
-
867
-		$iniWrapper = \OC::$server->getIniWrapper();
868
-		foreach ($dependencies['classes'] as $class => $module) {
869
-			if (!class_exists($class)) {
870
-				$missingDependencies[] = $module;
871
-			}
872
-		}
873
-		foreach ($dependencies['functions'] as $function => $module) {
874
-			if (!function_exists($function)) {
875
-				$missingDependencies[] = $module;
876
-			}
877
-		}
878
-		foreach ($dependencies['defined'] as $defined => $module) {
879
-			if (!defined($defined)) {
880
-				$missingDependencies[] = $module;
881
-			}
882
-		}
883
-		foreach ($dependencies['ini'] as $setting => $expected) {
884
-			if (is_bool($expected)) {
885
-				if ($iniWrapper->getBool($setting) !== $expected) {
886
-					$invalidIniSettings[] = [$setting, $expected];
887
-				}
888
-			}
889
-			if (is_int($expected)) {
890
-				if ($iniWrapper->getNumeric($setting) !== $expected) {
891
-					$invalidIniSettings[] = [$setting, $expected];
892
-				}
893
-			}
894
-			if (is_string($expected)) {
895
-				if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) {
896
-					$invalidIniSettings[] = [$setting, $expected];
897
-				}
898
-			}
899
-		}
900
-
901
-		foreach ($missingDependencies as $missingDependency) {
902
-			$errors[] = [
903
-				'error' => $l->t('PHP module %s not installed.', [$missingDependency]),
904
-				'hint' => $l->t('Please ask your server administrator to install the module.'),
905
-			];
906
-			$webServerRestart = true;
907
-		}
908
-		foreach ($invalidIniSettings as $setting) {
909
-			if (is_bool($setting[1])) {
910
-				$setting[1] = $setting[1] ? 'on' : 'off';
911
-			}
912
-			$errors[] = [
913
-				'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]),
914
-				'hint' =>  $l->t('Adjusting this setting in php.ini will make Nextcloud run again')
915
-			];
916
-			$webServerRestart = true;
917
-		}
918
-
919
-		/**
920
-		 * The mbstring.func_overload check can only be performed if the mbstring
921
-		 * module is installed as it will return null if the checking setting is
922
-		 * not available and thus a check on the boolean value fails.
923
-		 *
924
-		 * TODO: Should probably be implemented in the above generic dependency
925
-		 *       check somehow in the long-term.
926
-		 */
927
-		if ($iniWrapper->getBool('mbstring.func_overload') !== null &&
928
-			$iniWrapper->getBool('mbstring.func_overload') === true) {
929
-			$errors[] = [
930
-				'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]),
931
-				'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini')
932
-			];
933
-		}
934
-
935
-		if (function_exists('xml_parser_create') &&
936
-			LIBXML_LOADED_VERSION < 20700) {
937
-			$version = LIBXML_LOADED_VERSION;
938
-			$major = floor($version/10000);
939
-			$version -= ($major * 10000);
940
-			$minor = floor($version/100);
941
-			$version -= ($minor * 100);
942
-			$patch = $version;
943
-			$errors[] = [
944
-				'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]),
945
-				'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.')
946
-			];
947
-		}
948
-
949
-		if (!self::isAnnotationsWorking()) {
950
-			$errors[] = [
951
-				'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'),
952
-				'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')
953
-			];
954
-		}
955
-
956
-		if (!\OC::$CLI && $webServerRestart) {
957
-			$errors[] = [
958
-				'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'),
959
-				'hint' => $l->t('Please ask your server administrator to restart the web server.')
960
-			];
961
-		}
962
-
963
-		$errors = array_merge($errors, self::checkDatabaseVersion());
964
-
965
-		// Cache the result of this function
966
-		\OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0);
967
-
968
-		return $errors;
969
-	}
970
-
971
-	/**
972
-	 * Check the database version
973
-	 *
974
-	 * @return array errors array
975
-	 */
976
-	public static function checkDatabaseVersion() {
977
-		$l = \OC::$server->getL10N('lib');
978
-		$errors = [];
979
-		$dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
980
-		if ($dbType === 'pgsql') {
981
-			// check PostgreSQL version
982
-			try {
983
-				$result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
984
-				$data = $result->fetchRow();
985
-				if (isset($data['server_version'])) {
986
-					$version = $data['server_version'];
987
-					if (version_compare($version, '9.0.0', '<')) {
988
-						$errors[] = [
989
-							'error' => $l->t('PostgreSQL >= 9 required'),
990
-							'hint' => $l->t('Please upgrade your database version')
991
-						];
992
-					}
993
-				}
994
-			} catch (\Doctrine\DBAL\DBALException $e) {
995
-				$logger = \OC::$server->getLogger();
996
-				$logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9');
997
-				$logger->logException($e);
998
-			}
999
-		}
1000
-		return $errors;
1001
-	}
1002
-
1003
-	/**
1004
-	 * Check for correct file permissions of data directory
1005
-	 *
1006
-	 * @param string $dataDirectory
1007
-	 * @return array arrays with error messages and hints
1008
-	 */
1009
-	public static function checkDataDirectoryPermissions($dataDirectory) {
1010
-		if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) {
1011
-			return  [];
1012
-		}
1013
-
1014
-		$perms = substr(decoct(@fileperms($dataDirectory)), -3);
1015
-		if (substr($perms, -1) !== '0') {
1016
-			chmod($dataDirectory, 0770);
1017
-			clearstatcache();
1018
-			$perms = substr(decoct(@fileperms($dataDirectory)), -3);
1019
-			if ($perms[2] !== '0') {
1020
-				$l = \OC::$server->getL10N('lib');
1021
-				return [[
1022
-					'error' => $l->t('Your data directory is readable by other users'),
1023
-					'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'),
1024
-				]];
1025
-			}
1026
-		}
1027
-		return [];
1028
-	}
1029
-
1030
-	/**
1031
-	 * Check that the data directory exists and is valid by
1032
-	 * checking the existence of the ".ocdata" file.
1033
-	 *
1034
-	 * @param string $dataDirectory data directory path
1035
-	 * @return array errors found
1036
-	 */
1037
-	public static function checkDataDirectoryValidity($dataDirectory) {
1038
-		$l = \OC::$server->getL10N('lib');
1039
-		$errors = [];
1040
-		if ($dataDirectory[0] !== '/') {
1041
-			$errors[] = [
1042
-				'error' => $l->t('Your data directory must be an absolute path'),
1043
-				'hint' => $l->t('Check the value of "datadirectory" in your configuration')
1044
-			];
1045
-		}
1046
-		if (!file_exists($dataDirectory . '/.ocdata')) {
1047
-			$errors[] = [
1048
-				'error' => $l->t('Your data directory is invalid'),
1049
-				'hint' => $l->t('Ensure there is a file called ".ocdata"' .
1050
-					' in the root of the data directory.')
1051
-			];
1052
-		}
1053
-		return $errors;
1054
-	}
1055
-
1056
-	/**
1057
-	 * Check if the user is logged in, redirects to home if not. With
1058
-	 * redirect URL parameter to the request URI.
1059
-	 *
1060
-	 * @return void
1061
-	 */
1062
-	public static function checkLoggedIn() {
1063
-		// Check if we are a user
1064
-		if (!\OC::$server->getUserSession()->isLoggedIn()) {
1065
-			header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
1066
-						'core.login.showLoginForm',
1067
-						[
1068
-							'redirect_url' => \OC::$server->getRequest()->getRequestUri(),
1069
-						]
1070
-					)
1071
-			);
1072
-			exit();
1073
-		}
1074
-		// Redirect to 2FA challenge selection if 2FA challenge was not solved yet
1075
-		if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
1076
-			header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
1077
-			exit();
1078
-		}
1079
-	}
1080
-
1081
-	/**
1082
-	 * Check if the user is a admin, redirects to home if not
1083
-	 *
1084
-	 * @return void
1085
-	 */
1086
-	public static function checkAdminUser() {
1087
-		OC_Util::checkLoggedIn();
1088
-		if (!OC_User::isAdminUser(OC_User::getUser())) {
1089
-			header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1090
-			exit();
1091
-		}
1092
-	}
1093
-
1094
-	/**
1095
-	 * Returns the URL of the default page
1096
-	 * based on the system configuration and
1097
-	 * the apps visible for the current user
1098
-	 *
1099
-	 * @return string URL
1100
-	 * @suppress PhanDeprecatedFunction
1101
-	 */
1102
-	public static function getDefaultPageUrl() {
1103
-		/** @var IConfig $config */
1104
-		$config = \OC::$server->get(IConfig::class);
1105
-		$urlGenerator = \OC::$server->getURLGenerator();
1106
-		// Deny the redirect if the URL contains a @
1107
-		// This prevents unvalidated redirects like ?redirect_url=:[email protected]
1108
-		if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
1109
-			$location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
1110
-		} else {
1111
-			$defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage');
1112
-			if ($defaultPage) {
1113
-				$location = $urlGenerator->getAbsoluteURL($defaultPage);
1114
-			} else {
1115
-				$appId = 'files';
1116
-				$defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files'));
1117
-
1118
-				/** @var IUserSession $userSession */
1119
-				$userSession = \OC::$server->get(IUserSession::class);
1120
-				$user = $userSession->getUser();
1121
-				if ($user) {
1122
-					$userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp'));
1123
-					$defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
1124
-				}
1125
-
1126
-				// find the first app that is enabled for the current user
1127
-				foreach ($defaultApps as $defaultApp) {
1128
-					$defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
1129
-					if (static::getAppManager()->isEnabledForUser($defaultApp)) {
1130
-						$appId = $defaultApp;
1131
-						break;
1132
-					}
1133
-				}
1134
-
1135
-				if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') {
1136
-					$location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
1137
-				} else {
1138
-					$location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
1139
-				}
1140
-			}
1141
-		}
1142
-		return $location;
1143
-	}
1144
-
1145
-	/**
1146
-	 * Redirect to the user default page
1147
-	 *
1148
-	 * @return void
1149
-	 */
1150
-	public static function redirectToDefaultPage() {
1151
-		$location = self::getDefaultPageUrl();
1152
-		header('Location: ' . $location);
1153
-		exit();
1154
-	}
1155
-
1156
-	/**
1157
-	 * get an id unique for this instance
1158
-	 *
1159
-	 * @return string
1160
-	 */
1161
-	public static function getInstanceId() {
1162
-		$id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
1163
-		if (is_null($id)) {
1164
-			// We need to guarantee at least one letter in instanceid so it can be used as the session_name
1165
-			$id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
1166
-			\OC::$server->getSystemConfig()->setValue('instanceid', $id);
1167
-		}
1168
-		return $id;
1169
-	}
1170
-
1171
-	/**
1172
-	 * Public function to sanitize HTML
1173
-	 *
1174
-	 * This function is used to sanitize HTML and should be applied on any
1175
-	 * string or array of strings before displaying it on a web page.
1176
-	 *
1177
-	 * @param string|array $value
1178
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
1179
-	 */
1180
-	public static function sanitizeHTML($value) {
1181
-		if (is_array($value)) {
1182
-			$value = array_map(function ($value) {
1183
-				return self::sanitizeHTML($value);
1184
-			}, $value);
1185
-		} else {
1186
-			// Specify encoding for PHP<5.4
1187
-			$value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
1188
-		}
1189
-		return $value;
1190
-	}
1191
-
1192
-	/**
1193
-	 * Public function to encode url parameters
1194
-	 *
1195
-	 * This function is used to encode path to file before output.
1196
-	 * Encoding is done according to RFC 3986 with one exception:
1197
-	 * Character '/' is preserved as is.
1198
-	 *
1199
-	 * @param string $component part of URI to encode
1200
-	 * @return string
1201
-	 */
1202
-	public static function encodePath($component) {
1203
-		$encoded = rawurlencode($component);
1204
-		$encoded = str_replace('%2F', '/', $encoded);
1205
-		return $encoded;
1206
-	}
1207
-
1208
-
1209
-	public function createHtaccessTestFile(\OCP\IConfig $config) {
1210
-		// php dev server does not support htaccess
1211
-		if (php_sapi_name() === 'cli-server') {
1212
-			return false;
1213
-		}
1214
-
1215
-		// testdata
1216
-		$fileName = '/htaccesstest.txt';
1217
-		$testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
1218
-
1219
-		// creating a test file
1220
-		$testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1221
-
1222
-		if (file_exists($testFile)) {// already running this test, possible recursive call
1223
-			return false;
1224
-		}
1225
-
1226
-		$fp = @fopen($testFile, 'w');
1227
-		if (!$fp) {
1228
-			throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
1229
-				'Make sure it is possible for the webserver to write to ' . $testFile);
1230
-		}
1231
-		fwrite($fp, $testContent);
1232
-		fclose($fp);
1233
-
1234
-		return $testContent;
1235
-	}
1236
-
1237
-	/**
1238
-	 * Check if the .htaccess file is working
1239
-	 * @param \OCP\IConfig $config
1240
-	 * @return bool
1241
-	 * @throws Exception
1242
-	 * @throws \OC\HintException If the test file can't get written.
1243
-	 */
1244
-	public function isHtaccessWorking(\OCP\IConfig $config) {
1245
-		if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) {
1246
-			return true;
1247
-		}
1248
-
1249
-		$testContent = $this->createHtaccessTestFile($config);
1250
-		if ($testContent === false) {
1251
-			return false;
1252
-		}
1253
-
1254
-		$fileName = '/htaccesstest.txt';
1255
-		$testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1256
-
1257
-		// accessing the file via http
1258
-		$url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
1259
-		try {
1260
-			$content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1261
-		} catch (\Exception $e) {
1262
-			$content = false;
1263
-		}
1264
-
1265
-		if (strpos($url, 'https:') === 0) {
1266
-			$url = 'http:' . substr($url, 6);
1267
-		} else {
1268
-			$url = 'https:' . substr($url, 5);
1269
-		}
1270
-
1271
-		try {
1272
-			$fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1273
-		} catch (\Exception $e) {
1274
-			$fallbackContent = false;
1275
-		}
1276
-
1277
-		// cleanup
1278
-		@unlink($testFile);
1279
-
1280
-		/*
270
+            if ($mount->getOption('readonly', false)) {
271
+                return new \OC\Files\Storage\Wrapper\PermissionsMask([
272
+                    'storage' => $storage,
273
+                    'mask' => \OCP\Constants::PERMISSION_ALL & ~(
274
+                        \OCP\Constants::PERMISSION_UPDATE |
275
+                        \OCP\Constants::PERMISSION_CREATE |
276
+                        \OCP\Constants::PERMISSION_DELETE
277
+                    ),
278
+                ]);
279
+            }
280
+            return $storage;
281
+        });
282
+
283
+        OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]);
284
+
285
+        \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
286
+
287
+        //check if we are using an object storage
288
+        $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
289
+        $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null);
290
+
291
+        // use the same order as in ObjectHomeMountProvider
292
+        if (isset($objectStoreMultibucket)) {
293
+            self::initObjectStoreMultibucketRootFS($objectStoreMultibucket);
294
+        } elseif (isset($objectStore)) {
295
+            self::initObjectStoreRootFS($objectStore);
296
+        } else {
297
+            self::initLocalStorageRootFS();
298
+        }
299
+
300
+        /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */
301
+        $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class);
302
+        /** @var \OCP\Files\Mount\IMountPoint[] $rootMountProviders */
303
+        $rootMountProviders = $mountProviderCollection->getRootMounts();
304
+
305
+        /** @var \OC\Files\Mount\Manager $mountManager */
306
+        $mountManager = \OC\Files\Filesystem::getMountManager();
307
+        foreach ($rootMountProviders as $rootMountProvider) {
308
+            $mountManager->addMount($rootMountProvider);
309
+        }
310
+
311
+        if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) {
312
+            \OC::$server->getEventLogger()->end('setup_fs');
313
+            return false;
314
+        }
315
+
316
+        //if we aren't logged in, there is no use to set up the filesystem
317
+        if ($user != "") {
318
+            $userDir = '/' . $user . '/files';
319
+
320
+            //jail the user into his "home" directory
321
+            \OC\Files\Filesystem::init($user, $userDir);
322
+
323
+            OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]);
324
+        }
325
+        \OC::$server->getEventLogger()->end('setup_fs');
326
+        return true;
327
+    }
328
+
329
+    /**
330
+     * check if a password is required for each public link
331
+     *
332
+     * @return boolean
333
+     * @suppress PhanDeprecatedFunction
334
+     */
335
+    public static function isPublicLinkPasswordRequired() {
336
+        $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no');
337
+        return $enforcePassword === 'yes';
338
+    }
339
+
340
+    /**
341
+     * check if sharing is disabled for the current user
342
+     * @param IConfig $config
343
+     * @param IGroupManager $groupManager
344
+     * @param IUser|null $user
345
+     * @return bool
346
+     */
347
+    public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) {
348
+        if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
349
+            $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
350
+            $excludedGroups = json_decode($groupsList);
351
+            if (is_null($excludedGroups)) {
352
+                $excludedGroups = explode(',', $groupsList);
353
+                $newValue = json_encode($excludedGroups);
354
+                $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
355
+            }
356
+            $usersGroups = $groupManager->getUserGroupIds($user);
357
+            if (!empty($usersGroups)) {
358
+                $remainingGroups = array_diff($usersGroups, $excludedGroups);
359
+                // if the user is only in groups which are disabled for sharing then
360
+                // sharing is also disabled for the user
361
+                if (empty($remainingGroups)) {
362
+                    return true;
363
+                }
364
+            }
365
+        }
366
+        return false;
367
+    }
368
+
369
+    /**
370
+     * check if share API enforces a default expire date
371
+     *
372
+     * @return boolean
373
+     * @suppress PhanDeprecatedFunction
374
+     */
375
+    public static function isDefaultExpireDateEnforced() {
376
+        $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no');
377
+        $enforceDefaultExpireDate = false;
378
+        if ($isDefaultExpireDateEnabled === 'yes') {
379
+            $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no');
380
+            $enforceDefaultExpireDate = $value === 'yes';
381
+        }
382
+
383
+        return $enforceDefaultExpireDate;
384
+    }
385
+
386
+    /**
387
+     * Get the quota of a user
388
+     *
389
+     * @param IUser|null $user
390
+     * @return float Quota bytes
391
+     */
392
+    public static function getUserQuota(?IUser $user) {
393
+        if (is_null($user)) {
394
+            return \OCP\Files\FileInfo::SPACE_UNLIMITED;
395
+        }
396
+        $userQuota = $user->getQuota();
397
+        if ($userQuota === 'none') {
398
+            return \OCP\Files\FileInfo::SPACE_UNLIMITED;
399
+        }
400
+        return OC_Helper::computerFileSize($userQuota);
401
+    }
402
+
403
+    /**
404
+     * copies the skeleton to the users /files
405
+     *
406
+     * @param string $userId
407
+     * @param \OCP\Files\Folder $userDirectory
408
+     * @throws \OCP\Files\NotFoundException
409
+     * @throws \OCP\Files\NotPermittedException
410
+     * @suppress PhanDeprecatedFunction
411
+     */
412
+    public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
413
+        $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton');
414
+        $userLang = \OC::$server->getL10NFactory()->findLanguage();
415
+        $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory);
416
+
417
+        if (!file_exists($skeletonDirectory)) {
418
+            $dialectStart = strpos($userLang, '_');
419
+            if ($dialectStart !== false) {
420
+                $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory);
421
+            }
422
+            if ($dialectStart === false || !file_exists($skeletonDirectory)) {
423
+                $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory);
424
+            }
425
+            if (!file_exists($skeletonDirectory)) {
426
+                $skeletonDirectory = '';
427
+            }
428
+        }
429
+
430
+        $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
431
+
432
+        if ($instanceId === null) {
433
+            throw new \RuntimeException('no instance id!');
434
+        }
435
+        $appdata = 'appdata_' . $instanceId;
436
+        if ($userId === $appdata) {
437
+            throw new \RuntimeException('username is reserved name: ' . $appdata);
438
+        }
439
+
440
+        if (!empty($skeletonDirectory)) {
441
+            \OCP\Util::writeLog(
442
+                'files_skeleton',
443
+                'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
444
+                ILogger::DEBUG
445
+            );
446
+            self::copyr($skeletonDirectory, $userDirectory);
447
+            // update the file cache
448
+            $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
449
+        }
450
+    }
451
+
452
+    /**
453
+     * copies a directory recursively by using streams
454
+     *
455
+     * @param string $source
456
+     * @param \OCP\Files\Folder $target
457
+     * @return void
458
+     */
459
+    public static function copyr($source, \OCP\Files\Folder $target) {
460
+        $logger = \OC::$server->getLogger();
461
+
462
+        // Verify if folder exists
463
+        $dir = opendir($source);
464
+        if ($dir === false) {
465
+            $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
466
+            return;
467
+        }
468
+
469
+        // Copy the files
470
+        while (false !== ($file = readdir($dir))) {
471
+            if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
472
+                if (is_dir($source . '/' . $file)) {
473
+                    $child = $target->newFolder($file);
474
+                    self::copyr($source . '/' . $file, $child);
475
+                } else {
476
+                    $child = $target->newFile($file);
477
+                    $sourceStream = fopen($source . '/' . $file, 'r');
478
+                    if ($sourceStream === false) {
479
+                        $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
480
+                        closedir($dir);
481
+                        return;
482
+                    }
483
+                    stream_copy_to_stream($sourceStream, $child->fopen('w'));
484
+                }
485
+            }
486
+        }
487
+        closedir($dir);
488
+    }
489
+
490
+    /**
491
+     * @return void
492
+     * @suppress PhanUndeclaredMethod
493
+     */
494
+    public static function tearDownFS() {
495
+        \OC\Files\Filesystem::tearDown();
496
+        \OC::$server->getRootFolder()->clearCache();
497
+        self::$fsSetup = false;
498
+        self::$rootMounted = false;
499
+    }
500
+
501
+    /**
502
+     * get the current installed version of ownCloud
503
+     *
504
+     * @return array
505
+     */
506
+    public static function getVersion() {
507
+        OC_Util::loadVersion();
508
+        return self::$versionCache['OC_Version'];
509
+    }
510
+
511
+    /**
512
+     * get the current installed version string of ownCloud
513
+     *
514
+     * @return string
515
+     */
516
+    public static function getVersionString() {
517
+        OC_Util::loadVersion();
518
+        return self::$versionCache['OC_VersionString'];
519
+    }
520
+
521
+    /**
522
+     * @deprecated the value is of no use anymore
523
+     * @return string
524
+     */
525
+    public static function getEditionString() {
526
+        return '';
527
+    }
528
+
529
+    /**
530
+     * @description get the update channel of the current installed of ownCloud.
531
+     * @return string
532
+     */
533
+    public static function getChannel() {
534
+        OC_Util::loadVersion();
535
+        return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']);
536
+    }
537
+
538
+    /**
539
+     * @description get the build number of the current installed of ownCloud.
540
+     * @return string
541
+     */
542
+    public static function getBuild() {
543
+        OC_Util::loadVersion();
544
+        return self::$versionCache['OC_Build'];
545
+    }
546
+
547
+    /**
548
+     * @description load the version.php into the session as cache
549
+     * @suppress PhanUndeclaredVariable
550
+     */
551
+    private static function loadVersion() {
552
+        if (self::$versionCache !== null) {
553
+            return;
554
+        }
555
+
556
+        $timestamp = filemtime(OC::$SERVERROOT . '/version.php');
557
+        require OC::$SERVERROOT . '/version.php';
558
+        /** @var $timestamp int */
559
+        self::$versionCache['OC_Version_Timestamp'] = $timestamp;
560
+        /** @var $OC_Version string */
561
+        self::$versionCache['OC_Version'] = $OC_Version;
562
+        /** @var $OC_VersionString string */
563
+        self::$versionCache['OC_VersionString'] = $OC_VersionString;
564
+        /** @var $OC_Build string */
565
+        self::$versionCache['OC_Build'] = $OC_Build;
566
+
567
+        /** @var $OC_Channel string */
568
+        self::$versionCache['OC_Channel'] = $OC_Channel;
569
+    }
570
+
571
+    /**
572
+     * generates a path for JS/CSS files. If no application is provided it will create the path for core.
573
+     *
574
+     * @param string $application application to get the files from
575
+     * @param string $directory directory within this application (css, js, vendor, etc)
576
+     * @param string $file the file inside of the above folder
577
+     * @return string the path
578
+     */
579
+    private static function generatePath($application, $directory, $file) {
580
+        if (is_null($file)) {
581
+            $file = $application;
582
+            $application = "";
583
+        }
584
+        if (!empty($application)) {
585
+            return "$application/$directory/$file";
586
+        } else {
587
+            return "$directory/$file";
588
+        }
589
+    }
590
+
591
+    /**
592
+     * add a javascript file
593
+     *
594
+     * @param string $application application id
595
+     * @param string|null $file filename
596
+     * @param bool $prepend prepend the Script to the beginning of the list
597
+     * @return void
598
+     */
599
+    public static function addScript($application, $file = null, $prepend = false) {
600
+        $path = OC_Util::generatePath($application, 'js', $file);
601
+
602
+        // core js files need separate handling
603
+        if ($application !== 'core' && $file !== null) {
604
+            self::addTranslations($application);
605
+        }
606
+        self::addExternalResource($application, $prepend, $path, "script");
607
+    }
608
+
609
+    /**
610
+     * add a javascript file from the vendor sub folder
611
+     *
612
+     * @param string $application application id
613
+     * @param string|null $file filename
614
+     * @param bool $prepend prepend the Script to the beginning of the list
615
+     * @return void
616
+     */
617
+    public static function addVendorScript($application, $file = null, $prepend = false) {
618
+        $path = OC_Util::generatePath($application, 'vendor', $file);
619
+        self::addExternalResource($application, $prepend, $path, "script");
620
+    }
621
+
622
+    /**
623
+     * add a translation JS file
624
+     *
625
+     * @param string $application application id
626
+     * @param string|null $languageCode language code, defaults to the current language
627
+     * @param bool|null $prepend prepend the Script to the beginning of the list
628
+     */
629
+    public static function addTranslations($application, $languageCode = null, $prepend = false) {
630
+        if (is_null($languageCode)) {
631
+            $languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
632
+        }
633
+        if (!empty($application)) {
634
+            $path = "$application/l10n/$languageCode";
635
+        } else {
636
+            $path = "l10n/$languageCode";
637
+        }
638
+        self::addExternalResource($application, $prepend, $path, "script");
639
+    }
640
+
641
+    /**
642
+     * add a css file
643
+     *
644
+     * @param string $application application id
645
+     * @param string|null $file filename
646
+     * @param bool $prepend prepend the Style to the beginning of the list
647
+     * @return void
648
+     */
649
+    public static function addStyle($application, $file = null, $prepend = false) {
650
+        $path = OC_Util::generatePath($application, 'css', $file);
651
+        self::addExternalResource($application, $prepend, $path, "style");
652
+    }
653
+
654
+    /**
655
+     * add a css file from the vendor sub folder
656
+     *
657
+     * @param string $application application id
658
+     * @param string|null $file filename
659
+     * @param bool $prepend prepend the Style to the beginning of the list
660
+     * @return void
661
+     */
662
+    public static function addVendorStyle($application, $file = null, $prepend = false) {
663
+        $path = OC_Util::generatePath($application, 'vendor', $file);
664
+        self::addExternalResource($application, $prepend, $path, "style");
665
+    }
666
+
667
+    /**
668
+     * add an external resource css/js file
669
+     *
670
+     * @param string $application application id
671
+     * @param bool $prepend prepend the file to the beginning of the list
672
+     * @param string $path
673
+     * @param string $type (script or style)
674
+     * @return void
675
+     */
676
+    private static function addExternalResource($application, $prepend, $path, $type = "script") {
677
+        if ($type === "style") {
678
+            if (!in_array($path, self::$styles)) {
679
+                if ($prepend === true) {
680
+                    array_unshift(self::$styles, $path);
681
+                } else {
682
+                    self::$styles[] = $path;
683
+                }
684
+            }
685
+        } elseif ($type === "script") {
686
+            if (!in_array($path, self::$scripts)) {
687
+                if ($prepend === true) {
688
+                    array_unshift(self::$scripts, $path);
689
+                } else {
690
+                    self::$scripts [] = $path;
691
+                }
692
+            }
693
+        }
694
+    }
695
+
696
+    /**
697
+     * Add a custom element to the header
698
+     * If $text is null then the element will be written as empty element.
699
+     * So use "" to get a closing tag.
700
+     * @param string $tag tag name of the element
701
+     * @param array $attributes array of attributes for the element
702
+     * @param string $text the text content for the element
703
+     * @param bool $prepend prepend the header to the beginning of the list
704
+     */
705
+    public static function addHeader($tag, $attributes, $text = null, $prepend = false) {
706
+        $header = [
707
+            'tag' => $tag,
708
+            'attributes' => $attributes,
709
+            'text' => $text
710
+        ];
711
+        if ($prepend === true) {
712
+            array_unshift(self::$headers, $header);
713
+        } else {
714
+            self::$headers[] = $header;
715
+        }
716
+    }
717
+
718
+    /**
719
+     * check if the current server configuration is suitable for ownCloud
720
+     *
721
+     * @param \OC\SystemConfig $config
722
+     * @return array arrays with error messages and hints
723
+     */
724
+    public static function checkServer(\OC\SystemConfig $config) {
725
+        $l = \OC::$server->getL10N('lib');
726
+        $errors = [];
727
+        $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data');
728
+
729
+        if (!self::needUpgrade($config) && $config->getValue('installed', false)) {
730
+            // this check needs to be done every time
731
+            $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
732
+        }
733
+
734
+        // Assume that if checkServer() succeeded before in this session, then all is fine.
735
+        if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) {
736
+            return $errors;
737
+        }
738
+
739
+        $webServerRestart = false;
740
+        $setup = new \OC\Setup(
741
+            $config,
742
+            \OC::$server->getIniWrapper(),
743
+            \OC::$server->getL10N('lib'),
744
+            \OC::$server->query(\OCP\Defaults::class),
745
+            \OC::$server->getLogger(),
746
+            \OC::$server->getSecureRandom(),
747
+            \OC::$server->query(\OC\Installer::class)
748
+        );
749
+
750
+        $urlGenerator = \OC::$server->getURLGenerator();
751
+
752
+        $availableDatabases = $setup->getSupportedDatabases();
753
+        if (empty($availableDatabases)) {
754
+            $errors[] = [
755
+                'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
756
+                'hint' => '' //TODO: sane hint
757
+            ];
758
+            $webServerRestart = true;
759
+        }
760
+
761
+        // Check if config folder is writable.
762
+        if (!OC_Helper::isReadOnlyConfigEnabled()) {
763
+            if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
764
+                $errors[] = [
765
+                    'error' => $l->t('Cannot write into "config" directory'),
766
+                    'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s',
767
+                        [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. '
768
+                        . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s',
769
+                        [ $urlGenerator->linkToDocs('admin-config') ])
770
+                ];
771
+            }
772
+        }
773
+
774
+        // Check if there is a writable install folder.
775
+        if ($config->getValue('appstoreenabled', true)) {
776
+            if (OC_App::getInstallPath() === null
777
+                || !is_writable(OC_App::getInstallPath())
778
+                || !is_readable(OC_App::getInstallPath())
779
+            ) {
780
+                $errors[] = [
781
+                    'error' => $l->t('Cannot write into "apps" directory'),
782
+                    'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory'
783
+                        . ' or disabling the appstore in the config file.')
784
+                ];
785
+            }
786
+        }
787
+        // Create root dir.
788
+        if ($config->getValue('installed', false)) {
789
+            if (!is_dir($CONFIG_DATADIRECTORY)) {
790
+                $success = @mkdir($CONFIG_DATADIRECTORY);
791
+                if ($success) {
792
+                    $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
793
+                } else {
794
+                    $errors[] = [
795
+                        'error' => $l->t('Cannot create "data" directory'),
796
+                        'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s',
797
+                            [$urlGenerator->linkToDocs('admin-dir_permissions')])
798
+                    ];
799
+                }
800
+            } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
801
+                // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists.
802
+                $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_'));
803
+                $handle = fopen($testFile, 'w');
804
+                if (!$handle || fwrite($handle, 'Test write operation') === false) {
805
+                    $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.',
806
+                        [$urlGenerator->linkToDocs('admin-dir_permissions')]);
807
+                    $errors[] = [
808
+                        'error' => 'Your data directory is not writable',
809
+                        'hint' => $permissionsHint
810
+                    ];
811
+                } else {
812
+                    fclose($handle);
813
+                    unlink($testFile);
814
+                }
815
+            } else {
816
+                $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
817
+            }
818
+        }
819
+
820
+        if (!OC_Util::isSetLocaleWorking()) {
821
+            $errors[] = [
822
+                'error' => $l->t('Setting locale to %s failed',
823
+                    ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/'
824
+                        . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']),
825
+                'hint' => $l->t('Please install one of these locales on your system and restart your webserver.')
826
+            ];
827
+        }
828
+
829
+        // Contains the dependencies that should be checked against
830
+        // classes = class_exists
831
+        // functions = function_exists
832
+        // defined = defined
833
+        // ini = ini_get
834
+        // If the dependency is not found the missing module name is shown to the EndUser
835
+        // When adding new checks always verify that they pass on Travis as well
836
+        // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini
837
+        $dependencies = [
838
+            'classes' => [
839
+                'ZipArchive' => 'zip',
840
+                'DOMDocument' => 'dom',
841
+                'XMLWriter' => 'XMLWriter',
842
+                'XMLReader' => 'XMLReader',
843
+            ],
844
+            'functions' => [
845
+                'xml_parser_create' => 'libxml',
846
+                'mb_strcut' => 'mbstring',
847
+                'ctype_digit' => 'ctype',
848
+                'json_encode' => 'JSON',
849
+                'gd_info' => 'GD',
850
+                'gzencode' => 'zlib',
851
+                'iconv' => 'iconv',
852
+                'simplexml_load_string' => 'SimpleXML',
853
+                'hash' => 'HASH Message Digest Framework',
854
+                'curl_init' => 'cURL',
855
+                'openssl_verify' => 'OpenSSL',
856
+            ],
857
+            'defined' => [
858
+                'PDO::ATTR_DRIVER_NAME' => 'PDO'
859
+            ],
860
+            'ini' => [
861
+                'default_charset' => 'UTF-8',
862
+            ],
863
+        ];
864
+        $missingDependencies = [];
865
+        $invalidIniSettings = [];
866
+
867
+        $iniWrapper = \OC::$server->getIniWrapper();
868
+        foreach ($dependencies['classes'] as $class => $module) {
869
+            if (!class_exists($class)) {
870
+                $missingDependencies[] = $module;
871
+            }
872
+        }
873
+        foreach ($dependencies['functions'] as $function => $module) {
874
+            if (!function_exists($function)) {
875
+                $missingDependencies[] = $module;
876
+            }
877
+        }
878
+        foreach ($dependencies['defined'] as $defined => $module) {
879
+            if (!defined($defined)) {
880
+                $missingDependencies[] = $module;
881
+            }
882
+        }
883
+        foreach ($dependencies['ini'] as $setting => $expected) {
884
+            if (is_bool($expected)) {
885
+                if ($iniWrapper->getBool($setting) !== $expected) {
886
+                    $invalidIniSettings[] = [$setting, $expected];
887
+                }
888
+            }
889
+            if (is_int($expected)) {
890
+                if ($iniWrapper->getNumeric($setting) !== $expected) {
891
+                    $invalidIniSettings[] = [$setting, $expected];
892
+                }
893
+            }
894
+            if (is_string($expected)) {
895
+                if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) {
896
+                    $invalidIniSettings[] = [$setting, $expected];
897
+                }
898
+            }
899
+        }
900
+
901
+        foreach ($missingDependencies as $missingDependency) {
902
+            $errors[] = [
903
+                'error' => $l->t('PHP module %s not installed.', [$missingDependency]),
904
+                'hint' => $l->t('Please ask your server administrator to install the module.'),
905
+            ];
906
+            $webServerRestart = true;
907
+        }
908
+        foreach ($invalidIniSettings as $setting) {
909
+            if (is_bool($setting[1])) {
910
+                $setting[1] = $setting[1] ? 'on' : 'off';
911
+            }
912
+            $errors[] = [
913
+                'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]),
914
+                'hint' =>  $l->t('Adjusting this setting in php.ini will make Nextcloud run again')
915
+            ];
916
+            $webServerRestart = true;
917
+        }
918
+
919
+        /**
920
+         * The mbstring.func_overload check can only be performed if the mbstring
921
+         * module is installed as it will return null if the checking setting is
922
+         * not available and thus a check on the boolean value fails.
923
+         *
924
+         * TODO: Should probably be implemented in the above generic dependency
925
+         *       check somehow in the long-term.
926
+         */
927
+        if ($iniWrapper->getBool('mbstring.func_overload') !== null &&
928
+            $iniWrapper->getBool('mbstring.func_overload') === true) {
929
+            $errors[] = [
930
+                'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]),
931
+                'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini')
932
+            ];
933
+        }
934
+
935
+        if (function_exists('xml_parser_create') &&
936
+            LIBXML_LOADED_VERSION < 20700) {
937
+            $version = LIBXML_LOADED_VERSION;
938
+            $major = floor($version/10000);
939
+            $version -= ($major * 10000);
940
+            $minor = floor($version/100);
941
+            $version -= ($minor * 100);
942
+            $patch = $version;
943
+            $errors[] = [
944
+                'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]),
945
+                'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.')
946
+            ];
947
+        }
948
+
949
+        if (!self::isAnnotationsWorking()) {
950
+            $errors[] = [
951
+                'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'),
952
+                'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.')
953
+            ];
954
+        }
955
+
956
+        if (!\OC::$CLI && $webServerRestart) {
957
+            $errors[] = [
958
+                'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'),
959
+                'hint' => $l->t('Please ask your server administrator to restart the web server.')
960
+            ];
961
+        }
962
+
963
+        $errors = array_merge($errors, self::checkDatabaseVersion());
964
+
965
+        // Cache the result of this function
966
+        \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0);
967
+
968
+        return $errors;
969
+    }
970
+
971
+    /**
972
+     * Check the database version
973
+     *
974
+     * @return array errors array
975
+     */
976
+    public static function checkDatabaseVersion() {
977
+        $l = \OC::$server->getL10N('lib');
978
+        $errors = [];
979
+        $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite');
980
+        if ($dbType === 'pgsql') {
981
+            // check PostgreSQL version
982
+            try {
983
+                $result = \OC_DB::executeAudited('SHOW SERVER_VERSION');
984
+                $data = $result->fetchRow();
985
+                if (isset($data['server_version'])) {
986
+                    $version = $data['server_version'];
987
+                    if (version_compare($version, '9.0.0', '<')) {
988
+                        $errors[] = [
989
+                            'error' => $l->t('PostgreSQL >= 9 required'),
990
+                            'hint' => $l->t('Please upgrade your database version')
991
+                        ];
992
+                    }
993
+                }
994
+            } catch (\Doctrine\DBAL\DBALException $e) {
995
+                $logger = \OC::$server->getLogger();
996
+                $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9');
997
+                $logger->logException($e);
998
+            }
999
+        }
1000
+        return $errors;
1001
+    }
1002
+
1003
+    /**
1004
+     * Check for correct file permissions of data directory
1005
+     *
1006
+     * @param string $dataDirectory
1007
+     * @return array arrays with error messages and hints
1008
+     */
1009
+    public static function checkDataDirectoryPermissions($dataDirectory) {
1010
+        if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) {
1011
+            return  [];
1012
+        }
1013
+
1014
+        $perms = substr(decoct(@fileperms($dataDirectory)), -3);
1015
+        if (substr($perms, -1) !== '0') {
1016
+            chmod($dataDirectory, 0770);
1017
+            clearstatcache();
1018
+            $perms = substr(decoct(@fileperms($dataDirectory)), -3);
1019
+            if ($perms[2] !== '0') {
1020
+                $l = \OC::$server->getL10N('lib');
1021
+                return [[
1022
+                    'error' => $l->t('Your data directory is readable by other users'),
1023
+                    'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'),
1024
+                ]];
1025
+            }
1026
+        }
1027
+        return [];
1028
+    }
1029
+
1030
+    /**
1031
+     * Check that the data directory exists and is valid by
1032
+     * checking the existence of the ".ocdata" file.
1033
+     *
1034
+     * @param string $dataDirectory data directory path
1035
+     * @return array errors found
1036
+     */
1037
+    public static function checkDataDirectoryValidity($dataDirectory) {
1038
+        $l = \OC::$server->getL10N('lib');
1039
+        $errors = [];
1040
+        if ($dataDirectory[0] !== '/') {
1041
+            $errors[] = [
1042
+                'error' => $l->t('Your data directory must be an absolute path'),
1043
+                'hint' => $l->t('Check the value of "datadirectory" in your configuration')
1044
+            ];
1045
+        }
1046
+        if (!file_exists($dataDirectory . '/.ocdata')) {
1047
+            $errors[] = [
1048
+                'error' => $l->t('Your data directory is invalid'),
1049
+                'hint' => $l->t('Ensure there is a file called ".ocdata"' .
1050
+                    ' in the root of the data directory.')
1051
+            ];
1052
+        }
1053
+        return $errors;
1054
+    }
1055
+
1056
+    /**
1057
+     * Check if the user is logged in, redirects to home if not. With
1058
+     * redirect URL parameter to the request URI.
1059
+     *
1060
+     * @return void
1061
+     */
1062
+    public static function checkLoggedIn() {
1063
+        // Check if we are a user
1064
+        if (!\OC::$server->getUserSession()->isLoggedIn()) {
1065
+            header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute(
1066
+                        'core.login.showLoginForm',
1067
+                        [
1068
+                            'redirect_url' => \OC::$server->getRequest()->getRequestUri(),
1069
+                        ]
1070
+                    )
1071
+            );
1072
+            exit();
1073
+        }
1074
+        // Redirect to 2FA challenge selection if 2FA challenge was not solved yet
1075
+        if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) {
1076
+            header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
1077
+            exit();
1078
+        }
1079
+    }
1080
+
1081
+    /**
1082
+     * Check if the user is a admin, redirects to home if not
1083
+     *
1084
+     * @return void
1085
+     */
1086
+    public static function checkAdminUser() {
1087
+        OC_Util::checkLoggedIn();
1088
+        if (!OC_User::isAdminUser(OC_User::getUser())) {
1089
+            header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php'));
1090
+            exit();
1091
+        }
1092
+    }
1093
+
1094
+    /**
1095
+     * Returns the URL of the default page
1096
+     * based on the system configuration and
1097
+     * the apps visible for the current user
1098
+     *
1099
+     * @return string URL
1100
+     * @suppress PhanDeprecatedFunction
1101
+     */
1102
+    public static function getDefaultPageUrl() {
1103
+        /** @var IConfig $config */
1104
+        $config = \OC::$server->get(IConfig::class);
1105
+        $urlGenerator = \OC::$server->getURLGenerator();
1106
+        // Deny the redirect if the URL contains a @
1107
+        // This prevents unvalidated redirects like ?redirect_url=:[email protected]
1108
+        if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) {
1109
+            $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url']));
1110
+        } else {
1111
+            $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage');
1112
+            if ($defaultPage) {
1113
+                $location = $urlGenerator->getAbsoluteURL($defaultPage);
1114
+            } else {
1115
+                $appId = 'files';
1116
+                $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files'));
1117
+
1118
+                /** @var IUserSession $userSession */
1119
+                $userSession = \OC::$server->get(IUserSession::class);
1120
+                $user = $userSession->getUser();
1121
+                if ($user) {
1122
+                    $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp'));
1123
+                    $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps));
1124
+                }
1125
+
1126
+                // find the first app that is enabled for the current user
1127
+                foreach ($defaultApps as $defaultApp) {
1128
+                    $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
1129
+                    if (static::getAppManager()->isEnabledForUser($defaultApp)) {
1130
+                        $appId = $defaultApp;
1131
+                        break;
1132
+                    }
1133
+                }
1134
+
1135
+                if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') {
1136
+                    $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/');
1137
+                } else {
1138
+                    $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/');
1139
+                }
1140
+            }
1141
+        }
1142
+        return $location;
1143
+    }
1144
+
1145
+    /**
1146
+     * Redirect to the user default page
1147
+     *
1148
+     * @return void
1149
+     */
1150
+    public static function redirectToDefaultPage() {
1151
+        $location = self::getDefaultPageUrl();
1152
+        header('Location: ' . $location);
1153
+        exit();
1154
+    }
1155
+
1156
+    /**
1157
+     * get an id unique for this instance
1158
+     *
1159
+     * @return string
1160
+     */
1161
+    public static function getInstanceId() {
1162
+        $id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
1163
+        if (is_null($id)) {
1164
+            // We need to guarantee at least one letter in instanceid so it can be used as the session_name
1165
+            $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
1166
+            \OC::$server->getSystemConfig()->setValue('instanceid', $id);
1167
+        }
1168
+        return $id;
1169
+    }
1170
+
1171
+    /**
1172
+     * Public function to sanitize HTML
1173
+     *
1174
+     * This function is used to sanitize HTML and should be applied on any
1175
+     * string or array of strings before displaying it on a web page.
1176
+     *
1177
+     * @param string|array $value
1178
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
1179
+     */
1180
+    public static function sanitizeHTML($value) {
1181
+        if (is_array($value)) {
1182
+            $value = array_map(function ($value) {
1183
+                return self::sanitizeHTML($value);
1184
+            }, $value);
1185
+        } else {
1186
+            // Specify encoding for PHP<5.4
1187
+            $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
1188
+        }
1189
+        return $value;
1190
+    }
1191
+
1192
+    /**
1193
+     * Public function to encode url parameters
1194
+     *
1195
+     * This function is used to encode path to file before output.
1196
+     * Encoding is done according to RFC 3986 with one exception:
1197
+     * Character '/' is preserved as is.
1198
+     *
1199
+     * @param string $component part of URI to encode
1200
+     * @return string
1201
+     */
1202
+    public static function encodePath($component) {
1203
+        $encoded = rawurlencode($component);
1204
+        $encoded = str_replace('%2F', '/', $encoded);
1205
+        return $encoded;
1206
+    }
1207
+
1208
+
1209
+    public function createHtaccessTestFile(\OCP\IConfig $config) {
1210
+        // php dev server does not support htaccess
1211
+        if (php_sapi_name() === 'cli-server') {
1212
+            return false;
1213
+        }
1214
+
1215
+        // testdata
1216
+        $fileName = '/htaccesstest.txt';
1217
+        $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
1218
+
1219
+        // creating a test file
1220
+        $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1221
+
1222
+        if (file_exists($testFile)) {// already running this test, possible recursive call
1223
+            return false;
1224
+        }
1225
+
1226
+        $fp = @fopen($testFile, 'w');
1227
+        if (!$fp) {
1228
+            throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
1229
+                'Make sure it is possible for the webserver to write to ' . $testFile);
1230
+        }
1231
+        fwrite($fp, $testContent);
1232
+        fclose($fp);
1233
+
1234
+        return $testContent;
1235
+    }
1236
+
1237
+    /**
1238
+     * Check if the .htaccess file is working
1239
+     * @param \OCP\IConfig $config
1240
+     * @return bool
1241
+     * @throws Exception
1242
+     * @throws \OC\HintException If the test file can't get written.
1243
+     */
1244
+    public function isHtaccessWorking(\OCP\IConfig $config) {
1245
+        if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) {
1246
+            return true;
1247
+        }
1248
+
1249
+        $testContent = $this->createHtaccessTestFile($config);
1250
+        if ($testContent === false) {
1251
+            return false;
1252
+        }
1253
+
1254
+        $fileName = '/htaccesstest.txt';
1255
+        $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
1256
+
1257
+        // accessing the file via http
1258
+        $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
1259
+        try {
1260
+            $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1261
+        } catch (\Exception $e) {
1262
+            $content = false;
1263
+        }
1264
+
1265
+        if (strpos($url, 'https:') === 0) {
1266
+            $url = 'http:' . substr($url, 6);
1267
+        } else {
1268
+            $url = 'https:' . substr($url, 5);
1269
+        }
1270
+
1271
+        try {
1272
+            $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
1273
+        } catch (\Exception $e) {
1274
+            $fallbackContent = false;
1275
+        }
1276
+
1277
+        // cleanup
1278
+        @unlink($testFile);
1279
+
1280
+        /*
1281 1281
 		 * If the content is not equal to test content our .htaccess
1282 1282
 		 * is working as required
1283 1283
 		 */
1284
-		return $content !== $testContent && $fallbackContent !== $testContent;
1285
-	}
1286
-
1287
-	/**
1288
-	 * Check if the setlocal call does not work. This can happen if the right
1289
-	 * local packages are not available on the server.
1290
-	 *
1291
-	 * @return bool
1292
-	 */
1293
-	public static function isSetLocaleWorking() {
1294
-		\Patchwork\Utf8\Bootup::initLocale();
1295
-		if ('' === basename('§')) {
1296
-			return false;
1297
-		}
1298
-		return true;
1299
-	}
1300
-
1301
-	/**
1302
-	 * Check if it's possible to get the inline annotations
1303
-	 *
1304
-	 * @return bool
1305
-	 */
1306
-	public static function isAnnotationsWorking() {
1307
-		$reflection = new \ReflectionMethod(__METHOD__);
1308
-		$docs = $reflection->getDocComment();
1309
-
1310
-		return (is_string($docs) && strlen($docs) > 50);
1311
-	}
1312
-
1313
-	/**
1314
-	 * Check if the PHP module fileinfo is loaded.
1315
-	 *
1316
-	 * @return bool
1317
-	 */
1318
-	public static function fileInfoLoaded() {
1319
-		return function_exists('finfo_open');
1320
-	}
1321
-
1322
-	/**
1323
-	 * clear all levels of output buffering
1324
-	 *
1325
-	 * @return void
1326
-	 */
1327
-	public static function obEnd() {
1328
-		while (ob_get_level()) {
1329
-			ob_end_clean();
1330
-		}
1331
-	}
1332
-
1333
-	/**
1334
-	 * Checks whether the server is running on Mac OS X
1335
-	 *
1336
-	 * @return bool true if running on Mac OS X, false otherwise
1337
-	 */
1338
-	public static function runningOnMac() {
1339
-		return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
1340
-	}
1341
-
1342
-	/**
1343
-	 * Handles the case that there may not be a theme, then check if a "default"
1344
-	 * theme exists and take that one
1345
-	 *
1346
-	 * @return string the theme
1347
-	 */
1348
-	public static function getTheme() {
1349
-		$theme = \OC::$server->getSystemConfig()->getValue("theme", '');
1350
-
1351
-		if ($theme === '') {
1352
-			if (is_dir(OC::$SERVERROOT . '/themes/default')) {
1353
-				$theme = 'default';
1354
-			}
1355
-		}
1356
-
1357
-		return $theme;
1358
-	}
1359
-
1360
-	/**
1361
-	 * Normalize a unicode string
1362
-	 *
1363
-	 * @param string $value a not normalized string
1364
-	 * @return bool|string
1365
-	 */
1366
-	public static function normalizeUnicode($value) {
1367
-		if (Normalizer::isNormalized($value)) {
1368
-			return $value;
1369
-		}
1370
-
1371
-		$normalizedValue = Normalizer::normalize($value);
1372
-		if ($normalizedValue === null || $normalizedValue === false) {
1373
-			\OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
1374
-			return $value;
1375
-		}
1376
-
1377
-		return $normalizedValue;
1378
-	}
1379
-
1380
-	/**
1381
-	 * A human readable string is generated based on version and build number
1382
-	 *
1383
-	 * @return string
1384
-	 */
1385
-	public static function getHumanVersion() {
1386
-		$version = OC_Util::getVersionString();
1387
-		$build = OC_Util::getBuild();
1388
-		if (!empty($build) and OC_Util::getChannel() === 'daily') {
1389
-			$version .= ' Build:' . $build;
1390
-		}
1391
-		return $version;
1392
-	}
1393
-
1394
-	/**
1395
-	 * Returns whether the given file name is valid
1396
-	 *
1397
-	 * @param string $file file name to check
1398
-	 * @return bool true if the file name is valid, false otherwise
1399
-	 * @deprecated use \OC\Files\View::verifyPath()
1400
-	 */
1401
-	public static function isValidFileName($file) {
1402
-		$trimmed = trim($file);
1403
-		if ($trimmed === '') {
1404
-			return false;
1405
-		}
1406
-		if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
1407
-			return false;
1408
-		}
1409
-
1410
-		// detect part files
1411
-		if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) {
1412
-			return false;
1413
-		}
1414
-
1415
-		foreach (str_split($trimmed) as $char) {
1416
-			if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
1417
-				return false;
1418
-			}
1419
-		}
1420
-		return true;
1421
-	}
1422
-
1423
-	/**
1424
-	 * Check whether the instance needs to perform an upgrade,
1425
-	 * either when the core version is higher or any app requires
1426
-	 * an upgrade.
1427
-	 *
1428
-	 * @param \OC\SystemConfig $config
1429
-	 * @return bool whether the core or any app needs an upgrade
1430
-	 * @throws \OC\HintException When the upgrade from the given version is not allowed
1431
-	 */
1432
-	public static function needUpgrade(\OC\SystemConfig $config) {
1433
-		if ($config->getValue('installed', false)) {
1434
-			$installedVersion = $config->getValue('version', '0.0.0');
1435
-			$currentVersion = implode('.', \OCP\Util::getVersion());
1436
-			$versionDiff = version_compare($currentVersion, $installedVersion);
1437
-			if ($versionDiff > 0) {
1438
-				return true;
1439
-			} elseif ($config->getValue('debug', false) && $versionDiff < 0) {
1440
-				// downgrade with debug
1441
-				$installedMajor = explode('.', $installedVersion);
1442
-				$installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
1443
-				$currentMajor = explode('.', $currentVersion);
1444
-				$currentMajor = $currentMajor[0] . '.' . $currentMajor[1];
1445
-				if ($installedMajor === $currentMajor) {
1446
-					// Same major, allow downgrade for developers
1447
-					return true;
1448
-				} else {
1449
-					// downgrade attempt, throw exception
1450
-					throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1451
-				}
1452
-			} elseif ($versionDiff < 0) {
1453
-				// downgrade attempt, throw exception
1454
-				throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1455
-			}
1456
-
1457
-			// also check for upgrades for apps (independently from the user)
1458
-			$apps = \OC_App::getEnabledApps(false, true);
1459
-			$shouldUpgrade = false;
1460
-			foreach ($apps as $app) {
1461
-				if (\OC_App::shouldUpgrade($app)) {
1462
-					$shouldUpgrade = true;
1463
-					break;
1464
-				}
1465
-			}
1466
-			return $shouldUpgrade;
1467
-		} else {
1468
-			return false;
1469
-		}
1470
-	}
1471
-
1472
-	/**
1473
-	 * is this Internet explorer ?
1474
-	 *
1475
-	 * @return boolean
1476
-	 */
1477
-	public static function isIe() {
1478
-		if (!isset($_SERVER['HTTP_USER_AGENT'])) {
1479
-			return false;
1480
-		}
1481
-
1482
-		return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1;
1483
-	}
1284
+        return $content !== $testContent && $fallbackContent !== $testContent;
1285
+    }
1286
+
1287
+    /**
1288
+     * Check if the setlocal call does not work. This can happen if the right
1289
+     * local packages are not available on the server.
1290
+     *
1291
+     * @return bool
1292
+     */
1293
+    public static function isSetLocaleWorking() {
1294
+        \Patchwork\Utf8\Bootup::initLocale();
1295
+        if ('' === basename('§')) {
1296
+            return false;
1297
+        }
1298
+        return true;
1299
+    }
1300
+
1301
+    /**
1302
+     * Check if it's possible to get the inline annotations
1303
+     *
1304
+     * @return bool
1305
+     */
1306
+    public static function isAnnotationsWorking() {
1307
+        $reflection = new \ReflectionMethod(__METHOD__);
1308
+        $docs = $reflection->getDocComment();
1309
+
1310
+        return (is_string($docs) && strlen($docs) > 50);
1311
+    }
1312
+
1313
+    /**
1314
+     * Check if the PHP module fileinfo is loaded.
1315
+     *
1316
+     * @return bool
1317
+     */
1318
+    public static function fileInfoLoaded() {
1319
+        return function_exists('finfo_open');
1320
+    }
1321
+
1322
+    /**
1323
+     * clear all levels of output buffering
1324
+     *
1325
+     * @return void
1326
+     */
1327
+    public static function obEnd() {
1328
+        while (ob_get_level()) {
1329
+            ob_end_clean();
1330
+        }
1331
+    }
1332
+
1333
+    /**
1334
+     * Checks whether the server is running on Mac OS X
1335
+     *
1336
+     * @return bool true if running on Mac OS X, false otherwise
1337
+     */
1338
+    public static function runningOnMac() {
1339
+        return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN');
1340
+    }
1341
+
1342
+    /**
1343
+     * Handles the case that there may not be a theme, then check if a "default"
1344
+     * theme exists and take that one
1345
+     *
1346
+     * @return string the theme
1347
+     */
1348
+    public static function getTheme() {
1349
+        $theme = \OC::$server->getSystemConfig()->getValue("theme", '');
1350
+
1351
+        if ($theme === '') {
1352
+            if (is_dir(OC::$SERVERROOT . '/themes/default')) {
1353
+                $theme = 'default';
1354
+            }
1355
+        }
1356
+
1357
+        return $theme;
1358
+    }
1359
+
1360
+    /**
1361
+     * Normalize a unicode string
1362
+     *
1363
+     * @param string $value a not normalized string
1364
+     * @return bool|string
1365
+     */
1366
+    public static function normalizeUnicode($value) {
1367
+        if (Normalizer::isNormalized($value)) {
1368
+            return $value;
1369
+        }
1370
+
1371
+        $normalizedValue = Normalizer::normalize($value);
1372
+        if ($normalizedValue === null || $normalizedValue === false) {
1373
+            \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']);
1374
+            return $value;
1375
+        }
1376
+
1377
+        return $normalizedValue;
1378
+    }
1379
+
1380
+    /**
1381
+     * A human readable string is generated based on version and build number
1382
+     *
1383
+     * @return string
1384
+     */
1385
+    public static function getHumanVersion() {
1386
+        $version = OC_Util::getVersionString();
1387
+        $build = OC_Util::getBuild();
1388
+        if (!empty($build) and OC_Util::getChannel() === 'daily') {
1389
+            $version .= ' Build:' . $build;
1390
+        }
1391
+        return $version;
1392
+    }
1393
+
1394
+    /**
1395
+     * Returns whether the given file name is valid
1396
+     *
1397
+     * @param string $file file name to check
1398
+     * @return bool true if the file name is valid, false otherwise
1399
+     * @deprecated use \OC\Files\View::verifyPath()
1400
+     */
1401
+    public static function isValidFileName($file) {
1402
+        $trimmed = trim($file);
1403
+        if ($trimmed === '') {
1404
+            return false;
1405
+        }
1406
+        if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
1407
+            return false;
1408
+        }
1409
+
1410
+        // detect part files
1411
+        if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) {
1412
+            return false;
1413
+        }
1414
+
1415
+        foreach (str_split($trimmed) as $char) {
1416
+            if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) {
1417
+                return false;
1418
+            }
1419
+        }
1420
+        return true;
1421
+    }
1422
+
1423
+    /**
1424
+     * Check whether the instance needs to perform an upgrade,
1425
+     * either when the core version is higher or any app requires
1426
+     * an upgrade.
1427
+     *
1428
+     * @param \OC\SystemConfig $config
1429
+     * @return bool whether the core or any app needs an upgrade
1430
+     * @throws \OC\HintException When the upgrade from the given version is not allowed
1431
+     */
1432
+    public static function needUpgrade(\OC\SystemConfig $config) {
1433
+        if ($config->getValue('installed', false)) {
1434
+            $installedVersion = $config->getValue('version', '0.0.0');
1435
+            $currentVersion = implode('.', \OCP\Util::getVersion());
1436
+            $versionDiff = version_compare($currentVersion, $installedVersion);
1437
+            if ($versionDiff > 0) {
1438
+                return true;
1439
+            } elseif ($config->getValue('debug', false) && $versionDiff < 0) {
1440
+                // downgrade with debug
1441
+                $installedMajor = explode('.', $installedVersion);
1442
+                $installedMajor = $installedMajor[0] . '.' . $installedMajor[1];
1443
+                $currentMajor = explode('.', $currentVersion);
1444
+                $currentMajor = $currentMajor[0] . '.' . $currentMajor[1];
1445
+                if ($installedMajor === $currentMajor) {
1446
+                    // Same major, allow downgrade for developers
1447
+                    return true;
1448
+                } else {
1449
+                    // downgrade attempt, throw exception
1450
+                    throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1451
+                }
1452
+            } elseif ($versionDiff < 0) {
1453
+                // downgrade attempt, throw exception
1454
+                throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')');
1455
+            }
1456
+
1457
+            // also check for upgrades for apps (independently from the user)
1458
+            $apps = \OC_App::getEnabledApps(false, true);
1459
+            $shouldUpgrade = false;
1460
+            foreach ($apps as $app) {
1461
+                if (\OC_App::shouldUpgrade($app)) {
1462
+                    $shouldUpgrade = true;
1463
+                    break;
1464
+                }
1465
+            }
1466
+            return $shouldUpgrade;
1467
+        } else {
1468
+            return false;
1469
+        }
1470
+    }
1471
+
1472
+    /**
1473
+     * is this Internet explorer ?
1474
+     *
1475
+     * @return boolean
1476
+     */
1477
+    public static function isIe() {
1478
+        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
1479
+            return false;
1480
+        }
1481
+
1482
+        return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1;
1483
+    }
1484 1484
 }
Please login to merge, or discard this patch.
lib/public/Files/Config/IRootMountProvider.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@
 block discarded – undo
31 31
  * @since 20.0.0
32 32
  */
33 33
 interface IRootMountProvider {
34
-	/**
35
-	 * Get all root mountpoints
36
-	 *
37
-	 * @return \OCP\Files\Mount\IMountPoint[]
38
-	 * @since 20.0.0
39
-	 */
40
-	public function getRootMounts(IStorageFactory $loader): array;
34
+    /**
35
+     * Get all root mountpoints
36
+     *
37
+     * @return \OCP\Files\Mount\IMountPoint[]
38
+     * @since 20.0.0
39
+     */
40
+    public function getRootMounts(IStorageFactory $loader): array;
41 41
 }
Please login to merge, or discard this patch.