Completed
Pull Request — master (#5897)
by Morris
14:30
created
lib/private/Share20/Manager.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,6 @@
 block discarded – undo
31 31
 use OC\Files\Mount\MoveableMount;
32 32
 use OC\HintException;
33 33
 use OC\Share20\Exception\ProviderException;
34
-use OCP\Defaults;
35 34
 use OCP\Files\File;
36 35
 use OCP\Files\Folder;
37 36
 use OCP\Files\IRootFolder;
Please login to merge, or discard this patch.
Indentation   +1458 added lines, -1458 removed lines patch added patch discarded remove patch
@@ -59,1486 +59,1486 @@
 block discarded – undo
59 59
  */
60 60
 class Manager implements IManager {
61 61
 
62
-	/** @var IProviderFactory */
63
-	private $factory;
64
-	/** @var ILogger */
65
-	private $logger;
66
-	/** @var IConfig */
67
-	private $config;
68
-	/** @var ISecureRandom */
69
-	private $secureRandom;
70
-	/** @var IHasher */
71
-	private $hasher;
72
-	/** @var IMountManager */
73
-	private $mountManager;
74
-	/** @var IGroupManager */
75
-	private $groupManager;
76
-	/** @var IL10N */
77
-	private $l;
78
-	/** @var IUserManager */
79
-	private $userManager;
80
-	/** @var IRootFolder */
81
-	private $rootFolder;
82
-	/** @var CappedMemoryCache */
83
-	private $sharingDisabledForUsersCache;
84
-	/** @var EventDispatcher */
85
-	private $eventDispatcher;
86
-	/** @var LegacyHooks */
87
-	private $legacyHooks;
88
-	/** @var IMailer */
89
-	private $mailer;
90
-	/** @var IURLGenerator */
91
-	private $urlGenerator;
92
-	/** @var \OC_Defaults */
93
-	private $defaults;
94
-
95
-
96
-	/**
97
-	 * Manager constructor.
98
-	 *
99
-	 * @param ILogger $logger
100
-	 * @param IConfig $config
101
-	 * @param ISecureRandom $secureRandom
102
-	 * @param IHasher $hasher
103
-	 * @param IMountManager $mountManager
104
-	 * @param IGroupManager $groupManager
105
-	 * @param IL10N $l
106
-	 * @param IProviderFactory $factory
107
-	 * @param IUserManager $userManager
108
-	 * @param IRootFolder $rootFolder
109
-	 * @param EventDispatcher $eventDispatcher
110
-	 * @param IMailer $mailer
111
-	 * @param IURLGenerator $urlGenerator
112
-	 * @param \OC_Defaults $defaults
113
-	 */
114
-	public function __construct(
115
-			ILogger $logger,
116
-			IConfig $config,
117
-			ISecureRandom $secureRandom,
118
-			IHasher $hasher,
119
-			IMountManager $mountManager,
120
-			IGroupManager $groupManager,
121
-			IL10N $l,
122
-			IProviderFactory $factory,
123
-			IUserManager $userManager,
124
-			IRootFolder $rootFolder,
125
-			EventDispatcher $eventDispatcher,
126
-			IMailer $mailer,
127
-			IURLGenerator $urlGenerator,
128
-			\OC_Defaults $defaults
129
-	) {
130
-		$this->logger = $logger;
131
-		$this->config = $config;
132
-		$this->secureRandom = $secureRandom;
133
-		$this->hasher = $hasher;
134
-		$this->mountManager = $mountManager;
135
-		$this->groupManager = $groupManager;
136
-		$this->l = $l;
137
-		$this->factory = $factory;
138
-		$this->userManager = $userManager;
139
-		$this->rootFolder = $rootFolder;
140
-		$this->eventDispatcher = $eventDispatcher;
141
-		$this->sharingDisabledForUsersCache = new CappedMemoryCache();
142
-		$this->legacyHooks = new LegacyHooks($this->eventDispatcher);
143
-		$this->mailer = $mailer;
144
-		$this->urlGenerator = $urlGenerator;
145
-		$this->defaults = $defaults;
146
-	}
147
-
148
-	/**
149
-	 * Convert from a full share id to a tuple (providerId, shareId)
150
-	 *
151
-	 * @param string $id
152
-	 * @return string[]
153
-	 */
154
-	private function splitFullId($id) {
155
-		return explode(':', $id, 2);
156
-	}
157
-
158
-	/**
159
-	 * Verify if a password meets all requirements
160
-	 *
161
-	 * @param string $password
162
-	 * @throws \Exception
163
-	 */
164
-	protected function verifyPassword($password) {
165
-		if ($password === null) {
166
-			// No password is set, check if this is allowed.
167
-			if ($this->shareApiLinkEnforcePassword()) {
168
-				throw new \InvalidArgumentException('Passwords are enforced for link shares');
169
-			}
170
-
171
-			return;
172
-		}
173
-
174
-		// Let others verify the password
175
-		try {
176
-			$event = new GenericEvent($password);
177
-			$this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event);
178
-		} catch (HintException $e) {
179
-			throw new \Exception($e->getHint());
180
-		}
181
-	}
182
-
183
-	/**
184
-	 * Check for generic requirements before creating a share
185
-	 *
186
-	 * @param \OCP\Share\IShare $share
187
-	 * @throws \InvalidArgumentException
188
-	 * @throws GenericShareException
189
-	 *
190
-	 * @suppress PhanUndeclaredClassMethod
191
-	 */
192
-	protected function generalCreateChecks(\OCP\Share\IShare $share) {
193
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
194
-			// We expect a valid user as sharedWith for user shares
195
-			if (!$this->userManager->userExists($share->getSharedWith())) {
196
-				throw new \InvalidArgumentException('SharedWith is not a valid user');
197
-			}
198
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
199
-			// We expect a valid group as sharedWith for group shares
200
-			if (!$this->groupManager->groupExists($share->getSharedWith())) {
201
-				throw new \InvalidArgumentException('SharedWith is not a valid group');
202
-			}
203
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
204
-			if ($share->getSharedWith() !== null) {
205
-				throw new \InvalidArgumentException('SharedWith should be empty');
206
-			}
207
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
208
-			if ($share->getSharedWith() === null) {
209
-				throw new \InvalidArgumentException('SharedWith should not be empty');
210
-			}
211
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
212
-			if ($share->getSharedWith() === null) {
213
-				throw new \InvalidArgumentException('SharedWith should not be empty');
214
-			}
215
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
216
-			$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith());
217
-			if ($circle === null) {
218
-				throw new \InvalidArgumentException('SharedWith is not a valid circle');
219
-			}
220
-		} else {
221
-			// We can't handle other types yet
222
-			throw new \InvalidArgumentException('unknown share type');
223
-		}
224
-
225
-		// Verify the initiator of the share is set
226
-		if ($share->getSharedBy() === null) {
227
-			throw new \InvalidArgumentException('SharedBy should be set');
228
-		}
229
-
230
-		// Cannot share with yourself
231
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
232
-			$share->getSharedWith() === $share->getSharedBy()) {
233
-			throw new \InvalidArgumentException('Can’t share with yourself');
234
-		}
235
-
236
-		// The path should be set
237
-		if ($share->getNode() === null) {
238
-			throw new \InvalidArgumentException('Path should be set');
239
-		}
240
-
241
-		// And it should be a file or a folder
242
-		if (!($share->getNode() instanceof \OCP\Files\File) &&
243
-				!($share->getNode() instanceof \OCP\Files\Folder)) {
244
-			throw new \InvalidArgumentException('Path should be either a file or a folder');
245
-		}
246
-
247
-		// And you can't share your rootfolder
248
-		if ($this->userManager->userExists($share->getSharedBy())) {
249
-			$sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath();
250
-		} else {
251
-			$sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath();
252
-		}
253
-		if ($sharedPath === $share->getNode()->getPath()) {
254
-			throw new \InvalidArgumentException('You can’t share your root folder');
255
-		}
256
-
257
-		// Check if we actually have share permissions
258
-		if (!$share->getNode()->isShareable()) {
259
-			$message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
260
-			throw new GenericShareException($message_t, $message_t, 404);
261
-		}
262
-
263
-		// Permissions should be set
264
-		if ($share->getPermissions() === null) {
265
-			throw new \InvalidArgumentException('A share requires permissions');
266
-		}
267
-
268
-		/*
62
+    /** @var IProviderFactory */
63
+    private $factory;
64
+    /** @var ILogger */
65
+    private $logger;
66
+    /** @var IConfig */
67
+    private $config;
68
+    /** @var ISecureRandom */
69
+    private $secureRandom;
70
+    /** @var IHasher */
71
+    private $hasher;
72
+    /** @var IMountManager */
73
+    private $mountManager;
74
+    /** @var IGroupManager */
75
+    private $groupManager;
76
+    /** @var IL10N */
77
+    private $l;
78
+    /** @var IUserManager */
79
+    private $userManager;
80
+    /** @var IRootFolder */
81
+    private $rootFolder;
82
+    /** @var CappedMemoryCache */
83
+    private $sharingDisabledForUsersCache;
84
+    /** @var EventDispatcher */
85
+    private $eventDispatcher;
86
+    /** @var LegacyHooks */
87
+    private $legacyHooks;
88
+    /** @var IMailer */
89
+    private $mailer;
90
+    /** @var IURLGenerator */
91
+    private $urlGenerator;
92
+    /** @var \OC_Defaults */
93
+    private $defaults;
94
+
95
+
96
+    /**
97
+     * Manager constructor.
98
+     *
99
+     * @param ILogger $logger
100
+     * @param IConfig $config
101
+     * @param ISecureRandom $secureRandom
102
+     * @param IHasher $hasher
103
+     * @param IMountManager $mountManager
104
+     * @param IGroupManager $groupManager
105
+     * @param IL10N $l
106
+     * @param IProviderFactory $factory
107
+     * @param IUserManager $userManager
108
+     * @param IRootFolder $rootFolder
109
+     * @param EventDispatcher $eventDispatcher
110
+     * @param IMailer $mailer
111
+     * @param IURLGenerator $urlGenerator
112
+     * @param \OC_Defaults $defaults
113
+     */
114
+    public function __construct(
115
+            ILogger $logger,
116
+            IConfig $config,
117
+            ISecureRandom $secureRandom,
118
+            IHasher $hasher,
119
+            IMountManager $mountManager,
120
+            IGroupManager $groupManager,
121
+            IL10N $l,
122
+            IProviderFactory $factory,
123
+            IUserManager $userManager,
124
+            IRootFolder $rootFolder,
125
+            EventDispatcher $eventDispatcher,
126
+            IMailer $mailer,
127
+            IURLGenerator $urlGenerator,
128
+            \OC_Defaults $defaults
129
+    ) {
130
+        $this->logger = $logger;
131
+        $this->config = $config;
132
+        $this->secureRandom = $secureRandom;
133
+        $this->hasher = $hasher;
134
+        $this->mountManager = $mountManager;
135
+        $this->groupManager = $groupManager;
136
+        $this->l = $l;
137
+        $this->factory = $factory;
138
+        $this->userManager = $userManager;
139
+        $this->rootFolder = $rootFolder;
140
+        $this->eventDispatcher = $eventDispatcher;
141
+        $this->sharingDisabledForUsersCache = new CappedMemoryCache();
142
+        $this->legacyHooks = new LegacyHooks($this->eventDispatcher);
143
+        $this->mailer = $mailer;
144
+        $this->urlGenerator = $urlGenerator;
145
+        $this->defaults = $defaults;
146
+    }
147
+
148
+    /**
149
+     * Convert from a full share id to a tuple (providerId, shareId)
150
+     *
151
+     * @param string $id
152
+     * @return string[]
153
+     */
154
+    private function splitFullId($id) {
155
+        return explode(':', $id, 2);
156
+    }
157
+
158
+    /**
159
+     * Verify if a password meets all requirements
160
+     *
161
+     * @param string $password
162
+     * @throws \Exception
163
+     */
164
+    protected function verifyPassword($password) {
165
+        if ($password === null) {
166
+            // No password is set, check if this is allowed.
167
+            if ($this->shareApiLinkEnforcePassword()) {
168
+                throw new \InvalidArgumentException('Passwords are enforced for link shares');
169
+            }
170
+
171
+            return;
172
+        }
173
+
174
+        // Let others verify the password
175
+        try {
176
+            $event = new GenericEvent($password);
177
+            $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event);
178
+        } catch (HintException $e) {
179
+            throw new \Exception($e->getHint());
180
+        }
181
+    }
182
+
183
+    /**
184
+     * Check for generic requirements before creating a share
185
+     *
186
+     * @param \OCP\Share\IShare $share
187
+     * @throws \InvalidArgumentException
188
+     * @throws GenericShareException
189
+     *
190
+     * @suppress PhanUndeclaredClassMethod
191
+     */
192
+    protected function generalCreateChecks(\OCP\Share\IShare $share) {
193
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
194
+            // We expect a valid user as sharedWith for user shares
195
+            if (!$this->userManager->userExists($share->getSharedWith())) {
196
+                throw new \InvalidArgumentException('SharedWith is not a valid user');
197
+            }
198
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
199
+            // We expect a valid group as sharedWith for group shares
200
+            if (!$this->groupManager->groupExists($share->getSharedWith())) {
201
+                throw new \InvalidArgumentException('SharedWith is not a valid group');
202
+            }
203
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
204
+            if ($share->getSharedWith() !== null) {
205
+                throw new \InvalidArgumentException('SharedWith should be empty');
206
+            }
207
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
208
+            if ($share->getSharedWith() === null) {
209
+                throw new \InvalidArgumentException('SharedWith should not be empty');
210
+            }
211
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
212
+            if ($share->getSharedWith() === null) {
213
+                throw new \InvalidArgumentException('SharedWith should not be empty');
214
+            }
215
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
216
+            $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith());
217
+            if ($circle === null) {
218
+                throw new \InvalidArgumentException('SharedWith is not a valid circle');
219
+            }
220
+        } else {
221
+            // We can't handle other types yet
222
+            throw new \InvalidArgumentException('unknown share type');
223
+        }
224
+
225
+        // Verify the initiator of the share is set
226
+        if ($share->getSharedBy() === null) {
227
+            throw new \InvalidArgumentException('SharedBy should be set');
228
+        }
229
+
230
+        // Cannot share with yourself
231
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
232
+            $share->getSharedWith() === $share->getSharedBy()) {
233
+            throw new \InvalidArgumentException('Can’t share with yourself');
234
+        }
235
+
236
+        // The path should be set
237
+        if ($share->getNode() === null) {
238
+            throw new \InvalidArgumentException('Path should be set');
239
+        }
240
+
241
+        // And it should be a file or a folder
242
+        if (!($share->getNode() instanceof \OCP\Files\File) &&
243
+                !($share->getNode() instanceof \OCP\Files\Folder)) {
244
+            throw new \InvalidArgumentException('Path should be either a file or a folder');
245
+        }
246
+
247
+        // And you can't share your rootfolder
248
+        if ($this->userManager->userExists($share->getSharedBy())) {
249
+            $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath();
250
+        } else {
251
+            $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath();
252
+        }
253
+        if ($sharedPath === $share->getNode()->getPath()) {
254
+            throw new \InvalidArgumentException('You can’t share your root folder');
255
+        }
256
+
257
+        // Check if we actually have share permissions
258
+        if (!$share->getNode()->isShareable()) {
259
+            $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
260
+            throw new GenericShareException($message_t, $message_t, 404);
261
+        }
262
+
263
+        // Permissions should be set
264
+        if ($share->getPermissions() === null) {
265
+            throw new \InvalidArgumentException('A share requires permissions');
266
+        }
267
+
268
+        /*
269 269
 		 * Quick fix for #23536
270 270
 		 * Non moveable mount points do not have update and delete permissions
271 271
 		 * while we 'most likely' do have that on the storage.
272 272
 		 */
273
-		$permissions = $share->getNode()->getPermissions();
274
-		$mount = $share->getNode()->getMountPoint();
275
-		if (!($mount instanceof MoveableMount)) {
276
-			$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
277
-		}
278
-
279
-		// Check that we do not share with more permissions than we have
280
-		if ($share->getPermissions() & ~$permissions) {
281
-			$message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]);
282
-			throw new GenericShareException($message_t, $message_t, 404);
283
-		}
284
-
285
-
286
-		// Check that read permissions are always set
287
-		// Link shares are allowed to have no read permissions to allow upload to hidden folders
288
-		$noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK
289
-			|| $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL;
290
-		if (!$noReadPermissionRequired &&
291
-			($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
292
-			throw new \InvalidArgumentException('Shares need at least read permissions');
293
-		}
294
-
295
-		if ($share->getNode() instanceof \OCP\Files\File) {
296
-			if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
297
-				$message_t = $this->l->t('Files can’t be shared with delete permissions');
298
-				throw new GenericShareException($message_t);
299
-			}
300
-			if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
301
-				$message_t = $this->l->t('Files can’t be shared with create permissions');
302
-				throw new GenericShareException($message_t);
303
-			}
304
-		}
305
-	}
306
-
307
-	/**
308
-	 * Validate if the expiration date fits the system settings
309
-	 *
310
-	 * @param \OCP\Share\IShare $share The share to validate the expiration date of
311
-	 * @return \OCP\Share\IShare The modified share object
312
-	 * @throws GenericShareException
313
-	 * @throws \InvalidArgumentException
314
-	 * @throws \Exception
315
-	 */
316
-	protected function validateExpirationDate(\OCP\Share\IShare $share) {
317
-
318
-		$expirationDate = $share->getExpirationDate();
319
-
320
-		if ($expirationDate !== null) {
321
-			//Make sure the expiration date is a date
322
-			$expirationDate->setTime(0, 0, 0);
323
-
324
-			$date = new \DateTime();
325
-			$date->setTime(0, 0, 0);
326
-			if ($date >= $expirationDate) {
327
-				$message = $this->l->t('Expiration date is in the past');
328
-				throw new GenericShareException($message, $message, 404);
329
-			}
330
-		}
331
-
332
-		// If expiredate is empty set a default one if there is a default
333
-		$fullId = null;
334
-		try {
335
-			$fullId = $share->getFullId();
336
-		} catch (\UnexpectedValueException $e) {
337
-			// This is a new share
338
-		}
339
-
340
-		if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
341
-			$expirationDate = new \DateTime();
342
-			$expirationDate->setTime(0,0,0);
343
-			$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
344
-		}
345
-
346
-		// If we enforce the expiration date check that is does not exceed
347
-		if ($this->shareApiLinkDefaultExpireDateEnforced()) {
348
-			if ($expirationDate === null) {
349
-				throw new \InvalidArgumentException('Expiration date is enforced');
350
-			}
351
-
352
-			$date = new \DateTime();
353
-			$date->setTime(0, 0, 0);
354
-			$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
355
-			if ($date < $expirationDate) {
356
-				$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
357
-				throw new GenericShareException($message, $message, 404);
358
-			}
359
-		}
360
-
361
-		$accepted = true;
362
-		$message = '';
363
-		\OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [
364
-			'expirationDate' => &$expirationDate,
365
-			'accepted' => &$accepted,
366
-			'message' => &$message,
367
-			'passwordSet' => $share->getPassword() !== null,
368
-		]);
369
-
370
-		if (!$accepted) {
371
-			throw new \Exception($message);
372
-		}
373
-
374
-		$share->setExpirationDate($expirationDate);
375
-
376
-		return $share;
377
-	}
378
-
379
-	/**
380
-	 * Check for pre share requirements for user shares
381
-	 *
382
-	 * @param \OCP\Share\IShare $share
383
-	 * @throws \Exception
384
-	 */
385
-	protected function userCreateChecks(\OCP\Share\IShare $share) {
386
-		// Check if we can share with group members only
387
-		if ($this->shareWithGroupMembersOnly()) {
388
-			$sharedBy = $this->userManager->get($share->getSharedBy());
389
-			$sharedWith = $this->userManager->get($share->getSharedWith());
390
-			// Verify we can share with this user
391
-			$groups = array_intersect(
392
-					$this->groupManager->getUserGroupIds($sharedBy),
393
-					$this->groupManager->getUserGroupIds($sharedWith)
394
-			);
395
-			if (empty($groups)) {
396
-				throw new \Exception('Sharing is only allowed with group members');
397
-			}
398
-		}
399
-
400
-		/*
273
+        $permissions = $share->getNode()->getPermissions();
274
+        $mount = $share->getNode()->getMountPoint();
275
+        if (!($mount instanceof MoveableMount)) {
276
+            $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
277
+        }
278
+
279
+        // Check that we do not share with more permissions than we have
280
+        if ($share->getPermissions() & ~$permissions) {
281
+            $message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]);
282
+            throw new GenericShareException($message_t, $message_t, 404);
283
+        }
284
+
285
+
286
+        // Check that read permissions are always set
287
+        // Link shares are allowed to have no read permissions to allow upload to hidden folders
288
+        $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK
289
+            || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL;
290
+        if (!$noReadPermissionRequired &&
291
+            ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
292
+            throw new \InvalidArgumentException('Shares need at least read permissions');
293
+        }
294
+
295
+        if ($share->getNode() instanceof \OCP\Files\File) {
296
+            if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
297
+                $message_t = $this->l->t('Files can’t be shared with delete permissions');
298
+                throw new GenericShareException($message_t);
299
+            }
300
+            if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
301
+                $message_t = $this->l->t('Files can’t be shared with create permissions');
302
+                throw new GenericShareException($message_t);
303
+            }
304
+        }
305
+    }
306
+
307
+    /**
308
+     * Validate if the expiration date fits the system settings
309
+     *
310
+     * @param \OCP\Share\IShare $share The share to validate the expiration date of
311
+     * @return \OCP\Share\IShare The modified share object
312
+     * @throws GenericShareException
313
+     * @throws \InvalidArgumentException
314
+     * @throws \Exception
315
+     */
316
+    protected function validateExpirationDate(\OCP\Share\IShare $share) {
317
+
318
+        $expirationDate = $share->getExpirationDate();
319
+
320
+        if ($expirationDate !== null) {
321
+            //Make sure the expiration date is a date
322
+            $expirationDate->setTime(0, 0, 0);
323
+
324
+            $date = new \DateTime();
325
+            $date->setTime(0, 0, 0);
326
+            if ($date >= $expirationDate) {
327
+                $message = $this->l->t('Expiration date is in the past');
328
+                throw new GenericShareException($message, $message, 404);
329
+            }
330
+        }
331
+
332
+        // If expiredate is empty set a default one if there is a default
333
+        $fullId = null;
334
+        try {
335
+            $fullId = $share->getFullId();
336
+        } catch (\UnexpectedValueException $e) {
337
+            // This is a new share
338
+        }
339
+
340
+        if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
341
+            $expirationDate = new \DateTime();
342
+            $expirationDate->setTime(0,0,0);
343
+            $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
344
+        }
345
+
346
+        // If we enforce the expiration date check that is does not exceed
347
+        if ($this->shareApiLinkDefaultExpireDateEnforced()) {
348
+            if ($expirationDate === null) {
349
+                throw new \InvalidArgumentException('Expiration date is enforced');
350
+            }
351
+
352
+            $date = new \DateTime();
353
+            $date->setTime(0, 0, 0);
354
+            $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
355
+            if ($date < $expirationDate) {
356
+                $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
357
+                throw new GenericShareException($message, $message, 404);
358
+            }
359
+        }
360
+
361
+        $accepted = true;
362
+        $message = '';
363
+        \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [
364
+            'expirationDate' => &$expirationDate,
365
+            'accepted' => &$accepted,
366
+            'message' => &$message,
367
+            'passwordSet' => $share->getPassword() !== null,
368
+        ]);
369
+
370
+        if (!$accepted) {
371
+            throw new \Exception($message);
372
+        }
373
+
374
+        $share->setExpirationDate($expirationDate);
375
+
376
+        return $share;
377
+    }
378
+
379
+    /**
380
+     * Check for pre share requirements for user shares
381
+     *
382
+     * @param \OCP\Share\IShare $share
383
+     * @throws \Exception
384
+     */
385
+    protected function userCreateChecks(\OCP\Share\IShare $share) {
386
+        // Check if we can share with group members only
387
+        if ($this->shareWithGroupMembersOnly()) {
388
+            $sharedBy = $this->userManager->get($share->getSharedBy());
389
+            $sharedWith = $this->userManager->get($share->getSharedWith());
390
+            // Verify we can share with this user
391
+            $groups = array_intersect(
392
+                    $this->groupManager->getUserGroupIds($sharedBy),
393
+                    $this->groupManager->getUserGroupIds($sharedWith)
394
+            );
395
+            if (empty($groups)) {
396
+                throw new \Exception('Sharing is only allowed with group members');
397
+            }
398
+        }
399
+
400
+        /*
401 401
 		 * TODO: Could be costly, fix
402 402
 		 *
403 403
 		 * Also this is not what we want in the future.. then we want to squash identical shares.
404 404
 		 */
405
-		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
406
-		$existingShares = $provider->getSharesByPath($share->getNode());
407
-		foreach($existingShares as $existingShare) {
408
-			// Ignore if it is the same share
409
-			try {
410
-				if ($existingShare->getFullId() === $share->getFullId()) {
411
-					continue;
412
-				}
413
-			} catch (\UnexpectedValueException $e) {
414
-				//Shares are not identical
415
-			}
416
-
417
-			// Identical share already existst
418
-			if ($existingShare->getSharedWith() === $share->getSharedWith()) {
419
-				throw new \Exception('Path is already shared with this user');
420
-			}
421
-
422
-			// The share is already shared with this user via a group share
423
-			if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
424
-				$group = $this->groupManager->get($existingShare->getSharedWith());
425
-				if (!is_null($group)) {
426
-					$user = $this->userManager->get($share->getSharedWith());
427
-
428
-					if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
429
-						throw new \Exception('Path is already shared with this user');
430
-					}
431
-				}
432
-			}
433
-		}
434
-	}
435
-
436
-	/**
437
-	 * Check for pre share requirements for group shares
438
-	 *
439
-	 * @param \OCP\Share\IShare $share
440
-	 * @throws \Exception
441
-	 */
442
-	protected function groupCreateChecks(\OCP\Share\IShare $share) {
443
-		// Verify group shares are allowed
444
-		if (!$this->allowGroupSharing()) {
445
-			throw new \Exception('Group sharing is now allowed');
446
-		}
447
-
448
-		// Verify if the user can share with this group
449
-		if ($this->shareWithGroupMembersOnly()) {
450
-			$sharedBy = $this->userManager->get($share->getSharedBy());
451
-			$sharedWith = $this->groupManager->get($share->getSharedWith());
452
-			if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) {
453
-				throw new \Exception('Sharing is only allowed within your own groups');
454
-			}
455
-		}
456
-
457
-		/*
405
+        $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
406
+        $existingShares = $provider->getSharesByPath($share->getNode());
407
+        foreach($existingShares as $existingShare) {
408
+            // Ignore if it is the same share
409
+            try {
410
+                if ($existingShare->getFullId() === $share->getFullId()) {
411
+                    continue;
412
+                }
413
+            } catch (\UnexpectedValueException $e) {
414
+                //Shares are not identical
415
+            }
416
+
417
+            // Identical share already existst
418
+            if ($existingShare->getSharedWith() === $share->getSharedWith()) {
419
+                throw new \Exception('Path is already shared with this user');
420
+            }
421
+
422
+            // The share is already shared with this user via a group share
423
+            if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
424
+                $group = $this->groupManager->get($existingShare->getSharedWith());
425
+                if (!is_null($group)) {
426
+                    $user = $this->userManager->get($share->getSharedWith());
427
+
428
+                    if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
429
+                        throw new \Exception('Path is already shared with this user');
430
+                    }
431
+                }
432
+            }
433
+        }
434
+    }
435
+
436
+    /**
437
+     * Check for pre share requirements for group shares
438
+     *
439
+     * @param \OCP\Share\IShare $share
440
+     * @throws \Exception
441
+     */
442
+    protected function groupCreateChecks(\OCP\Share\IShare $share) {
443
+        // Verify group shares are allowed
444
+        if (!$this->allowGroupSharing()) {
445
+            throw new \Exception('Group sharing is now allowed');
446
+        }
447
+
448
+        // Verify if the user can share with this group
449
+        if ($this->shareWithGroupMembersOnly()) {
450
+            $sharedBy = $this->userManager->get($share->getSharedBy());
451
+            $sharedWith = $this->groupManager->get($share->getSharedWith());
452
+            if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) {
453
+                throw new \Exception('Sharing is only allowed within your own groups');
454
+            }
455
+        }
456
+
457
+        /*
458 458
 		 * TODO: Could be costly, fix
459 459
 		 *
460 460
 		 * Also this is not what we want in the future.. then we want to squash identical shares.
461 461
 		 */
462
-		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
463
-		$existingShares = $provider->getSharesByPath($share->getNode());
464
-		foreach($existingShares as $existingShare) {
465
-			try {
466
-				if ($existingShare->getFullId() === $share->getFullId()) {
467
-					continue;
468
-				}
469
-			} catch (\UnexpectedValueException $e) {
470
-				//It is a new share so just continue
471
-			}
472
-
473
-			if ($existingShare->getSharedWith() === $share->getSharedWith()) {
474
-				throw new \Exception('Path is already shared with this group');
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Check for pre share requirements for link shares
481
-	 *
482
-	 * @param \OCP\Share\IShare $share
483
-	 * @throws \Exception
484
-	 */
485
-	protected function linkCreateChecks(\OCP\Share\IShare $share) {
486
-		// Are link shares allowed?
487
-		if (!$this->shareApiAllowLinks()) {
488
-			throw new \Exception('Link sharing is not allowed');
489
-		}
490
-
491
-		// Link shares by definition can't have share permissions
492
-		if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) {
493
-			throw new \InvalidArgumentException('Link shares can’t have reshare permissions');
494
-		}
495
-
496
-		// Check if public upload is allowed
497
-		if (!$this->shareApiLinkAllowPublicUpload() &&
498
-			($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) {
499
-			throw new \InvalidArgumentException('Public upload is not allowed');
500
-		}
501
-	}
502
-
503
-	/**
504
-	 * To make sure we don't get invisible link shares we set the parent
505
-	 * of a link if it is a reshare. This is a quick word around
506
-	 * until we can properly display multiple link shares in the UI
507
-	 *
508
-	 * See: https://github.com/owncloud/core/issues/22295
509
-	 *
510
-	 * FIXME: Remove once multiple link shares can be properly displayed
511
-	 *
512
-	 * @param \OCP\Share\IShare $share
513
-	 */
514
-	protected function setLinkParent(\OCP\Share\IShare $share) {
515
-
516
-		// No sense in checking if the method is not there.
517
-		if (method_exists($share, 'setParent')) {
518
-			$storage = $share->getNode()->getStorage();
519
-			if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
520
-				/** @var \OCA\Files_Sharing\SharedStorage $storage */
521
-				$share->setParent($storage->getShareId());
522
-			}
523
-		};
524
-	}
525
-
526
-	/**
527
-	 * @param File|Folder $path
528
-	 */
529
-	protected function pathCreateChecks($path) {
530
-		// Make sure that we do not share a path that contains a shared mountpoint
531
-		if ($path instanceof \OCP\Files\Folder) {
532
-			$mounts = $this->mountManager->findIn($path->getPath());
533
-			foreach($mounts as $mount) {
534
-				if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
535
-					throw new \InvalidArgumentException('Path contains files shared with you');
536
-				}
537
-			}
538
-		}
539
-	}
540
-
541
-	/**
542
-	 * Check if the user that is sharing can actually share
543
-	 *
544
-	 * @param \OCP\Share\IShare $share
545
-	 * @throws \Exception
546
-	 */
547
-	protected function canShare(\OCP\Share\IShare $share) {
548
-		if (!$this->shareApiEnabled()) {
549
-			throw new \Exception('Sharing is disabled');
550
-		}
551
-
552
-		if ($this->sharingDisabledForUser($share->getSharedBy())) {
553
-			throw new \Exception('Sharing is disabled for you');
554
-		}
555
-	}
556
-
557
-	/**
558
-	 * Share a path
559
-	 *
560
-	 * @param \OCP\Share\IShare $share
561
-	 * @return Share The share object
562
-	 * @throws \Exception
563
-	 *
564
-	 * TODO: handle link share permissions or check them
565
-	 */
566
-	public function createShare(\OCP\Share\IShare $share) {
567
-		$this->canShare($share);
568
-
569
-		$this->generalCreateChecks($share);
570
-
571
-		// Verify if there are any issues with the path
572
-		$this->pathCreateChecks($share->getNode());
573
-
574
-		/*
462
+        $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
463
+        $existingShares = $provider->getSharesByPath($share->getNode());
464
+        foreach($existingShares as $existingShare) {
465
+            try {
466
+                if ($existingShare->getFullId() === $share->getFullId()) {
467
+                    continue;
468
+                }
469
+            } catch (\UnexpectedValueException $e) {
470
+                //It is a new share so just continue
471
+            }
472
+
473
+            if ($existingShare->getSharedWith() === $share->getSharedWith()) {
474
+                throw new \Exception('Path is already shared with this group');
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Check for pre share requirements for link shares
481
+     *
482
+     * @param \OCP\Share\IShare $share
483
+     * @throws \Exception
484
+     */
485
+    protected function linkCreateChecks(\OCP\Share\IShare $share) {
486
+        // Are link shares allowed?
487
+        if (!$this->shareApiAllowLinks()) {
488
+            throw new \Exception('Link sharing is not allowed');
489
+        }
490
+
491
+        // Link shares by definition can't have share permissions
492
+        if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) {
493
+            throw new \InvalidArgumentException('Link shares can’t have reshare permissions');
494
+        }
495
+
496
+        // Check if public upload is allowed
497
+        if (!$this->shareApiLinkAllowPublicUpload() &&
498
+            ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) {
499
+            throw new \InvalidArgumentException('Public upload is not allowed');
500
+        }
501
+    }
502
+
503
+    /**
504
+     * To make sure we don't get invisible link shares we set the parent
505
+     * of a link if it is a reshare. This is a quick word around
506
+     * until we can properly display multiple link shares in the UI
507
+     *
508
+     * See: https://github.com/owncloud/core/issues/22295
509
+     *
510
+     * FIXME: Remove once multiple link shares can be properly displayed
511
+     *
512
+     * @param \OCP\Share\IShare $share
513
+     */
514
+    protected function setLinkParent(\OCP\Share\IShare $share) {
515
+
516
+        // No sense in checking if the method is not there.
517
+        if (method_exists($share, 'setParent')) {
518
+            $storage = $share->getNode()->getStorage();
519
+            if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
520
+                /** @var \OCA\Files_Sharing\SharedStorage $storage */
521
+                $share->setParent($storage->getShareId());
522
+            }
523
+        };
524
+    }
525
+
526
+    /**
527
+     * @param File|Folder $path
528
+     */
529
+    protected function pathCreateChecks($path) {
530
+        // Make sure that we do not share a path that contains a shared mountpoint
531
+        if ($path instanceof \OCP\Files\Folder) {
532
+            $mounts = $this->mountManager->findIn($path->getPath());
533
+            foreach($mounts as $mount) {
534
+                if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
535
+                    throw new \InvalidArgumentException('Path contains files shared with you');
536
+                }
537
+            }
538
+        }
539
+    }
540
+
541
+    /**
542
+     * Check if the user that is sharing can actually share
543
+     *
544
+     * @param \OCP\Share\IShare $share
545
+     * @throws \Exception
546
+     */
547
+    protected function canShare(\OCP\Share\IShare $share) {
548
+        if (!$this->shareApiEnabled()) {
549
+            throw new \Exception('Sharing is disabled');
550
+        }
551
+
552
+        if ($this->sharingDisabledForUser($share->getSharedBy())) {
553
+            throw new \Exception('Sharing is disabled for you');
554
+        }
555
+    }
556
+
557
+    /**
558
+     * Share a path
559
+     *
560
+     * @param \OCP\Share\IShare $share
561
+     * @return Share The share object
562
+     * @throws \Exception
563
+     *
564
+     * TODO: handle link share permissions or check them
565
+     */
566
+    public function createShare(\OCP\Share\IShare $share) {
567
+        $this->canShare($share);
568
+
569
+        $this->generalCreateChecks($share);
570
+
571
+        // Verify if there are any issues with the path
572
+        $this->pathCreateChecks($share->getNode());
573
+
574
+        /*
575 575
 		 * On creation of a share the owner is always the owner of the path
576 576
 		 * Except for mounted federated shares.
577 577
 		 */
578
-		$storage = $share->getNode()->getStorage();
579
-		if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
580
-			$parent = $share->getNode()->getParent();
581
-			while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
582
-				$parent = $parent->getParent();
583
-			}
584
-			$share->setShareOwner($parent->getOwner()->getUID());
585
-		} else {
586
-			$share->setShareOwner($share->getNode()->getOwner()->getUID());
587
-		}
588
-
589
-		//Verify share type
590
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
591
-			$this->userCreateChecks($share);
592
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
593
-			$this->groupCreateChecks($share);
594
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
595
-			$this->linkCreateChecks($share);
596
-			$this->setLinkParent($share);
597
-
598
-			/*
578
+        $storage = $share->getNode()->getStorage();
579
+        if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
580
+            $parent = $share->getNode()->getParent();
581
+            while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
582
+                $parent = $parent->getParent();
583
+            }
584
+            $share->setShareOwner($parent->getOwner()->getUID());
585
+        } else {
586
+            $share->setShareOwner($share->getNode()->getOwner()->getUID());
587
+        }
588
+
589
+        //Verify share type
590
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
591
+            $this->userCreateChecks($share);
592
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
593
+            $this->groupCreateChecks($share);
594
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
595
+            $this->linkCreateChecks($share);
596
+            $this->setLinkParent($share);
597
+
598
+            /*
599 599
 			 * For now ignore a set token.
600 600
 			 */
601
-			$share->setToken(
602
-				$this->secureRandom->generate(
603
-					\OC\Share\Constants::TOKEN_LENGTH,
604
-					\OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE
605
-				)
606
-			);
607
-
608
-			//Verify the expiration date
609
-			$this->validateExpirationDate($share);
610
-
611
-			//Verify the password
612
-			$this->verifyPassword($share->getPassword());
613
-
614
-			// If a password is set. Hash it!
615
-			if ($share->getPassword() !== null) {
616
-				$share->setPassword($this->hasher->hash($share->getPassword()));
617
-			}
618
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
619
-			$share->setToken(
620
-				$this->secureRandom->generate(
621
-					\OC\Share\Constants::TOKEN_LENGTH,
622
-					\OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE
623
-				)
624
-			);
625
-		}
626
-
627
-		// Cannot share with the owner
628
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
629
-			$share->getSharedWith() === $share->getShareOwner()) {
630
-			throw new \InvalidArgumentException('Can’t share with the share owner');
631
-		}
632
-
633
-		// Generate the target
634
-		$target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName();
635
-		$target = \OC\Files\Filesystem::normalizePath($target);
636
-		$share->setTarget($target);
637
-
638
-		// Pre share hook
639
-		$run = true;
640
-		$error = '';
641
-		$preHookData = [
642
-			'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
643
-			'itemSource' => $share->getNode()->getId(),
644
-			'shareType' => $share->getShareType(),
645
-			'uidOwner' => $share->getSharedBy(),
646
-			'permissions' => $share->getPermissions(),
647
-			'fileSource' => $share->getNode()->getId(),
648
-			'expiration' => $share->getExpirationDate(),
649
-			'token' => $share->getToken(),
650
-			'itemTarget' => $share->getTarget(),
651
-			'shareWith' => $share->getSharedWith(),
652
-			'run' => &$run,
653
-			'error' => &$error,
654
-		];
655
-		\OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
656
-
657
-		if ($run === false) {
658
-			throw new \Exception($error);
659
-		}
660
-
661
-		$oldShare = $share;
662
-		$provider = $this->factory->getProviderForType($share->getShareType());
663
-		$share = $provider->create($share);
664
-		//reuse the node we already have
665
-		$share->setNode($oldShare->getNode());
666
-
667
-		// Post share hook
668
-		$postHookData = [
669
-			'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
670
-			'itemSource' => $share->getNode()->getId(),
671
-			'shareType' => $share->getShareType(),
672
-			'uidOwner' => $share->getSharedBy(),
673
-			'permissions' => $share->getPermissions(),
674
-			'fileSource' => $share->getNode()->getId(),
675
-			'expiration' => $share->getExpirationDate(),
676
-			'token' => $share->getToken(),
677
-			'id' => $share->getId(),
678
-			'shareWith' => $share->getSharedWith(),
679
-			'itemTarget' => $share->getTarget(),
680
-			'fileTarget' => $share->getTarget(),
681
-		];
682
-
683
-		\OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
684
-
685
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
686
-			$user = $this->userManager->get($share->getSharedWith());
687
-			if ($user !== null) {
688
-				$emailAddress = $user->getEMailAddress();
689
-				if ($emailAddress !== null && $emailAddress !== '') {
690
-					$this->sendMailNotification(
691
-						$share->getNode()->getName(),
692
-						$this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]),
693
-						$share->getSharedBy(),
694
-						$emailAddress
695
-					);
696
-					$this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']);
697
-				} else {
698
-					$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
699
-				}
700
-			} else {
701
-				$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
702
-			}
703
-		}
704
-
705
-		return $share;
706
-	}
707
-
708
-	/**
709
-	 * @param string $filename file/folder name
710
-	 * @param string $link link to the file/folder
711
-	 * @param string $initiator user ID of share sender
712
-	 * @param string $shareWith email address of share receiver
713
-	 * @throws \Exception If mail couldn't be sent
714
-	 */
715
-	protected function sendMailNotification($filename,
716
-											$link,
717
-											$initiator,
718
-											$shareWith) {
719
-		$initiatorUser = $this->userManager->get($initiator);
720
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
721
-		$subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));
722
-
723
-		$message = $this->mailer->createMessage();
724
-
725
-		$emailTemplate = $this->mailer->createEMailTemplate();
726
-
727
-		$emailTemplate->addHeader();
728
-		$emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false);
729
-		$text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);
730
-
731
-		$emailTemplate->addBodyText(
732
-			$text . ' ' . $this->l->t('Click the button below to open it.'),
733
-			$text
734
-		);
735
-		$emailTemplate->addBodyButton(
736
-			$this->l->t('Open »%s«', [$filename]),
737
-			$link
738
-		);
739
-
740
-		$message->setTo([$shareWith]);
741
-
742
-		// The "From" contains the sharers name
743
-		$instanceName = $this->defaults->getName();
744
-		$senderName = $this->l->t(
745
-			'%s via %s',
746
-			[
747
-				$initiatorDisplayName,
748
-				$instanceName
749
-			]
750
-		);
751
-		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
752
-
753
-		// The "Reply-To" is set to the sharer if an mail address is configured
754
-		// also the default footer contains a "Do not reply" which needs to be adjusted.
755
-		$initiatorEmail = $initiatorUser->getEMailAddress();
756
-		if($initiatorEmail !== null) {
757
-			$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
758
-			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
759
-		} else {
760
-			$emailTemplate->addFooter();
761
-		}
762
-
763
-		$message->setSubject($subject);
764
-		$message->setPlainBody($emailTemplate->renderText());
765
-		$message->setHtmlBody($emailTemplate->renderHtml());
766
-		$this->mailer->send($message);
767
-	}
768
-
769
-	/**
770
-	 * Update a share
771
-	 *
772
-	 * @param \OCP\Share\IShare $share
773
-	 * @return \OCP\Share\IShare The share object
774
-	 * @throws \InvalidArgumentException
775
-	 */
776
-	public function updateShare(\OCP\Share\IShare $share) {
777
-		$expirationDateUpdated = false;
778
-
779
-		$this->canShare($share);
780
-
781
-		try {
782
-			$originalShare = $this->getShareById($share->getFullId());
783
-		} catch (\UnexpectedValueException $e) {
784
-			throw new \InvalidArgumentException('Share does not have a full id');
785
-		}
786
-
787
-		// We can't change the share type!
788
-		if ($share->getShareType() !== $originalShare->getShareType()) {
789
-			throw new \InvalidArgumentException('Can’t change share type');
790
-		}
791
-
792
-		// We can only change the recipient on user shares
793
-		if ($share->getSharedWith() !== $originalShare->getSharedWith() &&
794
-		    $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) {
795
-			throw new \InvalidArgumentException('Can only update recipient on user shares');
796
-		}
797
-
798
-		// Cannot share with the owner
799
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
800
-			$share->getSharedWith() === $share->getShareOwner()) {
801
-			throw new \InvalidArgumentException('Can’t share with the share owner');
802
-		}
803
-
804
-		$this->generalCreateChecks($share);
805
-
806
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
807
-			$this->userCreateChecks($share);
808
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
809
-			$this->groupCreateChecks($share);
810
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
811
-			$this->linkCreateChecks($share);
812
-
813
-			$this->updateSharePasswordIfNeeded($share, $originalShare);
814
-
815
-			if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
816
-				//Verify the expiration date
817
-				$this->validateExpirationDate($share);
818
-				$expirationDateUpdated = true;
819
-			}
820
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
821
-			$plainTextPassword = $share->getPassword();
822
-			if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) {
823
-				$plainTextPassword = null;
824
-			}
825
-		}
826
-
827
-		$this->pathCreateChecks($share->getNode());
828
-
829
-		// Now update the share!
830
-		$provider = $this->factory->getProviderForType($share->getShareType());
831
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
832
-			$share = $provider->update($share, $plainTextPassword);
833
-		} else {
834
-			$share = $provider->update($share);
835
-		}
836
-
837
-		if ($expirationDateUpdated === true) {
838
-			\OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [
839
-				'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
840
-				'itemSource' => $share->getNode()->getId(),
841
-				'date' => $share->getExpirationDate(),
842
-				'uidOwner' => $share->getSharedBy(),
843
-			]);
844
-		}
845
-
846
-		if ($share->getPassword() !== $originalShare->getPassword()) {
847
-			\OC_Hook::emit('OCP\Share', 'post_update_password', [
848
-				'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
849
-				'itemSource' => $share->getNode()->getId(),
850
-				'uidOwner' => $share->getSharedBy(),
851
-				'token' => $share->getToken(),
852
-				'disabled' => is_null($share->getPassword()),
853
-			]);
854
-		}
855
-
856
-		if ($share->getPermissions() !== $originalShare->getPermissions()) {
857
-			if ($this->userManager->userExists($share->getShareOwner())) {
858
-				$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
859
-			} else {
860
-				$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
861
-			}
862
-			\OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
863
-				'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
864
-				'itemSource' => $share->getNode()->getId(),
865
-				'shareType' => $share->getShareType(),
866
-				'shareWith' => $share->getSharedWith(),
867
-				'uidOwner' => $share->getSharedBy(),
868
-				'permissions' => $share->getPermissions(),
869
-				'path' => $userFolder->getRelativePath($share->getNode()->getPath()),
870
-			));
871
-		}
872
-
873
-		return $share;
874
-	}
875
-
876
-	/**
877
-	 * Updates the password of the given share if it is not the same as the
878
-	 * password of the original share.
879
-	 *
880
-	 * @param \OCP\Share\IShare $share the share to update its password.
881
-	 * @param \OCP\Share\IShare $originalShare the original share to compare its
882
-	 *        password with.
883
-	 * @return boolean whether the password was updated or not.
884
-	 */
885
-	private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) {
886
-		// Password updated.
887
-		if ($share->getPassword() !== $originalShare->getPassword()) {
888
-			//Verify the password
889
-			$this->verifyPassword($share->getPassword());
890
-
891
-			// If a password is set. Hash it!
892
-			if ($share->getPassword() !== null) {
893
-				$share->setPassword($this->hasher->hash($share->getPassword()));
894
-
895
-				return true;
896
-			}
897
-		}
898
-
899
-		return false;
900
-	}
901
-
902
-	/**
903
-	 * Delete all the children of this share
904
-	 * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
905
-	 *
906
-	 * @param \OCP\Share\IShare $share
907
-	 * @return \OCP\Share\IShare[] List of deleted shares
908
-	 */
909
-	protected function deleteChildren(\OCP\Share\IShare $share) {
910
-		$deletedShares = [];
911
-
912
-		$provider = $this->factory->getProviderForType($share->getShareType());
913
-
914
-		foreach ($provider->getChildren($share) as $child) {
915
-			$deletedChildren = $this->deleteChildren($child);
916
-			$deletedShares = array_merge($deletedShares, $deletedChildren);
917
-
918
-			$provider->delete($child);
919
-			$deletedShares[] = $child;
920
-		}
921
-
922
-		return $deletedShares;
923
-	}
924
-
925
-	/**
926
-	 * Delete a share
927
-	 *
928
-	 * @param \OCP\Share\IShare $share
929
-	 * @throws ShareNotFound
930
-	 * @throws \InvalidArgumentException
931
-	 */
932
-	public function deleteShare(\OCP\Share\IShare $share) {
933
-
934
-		try {
935
-			$share->getFullId();
936
-		} catch (\UnexpectedValueException $e) {
937
-			throw new \InvalidArgumentException('Share does not have a full id');
938
-		}
939
-
940
-		$event = new GenericEvent($share);
941
-		$this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
942
-
943
-		// Get all children and delete them as well
944
-		$deletedShares = $this->deleteChildren($share);
945
-
946
-		// Do the actual delete
947
-		$provider = $this->factory->getProviderForType($share->getShareType());
948
-		$provider->delete($share);
949
-
950
-		// All the deleted shares caused by this delete
951
-		$deletedShares[] = $share;
952
-
953
-		// Emit post hook
954
-		$event->setArgument('deletedShares', $deletedShares);
955
-		$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
956
-	}
957
-
958
-
959
-	/**
960
-	 * Unshare a file as the recipient.
961
-	 * This can be different from a regular delete for example when one of
962
-	 * the users in a groups deletes that share. But the provider should
963
-	 * handle this.
964
-	 *
965
-	 * @param \OCP\Share\IShare $share
966
-	 * @param string $recipientId
967
-	 */
968
-	public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
969
-		list($providerId, ) = $this->splitFullId($share->getFullId());
970
-		$provider = $this->factory->getProvider($providerId);
971
-
972
-		$provider->deleteFromSelf($share, $recipientId);
973
-		$event = new GenericEvent($share);
974
-		$this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
975
-	}
976
-
977
-	/**
978
-	 * @inheritdoc
979
-	 */
980
-	public function moveShare(\OCP\Share\IShare $share, $recipientId) {
981
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
982
-			throw new \InvalidArgumentException('Can’t change target of link share');
983
-		}
984
-
985
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) {
986
-			throw new \InvalidArgumentException('Invalid recipient');
987
-		}
988
-
989
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
990
-			$sharedWith = $this->groupManager->get($share->getSharedWith());
991
-			if (is_null($sharedWith)) {
992
-				throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist');
993
-			}
994
-			$recipient = $this->userManager->get($recipientId);
995
-			if (!$sharedWith->inGroup($recipient)) {
996
-				throw new \InvalidArgumentException('Invalid recipient');
997
-			}
998
-		}
999
-
1000
-		list($providerId, ) = $this->splitFullId($share->getFullId());
1001
-		$provider = $this->factory->getProvider($providerId);
1002
-
1003
-		$provider->move($share, $recipientId);
1004
-	}
1005
-
1006
-	public function getSharesInFolder($userId, Folder $node, $reshares = false) {
1007
-		$providers = $this->factory->getAllProviders();
1008
-
1009
-		return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) {
1010
-			$newShares = $provider->getSharesInFolder($userId, $node, $reshares);
1011
-			foreach ($newShares as $fid => $data) {
1012
-				if (!isset($shares[$fid])) {
1013
-					$shares[$fid] = [];
1014
-				}
1015
-
1016
-				$shares[$fid] = array_merge($shares[$fid], $data);
1017
-			}
1018
-			return $shares;
1019
-		}, []);
1020
-	}
1021
-
1022
-	/**
1023
-	 * @inheritdoc
1024
-	 */
1025
-	public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
1026
-		if ($path !== null &&
1027
-				!($path instanceof \OCP\Files\File) &&
1028
-				!($path instanceof \OCP\Files\Folder)) {
1029
-			throw new \InvalidArgumentException('invalid path');
1030
-		}
1031
-
1032
-		try {
1033
-			$provider = $this->factory->getProviderForType($shareType);
1034
-		} catch (ProviderException $e) {
1035
-			return [];
1036
-		}
1037
-
1038
-		$shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
1039
-
1040
-		/*
601
+            $share->setToken(
602
+                $this->secureRandom->generate(
603
+                    \OC\Share\Constants::TOKEN_LENGTH,
604
+                    \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE
605
+                )
606
+            );
607
+
608
+            //Verify the expiration date
609
+            $this->validateExpirationDate($share);
610
+
611
+            //Verify the password
612
+            $this->verifyPassword($share->getPassword());
613
+
614
+            // If a password is set. Hash it!
615
+            if ($share->getPassword() !== null) {
616
+                $share->setPassword($this->hasher->hash($share->getPassword()));
617
+            }
618
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
619
+            $share->setToken(
620
+                $this->secureRandom->generate(
621
+                    \OC\Share\Constants::TOKEN_LENGTH,
622
+                    \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE
623
+                )
624
+            );
625
+        }
626
+
627
+        // Cannot share with the owner
628
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
629
+            $share->getSharedWith() === $share->getShareOwner()) {
630
+            throw new \InvalidArgumentException('Can’t share with the share owner');
631
+        }
632
+
633
+        // Generate the target
634
+        $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName();
635
+        $target = \OC\Files\Filesystem::normalizePath($target);
636
+        $share->setTarget($target);
637
+
638
+        // Pre share hook
639
+        $run = true;
640
+        $error = '';
641
+        $preHookData = [
642
+            'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
643
+            'itemSource' => $share->getNode()->getId(),
644
+            'shareType' => $share->getShareType(),
645
+            'uidOwner' => $share->getSharedBy(),
646
+            'permissions' => $share->getPermissions(),
647
+            'fileSource' => $share->getNode()->getId(),
648
+            'expiration' => $share->getExpirationDate(),
649
+            'token' => $share->getToken(),
650
+            'itemTarget' => $share->getTarget(),
651
+            'shareWith' => $share->getSharedWith(),
652
+            'run' => &$run,
653
+            'error' => &$error,
654
+        ];
655
+        \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
656
+
657
+        if ($run === false) {
658
+            throw new \Exception($error);
659
+        }
660
+
661
+        $oldShare = $share;
662
+        $provider = $this->factory->getProviderForType($share->getShareType());
663
+        $share = $provider->create($share);
664
+        //reuse the node we already have
665
+        $share->setNode($oldShare->getNode());
666
+
667
+        // Post share hook
668
+        $postHookData = [
669
+            'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
670
+            'itemSource' => $share->getNode()->getId(),
671
+            'shareType' => $share->getShareType(),
672
+            'uidOwner' => $share->getSharedBy(),
673
+            'permissions' => $share->getPermissions(),
674
+            'fileSource' => $share->getNode()->getId(),
675
+            'expiration' => $share->getExpirationDate(),
676
+            'token' => $share->getToken(),
677
+            'id' => $share->getId(),
678
+            'shareWith' => $share->getSharedWith(),
679
+            'itemTarget' => $share->getTarget(),
680
+            'fileTarget' => $share->getTarget(),
681
+        ];
682
+
683
+        \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
684
+
685
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
686
+            $user = $this->userManager->get($share->getSharedWith());
687
+            if ($user !== null) {
688
+                $emailAddress = $user->getEMailAddress();
689
+                if ($emailAddress !== null && $emailAddress !== '') {
690
+                    $this->sendMailNotification(
691
+                        $share->getNode()->getName(),
692
+                        $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]),
693
+                        $share->getSharedBy(),
694
+                        $emailAddress
695
+                    );
696
+                    $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']);
697
+                } else {
698
+                    $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
699
+                }
700
+            } else {
701
+                $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
702
+            }
703
+        }
704
+
705
+        return $share;
706
+    }
707
+
708
+    /**
709
+     * @param string $filename file/folder name
710
+     * @param string $link link to the file/folder
711
+     * @param string $initiator user ID of share sender
712
+     * @param string $shareWith email address of share receiver
713
+     * @throws \Exception If mail couldn't be sent
714
+     */
715
+    protected function sendMailNotification($filename,
716
+                                            $link,
717
+                                            $initiator,
718
+                                            $shareWith) {
719
+        $initiatorUser = $this->userManager->get($initiator);
720
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
721
+        $subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));
722
+
723
+        $message = $this->mailer->createMessage();
724
+
725
+        $emailTemplate = $this->mailer->createEMailTemplate();
726
+
727
+        $emailTemplate->addHeader();
728
+        $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false);
729
+        $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);
730
+
731
+        $emailTemplate->addBodyText(
732
+            $text . ' ' . $this->l->t('Click the button below to open it.'),
733
+            $text
734
+        );
735
+        $emailTemplate->addBodyButton(
736
+            $this->l->t('Open »%s«', [$filename]),
737
+            $link
738
+        );
739
+
740
+        $message->setTo([$shareWith]);
741
+
742
+        // The "From" contains the sharers name
743
+        $instanceName = $this->defaults->getName();
744
+        $senderName = $this->l->t(
745
+            '%s via %s',
746
+            [
747
+                $initiatorDisplayName,
748
+                $instanceName
749
+            ]
750
+        );
751
+        $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
752
+
753
+        // The "Reply-To" is set to the sharer if an mail address is configured
754
+        // also the default footer contains a "Do not reply" which needs to be adjusted.
755
+        $initiatorEmail = $initiatorUser->getEMailAddress();
756
+        if($initiatorEmail !== null) {
757
+            $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
758
+            $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
759
+        } else {
760
+            $emailTemplate->addFooter();
761
+        }
762
+
763
+        $message->setSubject($subject);
764
+        $message->setPlainBody($emailTemplate->renderText());
765
+        $message->setHtmlBody($emailTemplate->renderHtml());
766
+        $this->mailer->send($message);
767
+    }
768
+
769
+    /**
770
+     * Update a share
771
+     *
772
+     * @param \OCP\Share\IShare $share
773
+     * @return \OCP\Share\IShare The share object
774
+     * @throws \InvalidArgumentException
775
+     */
776
+    public function updateShare(\OCP\Share\IShare $share) {
777
+        $expirationDateUpdated = false;
778
+
779
+        $this->canShare($share);
780
+
781
+        try {
782
+            $originalShare = $this->getShareById($share->getFullId());
783
+        } catch (\UnexpectedValueException $e) {
784
+            throw new \InvalidArgumentException('Share does not have a full id');
785
+        }
786
+
787
+        // We can't change the share type!
788
+        if ($share->getShareType() !== $originalShare->getShareType()) {
789
+            throw new \InvalidArgumentException('Can’t change share type');
790
+        }
791
+
792
+        // We can only change the recipient on user shares
793
+        if ($share->getSharedWith() !== $originalShare->getSharedWith() &&
794
+            $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) {
795
+            throw new \InvalidArgumentException('Can only update recipient on user shares');
796
+        }
797
+
798
+        // Cannot share with the owner
799
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
800
+            $share->getSharedWith() === $share->getShareOwner()) {
801
+            throw new \InvalidArgumentException('Can’t share with the share owner');
802
+        }
803
+
804
+        $this->generalCreateChecks($share);
805
+
806
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
807
+            $this->userCreateChecks($share);
808
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
809
+            $this->groupCreateChecks($share);
810
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
811
+            $this->linkCreateChecks($share);
812
+
813
+            $this->updateSharePasswordIfNeeded($share, $originalShare);
814
+
815
+            if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
816
+                //Verify the expiration date
817
+                $this->validateExpirationDate($share);
818
+                $expirationDateUpdated = true;
819
+            }
820
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
821
+            $plainTextPassword = $share->getPassword();
822
+            if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) {
823
+                $plainTextPassword = null;
824
+            }
825
+        }
826
+
827
+        $this->pathCreateChecks($share->getNode());
828
+
829
+        // Now update the share!
830
+        $provider = $this->factory->getProviderForType($share->getShareType());
831
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
832
+            $share = $provider->update($share, $plainTextPassword);
833
+        } else {
834
+            $share = $provider->update($share);
835
+        }
836
+
837
+        if ($expirationDateUpdated === true) {
838
+            \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [
839
+                'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
840
+                'itemSource' => $share->getNode()->getId(),
841
+                'date' => $share->getExpirationDate(),
842
+                'uidOwner' => $share->getSharedBy(),
843
+            ]);
844
+        }
845
+
846
+        if ($share->getPassword() !== $originalShare->getPassword()) {
847
+            \OC_Hook::emit('OCP\Share', 'post_update_password', [
848
+                'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
849
+                'itemSource' => $share->getNode()->getId(),
850
+                'uidOwner' => $share->getSharedBy(),
851
+                'token' => $share->getToken(),
852
+                'disabled' => is_null($share->getPassword()),
853
+            ]);
854
+        }
855
+
856
+        if ($share->getPermissions() !== $originalShare->getPermissions()) {
857
+            if ($this->userManager->userExists($share->getShareOwner())) {
858
+                $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
859
+            } else {
860
+                $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
861
+            }
862
+            \OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
863
+                'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
864
+                'itemSource' => $share->getNode()->getId(),
865
+                'shareType' => $share->getShareType(),
866
+                'shareWith' => $share->getSharedWith(),
867
+                'uidOwner' => $share->getSharedBy(),
868
+                'permissions' => $share->getPermissions(),
869
+                'path' => $userFolder->getRelativePath($share->getNode()->getPath()),
870
+            ));
871
+        }
872
+
873
+        return $share;
874
+    }
875
+
876
+    /**
877
+     * Updates the password of the given share if it is not the same as the
878
+     * password of the original share.
879
+     *
880
+     * @param \OCP\Share\IShare $share the share to update its password.
881
+     * @param \OCP\Share\IShare $originalShare the original share to compare its
882
+     *        password with.
883
+     * @return boolean whether the password was updated or not.
884
+     */
885
+    private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) {
886
+        // Password updated.
887
+        if ($share->getPassword() !== $originalShare->getPassword()) {
888
+            //Verify the password
889
+            $this->verifyPassword($share->getPassword());
890
+
891
+            // If a password is set. Hash it!
892
+            if ($share->getPassword() !== null) {
893
+                $share->setPassword($this->hasher->hash($share->getPassword()));
894
+
895
+                return true;
896
+            }
897
+        }
898
+
899
+        return false;
900
+    }
901
+
902
+    /**
903
+     * Delete all the children of this share
904
+     * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
905
+     *
906
+     * @param \OCP\Share\IShare $share
907
+     * @return \OCP\Share\IShare[] List of deleted shares
908
+     */
909
+    protected function deleteChildren(\OCP\Share\IShare $share) {
910
+        $deletedShares = [];
911
+
912
+        $provider = $this->factory->getProviderForType($share->getShareType());
913
+
914
+        foreach ($provider->getChildren($share) as $child) {
915
+            $deletedChildren = $this->deleteChildren($child);
916
+            $deletedShares = array_merge($deletedShares, $deletedChildren);
917
+
918
+            $provider->delete($child);
919
+            $deletedShares[] = $child;
920
+        }
921
+
922
+        return $deletedShares;
923
+    }
924
+
925
+    /**
926
+     * Delete a share
927
+     *
928
+     * @param \OCP\Share\IShare $share
929
+     * @throws ShareNotFound
930
+     * @throws \InvalidArgumentException
931
+     */
932
+    public function deleteShare(\OCP\Share\IShare $share) {
933
+
934
+        try {
935
+            $share->getFullId();
936
+        } catch (\UnexpectedValueException $e) {
937
+            throw new \InvalidArgumentException('Share does not have a full id');
938
+        }
939
+
940
+        $event = new GenericEvent($share);
941
+        $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
942
+
943
+        // Get all children and delete them as well
944
+        $deletedShares = $this->deleteChildren($share);
945
+
946
+        // Do the actual delete
947
+        $provider = $this->factory->getProviderForType($share->getShareType());
948
+        $provider->delete($share);
949
+
950
+        // All the deleted shares caused by this delete
951
+        $deletedShares[] = $share;
952
+
953
+        // Emit post hook
954
+        $event->setArgument('deletedShares', $deletedShares);
955
+        $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
956
+    }
957
+
958
+
959
+    /**
960
+     * Unshare a file as the recipient.
961
+     * This can be different from a regular delete for example when one of
962
+     * the users in a groups deletes that share. But the provider should
963
+     * handle this.
964
+     *
965
+     * @param \OCP\Share\IShare $share
966
+     * @param string $recipientId
967
+     */
968
+    public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
969
+        list($providerId, ) = $this->splitFullId($share->getFullId());
970
+        $provider = $this->factory->getProvider($providerId);
971
+
972
+        $provider->deleteFromSelf($share, $recipientId);
973
+        $event = new GenericEvent($share);
974
+        $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
975
+    }
976
+
977
+    /**
978
+     * @inheritdoc
979
+     */
980
+    public function moveShare(\OCP\Share\IShare $share, $recipientId) {
981
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
982
+            throw new \InvalidArgumentException('Can’t change target of link share');
983
+        }
984
+
985
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) {
986
+            throw new \InvalidArgumentException('Invalid recipient');
987
+        }
988
+
989
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
990
+            $sharedWith = $this->groupManager->get($share->getSharedWith());
991
+            if (is_null($sharedWith)) {
992
+                throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist');
993
+            }
994
+            $recipient = $this->userManager->get($recipientId);
995
+            if (!$sharedWith->inGroup($recipient)) {
996
+                throw new \InvalidArgumentException('Invalid recipient');
997
+            }
998
+        }
999
+
1000
+        list($providerId, ) = $this->splitFullId($share->getFullId());
1001
+        $provider = $this->factory->getProvider($providerId);
1002
+
1003
+        $provider->move($share, $recipientId);
1004
+    }
1005
+
1006
+    public function getSharesInFolder($userId, Folder $node, $reshares = false) {
1007
+        $providers = $this->factory->getAllProviders();
1008
+
1009
+        return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) {
1010
+            $newShares = $provider->getSharesInFolder($userId, $node, $reshares);
1011
+            foreach ($newShares as $fid => $data) {
1012
+                if (!isset($shares[$fid])) {
1013
+                    $shares[$fid] = [];
1014
+                }
1015
+
1016
+                $shares[$fid] = array_merge($shares[$fid], $data);
1017
+            }
1018
+            return $shares;
1019
+        }, []);
1020
+    }
1021
+
1022
+    /**
1023
+     * @inheritdoc
1024
+     */
1025
+    public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
1026
+        if ($path !== null &&
1027
+                !($path instanceof \OCP\Files\File) &&
1028
+                !($path instanceof \OCP\Files\Folder)) {
1029
+            throw new \InvalidArgumentException('invalid path');
1030
+        }
1031
+
1032
+        try {
1033
+            $provider = $this->factory->getProviderForType($shareType);
1034
+        } catch (ProviderException $e) {
1035
+            return [];
1036
+        }
1037
+
1038
+        $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
1039
+
1040
+        /*
1041 1041
 		 * Work around so we don't return expired shares but still follow
1042 1042
 		 * proper pagination.
1043 1043
 		 */
1044 1044
 
1045
-		$shares2 = [];
1046
-
1047
-		while(true) {
1048
-			$added = 0;
1049
-			foreach ($shares as $share) {
1050
-
1051
-				try {
1052
-					$this->checkExpireDate($share);
1053
-				} catch (ShareNotFound $e) {
1054
-					//Ignore since this basically means the share is deleted
1055
-					continue;
1056
-				}
1057
-
1058
-				$added++;
1059
-				$shares2[] = $share;
1060
-
1061
-				if (count($shares2) === $limit) {
1062
-					break;
1063
-				}
1064
-			}
1065
-
1066
-			if (count($shares2) === $limit) {
1067
-				break;
1068
-			}
1069
-
1070
-			// If there was no limit on the select we are done
1071
-			if ($limit === -1) {
1072
-				break;
1073
-			}
1074
-
1075
-			$offset += $added;
1076
-
1077
-			// Fetch again $limit shares
1078
-			$shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
1079
-
1080
-			// No more shares means we are done
1081
-			if (empty($shares)) {
1082
-				break;
1083
-			}
1084
-		}
1085
-
1086
-		$shares = $shares2;
1087
-
1088
-		return $shares;
1089
-	}
1090
-
1091
-	/**
1092
-	 * @inheritdoc
1093
-	 */
1094
-	public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
1095
-		try {
1096
-			$provider = $this->factory->getProviderForType($shareType);
1097
-		} catch (ProviderException $e) {
1098
-			return [];
1099
-		}
1100
-
1101
-		$shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
1102
-
1103
-		// remove all shares which are already expired
1104
-		foreach ($shares as $key => $share) {
1105
-			try {
1106
-				$this->checkExpireDate($share);
1107
-			} catch (ShareNotFound $e) {
1108
-				unset($shares[$key]);
1109
-			}
1110
-		}
1111
-
1112
-		return $shares;
1113
-	}
1114
-
1115
-	/**
1116
-	 * @inheritdoc
1117
-	 */
1118
-	public function getShareById($id, $recipient = null) {
1119
-		if ($id === null) {
1120
-			throw new ShareNotFound();
1121
-		}
1122
-
1123
-		list($providerId, $id) = $this->splitFullId($id);
1124
-
1125
-		try {
1126
-			$provider = $this->factory->getProvider($providerId);
1127
-		} catch (ProviderException $e) {
1128
-			throw new ShareNotFound();
1129
-		}
1130
-
1131
-		$share = $provider->getShareById($id, $recipient);
1132
-
1133
-		$this->checkExpireDate($share);
1134
-
1135
-		return $share;
1136
-	}
1137
-
1138
-	/**
1139
-	 * Get all the shares for a given path
1140
-	 *
1141
-	 * @param \OCP\Files\Node $path
1142
-	 * @param int $page
1143
-	 * @param int $perPage
1144
-	 *
1145
-	 * @return Share[]
1146
-	 */
1147
-	public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
1148
-		return [];
1149
-	}
1150
-
1151
-	/**
1152
-	 * Get the share by token possible with password
1153
-	 *
1154
-	 * @param string $token
1155
-	 * @return Share
1156
-	 *
1157
-	 * @throws ShareNotFound
1158
-	 */
1159
-	public function getShareByToken($token) {
1160
-		$share = null;
1161
-		try {
1162
-			if($this->shareApiAllowLinks()) {
1163
-				$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
1164
-				$share = $provider->getShareByToken($token);
1165
-			}
1166
-		} catch (ProviderException $e) {
1167
-		} catch (ShareNotFound $e) {
1168
-		}
1169
-
1170
-
1171
-		// If it is not a link share try to fetch a federated share by token
1172
-		if ($share === null) {
1173
-			try {
1174
-				$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE);
1175
-				$share = $provider->getShareByToken($token);
1176
-			} catch (ProviderException $e) {
1177
-			} catch (ShareNotFound $e) {
1178
-			}
1179
-		}
1180
-
1181
-		// If it is not a link share try to fetch a mail share by token
1182
-		if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
1183
-			try {
1184
-				$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL);
1185
-				$share = $provider->getShareByToken($token);
1186
-			} catch (ProviderException $e) {
1187
-			} catch (ShareNotFound $e) {
1188
-			}
1189
-		}
1190
-
1191
-		if ($share === null) {
1192
-			throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
1193
-		}
1194
-
1195
-		$this->checkExpireDate($share);
1196
-
1197
-		/*
1045
+        $shares2 = [];
1046
+
1047
+        while(true) {
1048
+            $added = 0;
1049
+            foreach ($shares as $share) {
1050
+
1051
+                try {
1052
+                    $this->checkExpireDate($share);
1053
+                } catch (ShareNotFound $e) {
1054
+                    //Ignore since this basically means the share is deleted
1055
+                    continue;
1056
+                }
1057
+
1058
+                $added++;
1059
+                $shares2[] = $share;
1060
+
1061
+                if (count($shares2) === $limit) {
1062
+                    break;
1063
+                }
1064
+            }
1065
+
1066
+            if (count($shares2) === $limit) {
1067
+                break;
1068
+            }
1069
+
1070
+            // If there was no limit on the select we are done
1071
+            if ($limit === -1) {
1072
+                break;
1073
+            }
1074
+
1075
+            $offset += $added;
1076
+
1077
+            // Fetch again $limit shares
1078
+            $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset);
1079
+
1080
+            // No more shares means we are done
1081
+            if (empty($shares)) {
1082
+                break;
1083
+            }
1084
+        }
1085
+
1086
+        $shares = $shares2;
1087
+
1088
+        return $shares;
1089
+    }
1090
+
1091
+    /**
1092
+     * @inheritdoc
1093
+     */
1094
+    public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) {
1095
+        try {
1096
+            $provider = $this->factory->getProviderForType($shareType);
1097
+        } catch (ProviderException $e) {
1098
+            return [];
1099
+        }
1100
+
1101
+        $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset);
1102
+
1103
+        // remove all shares which are already expired
1104
+        foreach ($shares as $key => $share) {
1105
+            try {
1106
+                $this->checkExpireDate($share);
1107
+            } catch (ShareNotFound $e) {
1108
+                unset($shares[$key]);
1109
+            }
1110
+        }
1111
+
1112
+        return $shares;
1113
+    }
1114
+
1115
+    /**
1116
+     * @inheritdoc
1117
+     */
1118
+    public function getShareById($id, $recipient = null) {
1119
+        if ($id === null) {
1120
+            throw new ShareNotFound();
1121
+        }
1122
+
1123
+        list($providerId, $id) = $this->splitFullId($id);
1124
+
1125
+        try {
1126
+            $provider = $this->factory->getProvider($providerId);
1127
+        } catch (ProviderException $e) {
1128
+            throw new ShareNotFound();
1129
+        }
1130
+
1131
+        $share = $provider->getShareById($id, $recipient);
1132
+
1133
+        $this->checkExpireDate($share);
1134
+
1135
+        return $share;
1136
+    }
1137
+
1138
+    /**
1139
+     * Get all the shares for a given path
1140
+     *
1141
+     * @param \OCP\Files\Node $path
1142
+     * @param int $page
1143
+     * @param int $perPage
1144
+     *
1145
+     * @return Share[]
1146
+     */
1147
+    public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
1148
+        return [];
1149
+    }
1150
+
1151
+    /**
1152
+     * Get the share by token possible with password
1153
+     *
1154
+     * @param string $token
1155
+     * @return Share
1156
+     *
1157
+     * @throws ShareNotFound
1158
+     */
1159
+    public function getShareByToken($token) {
1160
+        $share = null;
1161
+        try {
1162
+            if($this->shareApiAllowLinks()) {
1163
+                $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
1164
+                $share = $provider->getShareByToken($token);
1165
+            }
1166
+        } catch (ProviderException $e) {
1167
+        } catch (ShareNotFound $e) {
1168
+        }
1169
+
1170
+
1171
+        // If it is not a link share try to fetch a federated share by token
1172
+        if ($share === null) {
1173
+            try {
1174
+                $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE);
1175
+                $share = $provider->getShareByToken($token);
1176
+            } catch (ProviderException $e) {
1177
+            } catch (ShareNotFound $e) {
1178
+            }
1179
+        }
1180
+
1181
+        // If it is not a link share try to fetch a mail share by token
1182
+        if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) {
1183
+            try {
1184
+                $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL);
1185
+                $share = $provider->getShareByToken($token);
1186
+            } catch (ProviderException $e) {
1187
+            } catch (ShareNotFound $e) {
1188
+            }
1189
+        }
1190
+
1191
+        if ($share === null) {
1192
+            throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
1193
+        }
1194
+
1195
+        $this->checkExpireDate($share);
1196
+
1197
+        /*
1198 1198
 		 * Reduce the permissions for link shares if public upload is not enabled
1199 1199
 		 */
1200
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
1201
-			!$this->shareApiLinkAllowPublicUpload()) {
1202
-			$share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE));
1203
-		}
1204
-
1205
-		return $share;
1206
-	}
1207
-
1208
-	protected function checkExpireDate($share) {
1209
-		if ($share->getExpirationDate() !== null &&
1210
-			$share->getExpirationDate() <= new \DateTime()) {
1211
-			$this->deleteShare($share);
1212
-			throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
1213
-		}
1214
-
1215
-	}
1216
-
1217
-	/**
1218
-	 * Verify the password of a public share
1219
-	 *
1220
-	 * @param \OCP\Share\IShare $share
1221
-	 * @param string $password
1222
-	 * @return bool
1223
-	 */
1224
-	public function checkPassword(\OCP\Share\IShare $share, $password) {
1225
-		$passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK
1226
-			|| $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL;
1227
-		if (!$passwordProtected) {
1228
-			//TODO maybe exception?
1229
-			return false;
1230
-		}
1231
-
1232
-		if ($password === null || $share->getPassword() === null) {
1233
-			return false;
1234
-		}
1235
-
1236
-		$newHash = '';
1237
-		if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
1238
-			return false;
1239
-		}
1240
-
1241
-		if (!empty($newHash)) {
1242
-			$share->setPassword($newHash);
1243
-			$provider = $this->factory->getProviderForType($share->getShareType());
1244
-			$provider->update($share);
1245
-		}
1246
-
1247
-		return true;
1248
-	}
1249
-
1250
-	/**
1251
-	 * @inheritdoc
1252
-	 */
1253
-	public function userDeleted($uid) {
1254
-		$types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL];
1255
-
1256
-		foreach ($types as $type) {
1257
-			try {
1258
-				$provider = $this->factory->getProviderForType($type);
1259
-			} catch (ProviderException $e) {
1260
-				continue;
1261
-			}
1262
-			$provider->userDeleted($uid, $type);
1263
-		}
1264
-	}
1265
-
1266
-	/**
1267
-	 * @inheritdoc
1268
-	 */
1269
-	public function groupDeleted($gid) {
1270
-		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
1271
-		$provider->groupDeleted($gid);
1272
-	}
1273
-
1274
-	/**
1275
-	 * @inheritdoc
1276
-	 */
1277
-	public function userDeletedFromGroup($uid, $gid) {
1278
-		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
1279
-		$provider->userDeletedFromGroup($uid, $gid);
1280
-	}
1281
-
1282
-	/**
1283
-	 * Get access list to a path. This means
1284
-	 * all the users that can access a given path.
1285
-	 *
1286
-	 * Consider:
1287
-	 * -root
1288
-	 * |-folder1 (23)
1289
-	 *  |-folder2 (32)
1290
-	 *   |-fileA (42)
1291
-	 *
1292
-	 * fileA is shared with user1 and user1@server1
1293
-	 * folder2 is shared with group2 (user4 is a member of group2)
1294
-	 * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
1295
-	 *
1296
-	 * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
1297
-	 * [
1298
-	 *  users  => [
1299
-	 *      'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
1300
-	 *      'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
1301
-	 *      'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
1302
-	 *  ],
1303
-	 *  remote => [
1304
-	 *      'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
1305
-	 *      'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
1306
-	 *  ],
1307
-	 *  public => bool
1308
-	 *  mail => bool
1309
-	 * ]
1310
-	 *
1311
-	 * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
1312
-	 * [
1313
-	 *  users  => ['user1', 'user2', 'user4'],
1314
-	 *  remote => bool,
1315
-	 *  public => bool
1316
-	 *  mail => bool
1317
-	 * ]
1318
-	 *
1319
-	 * This is required for encryption/activity
1320
-	 *
1321
-	 * @param \OCP\Files\Node $path
1322
-	 * @param bool $recursive Should we check all parent folders as well
1323
-	 * @param bool $currentAccess Should the user have currently access to the file
1324
-	 * @return array
1325
-	 */
1326
-	public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) {
1327
-		$owner = $path->getOwner()->getUID();
1328
-
1329
-		if ($currentAccess) {
1330
-			$al = ['users' => [], 'remote' => [], 'public' => false];
1331
-		} else {
1332
-			$al = ['users' => [], 'remote' => false, 'public' => false];
1333
-		}
1334
-		if (!$this->userManager->userExists($owner)) {
1335
-			return $al;
1336
-		}
1337
-
1338
-		//Get node for the owner
1339
-		$userFolder = $this->rootFolder->getUserFolder($owner);
1340
-		if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) {
1341
-			$path = $userFolder->getById($path->getId())[0];
1342
-		}
1343
-
1344
-		$providers = $this->factory->getAllProviders();
1345
-
1346
-		/** @var Node[] $nodes */
1347
-		$nodes = [];
1348
-
1349
-
1350
-		if ($currentAccess) {
1351
-			$ownerPath = $path->getPath();
1352
-			$ownerPath = explode('/', $ownerPath, 4);
1353
-			if (count($ownerPath) < 4) {
1354
-				$ownerPath = '';
1355
-			} else {
1356
-				$ownerPath = $ownerPath[3];
1357
-			}
1358
-			$al['users'][$owner] = [
1359
-				'node_id' => $path->getId(),
1360
-				'node_path' => '/' . $ownerPath,
1361
-			];
1362
-		} else {
1363
-			$al['users'][] = $owner;
1364
-		}
1365
-
1366
-		// Collect all the shares
1367
-		while ($path->getPath() !== $userFolder->getPath()) {
1368
-			$nodes[] = $path;
1369
-			if (!$recursive) {
1370
-				break;
1371
-			}
1372
-			$path = $path->getParent();
1373
-		}
1374
-
1375
-		foreach ($providers as $provider) {
1376
-			$tmp = $provider->getAccessList($nodes, $currentAccess);
1377
-
1378
-			foreach ($tmp as $k => $v) {
1379
-				if (isset($al[$k])) {
1380
-					if (is_array($al[$k])) {
1381
-						$al[$k] = array_merge($al[$k], $v);
1382
-					} else {
1383
-						$al[$k] = $al[$k] || $v;
1384
-					}
1385
-				} else {
1386
-					$al[$k] = $v;
1387
-				}
1388
-			}
1389
-		}
1390
-
1391
-		return $al;
1392
-	}
1393
-
1394
-	/**
1395
-	 * Create a new share
1396
-	 * @return \OCP\Share\IShare;
1397
-	 */
1398
-	public function newShare() {
1399
-		return new \OC\Share20\Share($this->rootFolder, $this->userManager);
1400
-	}
1401
-
1402
-	/**
1403
-	 * Is the share API enabled
1404
-	 *
1405
-	 * @return bool
1406
-	 */
1407
-	public function shareApiEnabled() {
1408
-		return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes';
1409
-	}
1410
-
1411
-	/**
1412
-	 * Is public link sharing enabled
1413
-	 *
1414
-	 * @return bool
1415
-	 */
1416
-	public function shareApiAllowLinks() {
1417
-		return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
1418
-	}
1419
-
1420
-	/**
1421
-	 * Is password on public link requires
1422
-	 *
1423
-	 * @return bool
1424
-	 */
1425
-	public function shareApiLinkEnforcePassword() {
1426
-		return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes';
1427
-	}
1428
-
1429
-	/**
1430
-	 * Is default expire date enabled
1431
-	 *
1432
-	 * @return bool
1433
-	 */
1434
-	public function shareApiLinkDefaultExpireDate() {
1435
-		return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
1436
-	}
1437
-
1438
-	/**
1439
-	 * Is default expire date enforced
1440
-	 *`
1441
-	 * @return bool
1442
-	 */
1443
-	public function shareApiLinkDefaultExpireDateEnforced() {
1444
-		return $this->shareApiLinkDefaultExpireDate() &&
1445
-			$this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
1446
-	}
1447
-
1448
-	/**
1449
-	 * Number of default expire days
1450
-	 *shareApiLinkAllowPublicUpload
1451
-	 * @return int
1452
-	 */
1453
-	public function shareApiLinkDefaultExpireDays() {
1454
-		return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
1455
-	}
1456
-
1457
-	/**
1458
-	 * Allow public upload on link shares
1459
-	 *
1460
-	 * @return bool
1461
-	 */
1462
-	public function shareApiLinkAllowPublicUpload() {
1463
-		return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
1464
-	}
1465
-
1466
-	/**
1467
-	 * check if user can only share with group members
1468
-	 * @return bool
1469
-	 */
1470
-	public function shareWithGroupMembersOnly() {
1471
-		return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
1472
-	}
1473
-
1474
-	/**
1475
-	 * Check if users can share with groups
1476
-	 * @return bool
1477
-	 */
1478
-	public function allowGroupSharing() {
1479
-		return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
1480
-	}
1481
-
1482
-	/**
1483
-	 * Copied from \OC_Util::isSharingDisabledForUser
1484
-	 *
1485
-	 * TODO: Deprecate fuction from OC_Util
1486
-	 *
1487
-	 * @param string $userId
1488
-	 * @return bool
1489
-	 */
1490
-	public function sharingDisabledForUser($userId) {
1491
-		if ($userId === null) {
1492
-			return false;
1493
-		}
1494
-
1495
-		if (isset($this->sharingDisabledForUsersCache[$userId])) {
1496
-			return $this->sharingDisabledForUsersCache[$userId];
1497
-		}
1498
-
1499
-		if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
1500
-			$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
1501
-			$excludedGroups = json_decode($groupsList);
1502
-			if (is_null($excludedGroups)) {
1503
-				$excludedGroups = explode(',', $groupsList);
1504
-				$newValue = json_encode($excludedGroups);
1505
-				$this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
1506
-			}
1507
-			$user = $this->userManager->get($userId);
1508
-			$usersGroups = $this->groupManager->getUserGroupIds($user);
1509
-			if (!empty($usersGroups)) {
1510
-				$remainingGroups = array_diff($usersGroups, $excludedGroups);
1511
-				// if the user is only in groups which are disabled for sharing then
1512
-				// sharing is also disabled for the user
1513
-				if (empty($remainingGroups)) {
1514
-					$this->sharingDisabledForUsersCache[$userId] = true;
1515
-					return true;
1516
-				}
1517
-			}
1518
-		}
1519
-
1520
-		$this->sharingDisabledForUsersCache[$userId] = false;
1521
-		return false;
1522
-	}
1523
-
1524
-	/**
1525
-	 * @inheritdoc
1526
-	 */
1527
-	public function outgoingServer2ServerSharesAllowed() {
1528
-		return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
1529
-	}
1530
-
1531
-	/**
1532
-	 * @inheritdoc
1533
-	 */
1534
-	public function shareProviderExists($shareType) {
1535
-		try {
1536
-			$this->factory->getProviderForType($shareType);
1537
-		} catch (ProviderException $e) {
1538
-			return false;
1539
-		}
1540
-
1541
-		return true;
1542
-	}
1200
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK &&
1201
+            !$this->shareApiLinkAllowPublicUpload()) {
1202
+            $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE));
1203
+        }
1204
+
1205
+        return $share;
1206
+    }
1207
+
1208
+    protected function checkExpireDate($share) {
1209
+        if ($share->getExpirationDate() !== null &&
1210
+            $share->getExpirationDate() <= new \DateTime()) {
1211
+            $this->deleteShare($share);
1212
+            throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
1213
+        }
1214
+
1215
+    }
1216
+
1217
+    /**
1218
+     * Verify the password of a public share
1219
+     *
1220
+     * @param \OCP\Share\IShare $share
1221
+     * @param string $password
1222
+     * @return bool
1223
+     */
1224
+    public function checkPassword(\OCP\Share\IShare $share, $password) {
1225
+        $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK
1226
+            || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL;
1227
+        if (!$passwordProtected) {
1228
+            //TODO maybe exception?
1229
+            return false;
1230
+        }
1231
+
1232
+        if ($password === null || $share->getPassword() === null) {
1233
+            return false;
1234
+        }
1235
+
1236
+        $newHash = '';
1237
+        if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
1238
+            return false;
1239
+        }
1240
+
1241
+        if (!empty($newHash)) {
1242
+            $share->setPassword($newHash);
1243
+            $provider = $this->factory->getProviderForType($share->getShareType());
1244
+            $provider->update($share);
1245
+        }
1246
+
1247
+        return true;
1248
+    }
1249
+
1250
+    /**
1251
+     * @inheritdoc
1252
+     */
1253
+    public function userDeleted($uid) {
1254
+        $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL];
1255
+
1256
+        foreach ($types as $type) {
1257
+            try {
1258
+                $provider = $this->factory->getProviderForType($type);
1259
+            } catch (ProviderException $e) {
1260
+                continue;
1261
+            }
1262
+            $provider->userDeleted($uid, $type);
1263
+        }
1264
+    }
1265
+
1266
+    /**
1267
+     * @inheritdoc
1268
+     */
1269
+    public function groupDeleted($gid) {
1270
+        $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
1271
+        $provider->groupDeleted($gid);
1272
+    }
1273
+
1274
+    /**
1275
+     * @inheritdoc
1276
+     */
1277
+    public function userDeletedFromGroup($uid, $gid) {
1278
+        $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
1279
+        $provider->userDeletedFromGroup($uid, $gid);
1280
+    }
1281
+
1282
+    /**
1283
+     * Get access list to a path. This means
1284
+     * all the users that can access a given path.
1285
+     *
1286
+     * Consider:
1287
+     * -root
1288
+     * |-folder1 (23)
1289
+     *  |-folder2 (32)
1290
+     *   |-fileA (42)
1291
+     *
1292
+     * fileA is shared with user1 and user1@server1
1293
+     * folder2 is shared with group2 (user4 is a member of group2)
1294
+     * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
1295
+     *
1296
+     * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
1297
+     * [
1298
+     *  users  => [
1299
+     *      'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
1300
+     *      'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
1301
+     *      'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
1302
+     *  ],
1303
+     *  remote => [
1304
+     *      'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
1305
+     *      'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
1306
+     *  ],
1307
+     *  public => bool
1308
+     *  mail => bool
1309
+     * ]
1310
+     *
1311
+     * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
1312
+     * [
1313
+     *  users  => ['user1', 'user2', 'user4'],
1314
+     *  remote => bool,
1315
+     *  public => bool
1316
+     *  mail => bool
1317
+     * ]
1318
+     *
1319
+     * This is required for encryption/activity
1320
+     *
1321
+     * @param \OCP\Files\Node $path
1322
+     * @param bool $recursive Should we check all parent folders as well
1323
+     * @param bool $currentAccess Should the user have currently access to the file
1324
+     * @return array
1325
+     */
1326
+    public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) {
1327
+        $owner = $path->getOwner()->getUID();
1328
+
1329
+        if ($currentAccess) {
1330
+            $al = ['users' => [], 'remote' => [], 'public' => false];
1331
+        } else {
1332
+            $al = ['users' => [], 'remote' => false, 'public' => false];
1333
+        }
1334
+        if (!$this->userManager->userExists($owner)) {
1335
+            return $al;
1336
+        }
1337
+
1338
+        //Get node for the owner
1339
+        $userFolder = $this->rootFolder->getUserFolder($owner);
1340
+        if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) {
1341
+            $path = $userFolder->getById($path->getId())[0];
1342
+        }
1343
+
1344
+        $providers = $this->factory->getAllProviders();
1345
+
1346
+        /** @var Node[] $nodes */
1347
+        $nodes = [];
1348
+
1349
+
1350
+        if ($currentAccess) {
1351
+            $ownerPath = $path->getPath();
1352
+            $ownerPath = explode('/', $ownerPath, 4);
1353
+            if (count($ownerPath) < 4) {
1354
+                $ownerPath = '';
1355
+            } else {
1356
+                $ownerPath = $ownerPath[3];
1357
+            }
1358
+            $al['users'][$owner] = [
1359
+                'node_id' => $path->getId(),
1360
+                'node_path' => '/' . $ownerPath,
1361
+            ];
1362
+        } else {
1363
+            $al['users'][] = $owner;
1364
+        }
1365
+
1366
+        // Collect all the shares
1367
+        while ($path->getPath() !== $userFolder->getPath()) {
1368
+            $nodes[] = $path;
1369
+            if (!$recursive) {
1370
+                break;
1371
+            }
1372
+            $path = $path->getParent();
1373
+        }
1374
+
1375
+        foreach ($providers as $provider) {
1376
+            $tmp = $provider->getAccessList($nodes, $currentAccess);
1377
+
1378
+            foreach ($tmp as $k => $v) {
1379
+                if (isset($al[$k])) {
1380
+                    if (is_array($al[$k])) {
1381
+                        $al[$k] = array_merge($al[$k], $v);
1382
+                    } else {
1383
+                        $al[$k] = $al[$k] || $v;
1384
+                    }
1385
+                } else {
1386
+                    $al[$k] = $v;
1387
+                }
1388
+            }
1389
+        }
1390
+
1391
+        return $al;
1392
+    }
1393
+
1394
+    /**
1395
+     * Create a new share
1396
+     * @return \OCP\Share\IShare;
1397
+     */
1398
+    public function newShare() {
1399
+        return new \OC\Share20\Share($this->rootFolder, $this->userManager);
1400
+    }
1401
+
1402
+    /**
1403
+     * Is the share API enabled
1404
+     *
1405
+     * @return bool
1406
+     */
1407
+    public function shareApiEnabled() {
1408
+        return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes';
1409
+    }
1410
+
1411
+    /**
1412
+     * Is public link sharing enabled
1413
+     *
1414
+     * @return bool
1415
+     */
1416
+    public function shareApiAllowLinks() {
1417
+        return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes';
1418
+    }
1419
+
1420
+    /**
1421
+     * Is password on public link requires
1422
+     *
1423
+     * @return bool
1424
+     */
1425
+    public function shareApiLinkEnforcePassword() {
1426
+        return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes';
1427
+    }
1428
+
1429
+    /**
1430
+     * Is default expire date enabled
1431
+     *
1432
+     * @return bool
1433
+     */
1434
+    public function shareApiLinkDefaultExpireDate() {
1435
+        return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
1436
+    }
1437
+
1438
+    /**
1439
+     * Is default expire date enforced
1440
+     *`
1441
+     * @return bool
1442
+     */
1443
+    public function shareApiLinkDefaultExpireDateEnforced() {
1444
+        return $this->shareApiLinkDefaultExpireDate() &&
1445
+            $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
1446
+    }
1447
+
1448
+    /**
1449
+     * Number of default expire days
1450
+     *shareApiLinkAllowPublicUpload
1451
+     * @return int
1452
+     */
1453
+    public function shareApiLinkDefaultExpireDays() {
1454
+        return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
1455
+    }
1456
+
1457
+    /**
1458
+     * Allow public upload on link shares
1459
+     *
1460
+     * @return bool
1461
+     */
1462
+    public function shareApiLinkAllowPublicUpload() {
1463
+        return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
1464
+    }
1465
+
1466
+    /**
1467
+     * check if user can only share with group members
1468
+     * @return bool
1469
+     */
1470
+    public function shareWithGroupMembersOnly() {
1471
+        return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
1472
+    }
1473
+
1474
+    /**
1475
+     * Check if users can share with groups
1476
+     * @return bool
1477
+     */
1478
+    public function allowGroupSharing() {
1479
+        return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes';
1480
+    }
1481
+
1482
+    /**
1483
+     * Copied from \OC_Util::isSharingDisabledForUser
1484
+     *
1485
+     * TODO: Deprecate fuction from OC_Util
1486
+     *
1487
+     * @param string $userId
1488
+     * @return bool
1489
+     */
1490
+    public function sharingDisabledForUser($userId) {
1491
+        if ($userId === null) {
1492
+            return false;
1493
+        }
1494
+
1495
+        if (isset($this->sharingDisabledForUsersCache[$userId])) {
1496
+            return $this->sharingDisabledForUsersCache[$userId];
1497
+        }
1498
+
1499
+        if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
1500
+            $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
1501
+            $excludedGroups = json_decode($groupsList);
1502
+            if (is_null($excludedGroups)) {
1503
+                $excludedGroups = explode(',', $groupsList);
1504
+                $newValue = json_encode($excludedGroups);
1505
+                $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue);
1506
+            }
1507
+            $user = $this->userManager->get($userId);
1508
+            $usersGroups = $this->groupManager->getUserGroupIds($user);
1509
+            if (!empty($usersGroups)) {
1510
+                $remainingGroups = array_diff($usersGroups, $excludedGroups);
1511
+                // if the user is only in groups which are disabled for sharing then
1512
+                // sharing is also disabled for the user
1513
+                if (empty($remainingGroups)) {
1514
+                    $this->sharingDisabledForUsersCache[$userId] = true;
1515
+                    return true;
1516
+                }
1517
+            }
1518
+        }
1519
+
1520
+        $this->sharingDisabledForUsersCache[$userId] = false;
1521
+        return false;
1522
+    }
1523
+
1524
+    /**
1525
+     * @inheritdoc
1526
+     */
1527
+    public function outgoingServer2ServerSharesAllowed() {
1528
+        return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
1529
+    }
1530
+
1531
+    /**
1532
+     * @inheritdoc
1533
+     */
1534
+    public function shareProviderExists($shareType) {
1535
+        try {
1536
+            $this->factory->getProviderForType($shareType);
1537
+        } catch (ProviderException $e) {
1538
+            return false;
1539
+        }
1540
+
1541
+        return true;
1542
+    }
1543 1543
 
1544 1544
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 
340 340
 		if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
341 341
 			$expirationDate = new \DateTime();
342
-			$expirationDate->setTime(0,0,0);
342
+			$expirationDate->setTime(0, 0, 0);
343 343
 			$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
344 344
 		}
345 345
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 
352 352
 			$date = new \DateTime();
353 353
 			$date->setTime(0, 0, 0);
354
-			$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
354
+			$date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
355 355
 			if ($date < $expirationDate) {
356 356
 				$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
357 357
 				throw new GenericShareException($message, $message, 404);
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 		 */
405 405
 		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
406 406
 		$existingShares = $provider->getSharesByPath($share->getNode());
407
-		foreach($existingShares as $existingShare) {
407
+		foreach ($existingShares as $existingShare) {
408 408
 			// Ignore if it is the same share
409 409
 			try {
410 410
 				if ($existingShare->getFullId() === $share->getFullId()) {
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 		 */
462 462
 		$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
463 463
 		$existingShares = $provider->getSharesByPath($share->getNode());
464
-		foreach($existingShares as $existingShare) {
464
+		foreach ($existingShares as $existingShare) {
465 465
 			try {
466 466
 				if ($existingShare->getFullId() === $share->getFullId()) {
467 467
 					continue;
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 		// Make sure that we do not share a path that contains a shared mountpoint
531 531
 		if ($path instanceof \OCP\Files\Folder) {
532 532
 			$mounts = $this->mountManager->findIn($path->getPath());
533
-			foreach($mounts as $mount) {
533
+			foreach ($mounts as $mount) {
534 534
 				if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
535 535
 					throw new \InvalidArgumentException('Path contains files shared with you');
536 536
 				}
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 		$storage = $share->getNode()->getStorage();
579 579
 		if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
580 580
 			$parent = $share->getNode()->getParent();
581
-			while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
581
+			while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
582 582
 				$parent = $parent->getParent();
583 583
 			}
584 584
 			$share->setShareOwner($parent->getOwner()->getUID());
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 		}
632 632
 
633 633
 		// Generate the target
634
-		$target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName();
634
+		$target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName();
635 635
 		$target = \OC\Files\Filesystem::normalizePath($target);
636 636
 		$share->setTarget($target);
637 637
 
@@ -689,16 +689,16 @@  discard block
 block discarded – undo
689 689
 				if ($emailAddress !== null && $emailAddress !== '') {
690 690
 					$this->sendMailNotification(
691 691
 						$share->getNode()->getName(),
692
-						$this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]),
692
+						$this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]),
693 693
 						$share->getSharedBy(),
694 694
 						$emailAddress
695 695
 					);
696
-					$this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']);
696
+					$this->logger->debug('Send share notification to '.$emailAddress.' for share with ID '.$share->getId(), ['app' => 'share']);
697 697
 				} else {
698
-					$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
698
+					$this->logger->debug('Share notification not send to '.$share->getSharedWith().' because email address is not set.', ['app' => 'share']);
699 699
 				}
700 700
 			} else {
701
-				$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
701
+				$this->logger->debug('Share notification not send to '.$share->getSharedWith().' because user could not be found.', ['app' => 'share']);
702 702
 			}
703 703
 		}
704 704
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 											$shareWith) {
719 719
 		$initiatorUser = $this->userManager->get($initiator);
720 720
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
721
-		$subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));
721
+		$subject = (string) $this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename));
722 722
 
723 723
 		$message = $this->mailer->createMessage();
724 724
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 		$text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]);
730 730
 
731 731
 		$emailTemplate->addBodyText(
732
-			$text . ' ' . $this->l->t('Click the button below to open it.'),
732
+			$text.' '.$this->l->t('Click the button below to open it.'),
733 733
 			$text
734 734
 		);
735 735
 		$emailTemplate->addBodyButton(
@@ -753,9 +753,9 @@  discard block
 block discarded – undo
753 753
 		// The "Reply-To" is set to the sharer if an mail address is configured
754 754
 		// also the default footer contains a "Do not reply" which needs to be adjusted.
755 755
 		$initiatorEmail = $initiatorUser->getEMailAddress();
756
-		if($initiatorEmail !== null) {
756
+		if ($initiatorEmail !== null) {
757 757
 			$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
758
-			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
758
+			$emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan());
759 759
 		} else {
760 760
 			$emailTemplate->addFooter();
761 761
 		}
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
 	 * @param string $recipientId
967 967
 	 */
968 968
 	public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
969
-		list($providerId, ) = $this->splitFullId($share->getFullId());
969
+		list($providerId,) = $this->splitFullId($share->getFullId());
970 970
 		$provider = $this->factory->getProvider($providerId);
971 971
 
972 972
 		$provider->deleteFromSelf($share, $recipientId);
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
 		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
990 990
 			$sharedWith = $this->groupManager->get($share->getSharedWith());
991 991
 			if (is_null($sharedWith)) {
992
-				throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist');
992
+				throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist');
993 993
 			}
994 994
 			$recipient = $this->userManager->get($recipientId);
995 995
 			if (!$sharedWith->inGroup($recipient)) {
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 			}
998 998
 		}
999 999
 
1000
-		list($providerId, ) = $this->splitFullId($share->getFullId());
1000
+		list($providerId,) = $this->splitFullId($share->getFullId());
1001 1001
 		$provider = $this->factory->getProvider($providerId);
1002 1002
 
1003 1003
 		$provider->move($share, $recipientId);
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 
1045 1045
 		$shares2 = [];
1046 1046
 
1047
-		while(true) {
1047
+		while (true) {
1048 1048
 			$added = 0;
1049 1049
 			foreach ($shares as $share) {
1050 1050
 
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 	 *
1145 1145
 	 * @return Share[]
1146 1146
 	 */
1147
-	public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
1147
+	public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) {
1148 1148
 		return [];
1149 1149
 	}
1150 1150
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 	public function getShareByToken($token) {
1160 1160
 		$share = null;
1161 1161
 		try {
1162
-			if($this->shareApiAllowLinks()) {
1162
+			if ($this->shareApiAllowLinks()) {
1163 1163
 				$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
1164 1164
 				$share = $provider->getShareByToken($token);
1165 1165
 			}
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
 			}
1358 1358
 			$al['users'][$owner] = [
1359 1359
 				'node_id' => $path->getId(),
1360
-				'node_path' => '/' . $ownerPath,
1360
+				'node_path' => '/'.$ownerPath,
1361 1361
 			];
1362 1362
 		} else {
1363 1363
 			$al['users'][] = $owner;
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 	 * @return int
1452 1452
 	 */
1453 1453
 	public function shareApiLinkDefaultExpireDays() {
1454
-		return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
1454
+		return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
1455 1455
 	}
1456 1456
 
1457 1457
 	/**
Please login to merge, or discard this patch.
lib/private/Server.php 1 patch
Indentation   +1663 added lines, -1663 removed lines patch added patch discarded remove patch
@@ -128,1672 +128,1672 @@
 block discarded – undo
128 128
  * TODO: hookup all manager classes
129 129
  */
130 130
 class Server extends ServerContainer implements IServerContainer {
131
-	/** @var string */
132
-	private $webRoot;
133
-
134
-	/**
135
-	 * @param string $webRoot
136
-	 * @param \OC\Config $config
137
-	 */
138
-	public function __construct($webRoot, \OC\Config $config) {
139
-		parent::__construct();
140
-		$this->webRoot = $webRoot;
141
-
142
-		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
143
-			return $c;
144
-		});
145
-
146
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
147
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
148
-
149
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
150
-
151
-
152
-
153
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
154
-			return new PreviewManager(
155
-				$c->getConfig(),
156
-				$c->getRootFolder(),
157
-				$c->getAppDataDir('preview'),
158
-				$c->getEventDispatcher(),
159
-				$c->getSession()->get('user_id')
160
-			);
161
-		});
162
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
163
-
164
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
165
-			return new \OC\Preview\Watcher(
166
-				$c->getAppDataDir('preview')
167
-			);
168
-		});
169
-
170
-		$this->registerService('EncryptionManager', function (Server $c) {
171
-			$view = new View();
172
-			$util = new Encryption\Util(
173
-				$view,
174
-				$c->getUserManager(),
175
-				$c->getGroupManager(),
176
-				$c->getConfig()
177
-			);
178
-			return new Encryption\Manager(
179
-				$c->getConfig(),
180
-				$c->getLogger(),
181
-				$c->getL10N('core'),
182
-				new View(),
183
-				$util,
184
-				new ArrayCache()
185
-			);
186
-		});
187
-
188
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
189
-			$util = new Encryption\Util(
190
-				new View(),
191
-				$c->getUserManager(),
192
-				$c->getGroupManager(),
193
-				$c->getConfig()
194
-			);
195
-			return new Encryption\File(
196
-				$util,
197
-				$c->getRootFolder(),
198
-				$c->getShareManager()
199
-			);
200
-		});
201
-
202
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
203
-			$view = new View();
204
-			$util = new Encryption\Util(
205
-				$view,
206
-				$c->getUserManager(),
207
-				$c->getGroupManager(),
208
-				$c->getConfig()
209
-			);
210
-
211
-			return new Encryption\Keys\Storage($view, $util);
212
-		});
213
-		$this->registerService('TagMapper', function (Server $c) {
214
-			return new TagMapper($c->getDatabaseConnection());
215
-		});
216
-
217
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
218
-			$tagMapper = $c->query('TagMapper');
219
-			return new TagManager($tagMapper, $c->getUserSession());
220
-		});
221
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
222
-
223
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
224
-			$config = $c->getConfig();
225
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
226
-			/** @var \OC\SystemTag\ManagerFactory $factory */
227
-			$factory = new $factoryClass($this);
228
-			return $factory;
229
-		});
230
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
231
-			return $c->query('SystemTagManagerFactory')->getManager();
232
-		});
233
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
234
-
235
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
236
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
237
-		});
238
-		$this->registerService('RootFolder', function (Server $c) {
239
-			$manager = \OC\Files\Filesystem::getMountManager(null);
240
-			$view = new View();
241
-			$root = new Root(
242
-				$manager,
243
-				$view,
244
-				null,
245
-				$c->getUserMountCache(),
246
-				$this->getLogger(),
247
-				$this->getUserManager()
248
-			);
249
-			$connector = new HookConnector($root, $view);
250
-			$connector->viewToNode();
251
-
252
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
253
-			$previewConnector->connectWatcher();
254
-
255
-			return $root;
256
-		});
257
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
258
-
259
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
260
-			return new LazyRoot(function() use ($c) {
261
-				return $c->query('RootFolder');
262
-			});
263
-		});
264
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
265
-
266
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
267
-			$config = $c->getConfig();
268
-			return new \OC\User\Manager($config);
269
-		});
270
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
271
-
272
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
273
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
274
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
275
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
276
-			});
277
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
278
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
279
-			});
280
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
281
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
282
-			});
283
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
284
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
285
-			});
286
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
288
-			});
289
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
290
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
292
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
293
-			});
294
-			return $groupManager;
295
-		});
296
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
297
-
298
-		$this->registerService(Store::class, function(Server $c) {
299
-			$session = $c->getSession();
300
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
301
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
302
-			} else {
303
-				$tokenProvider = null;
304
-			}
305
-			$logger = $c->getLogger();
306
-			return new Store($session, $logger, $tokenProvider);
307
-		});
308
-		$this->registerAlias(IStore::class, Store::class);
309
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
310
-			$dbConnection = $c->getDatabaseConnection();
311
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
312
-		});
313
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
314
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
315
-			$crypto = $c->getCrypto();
316
-			$config = $c->getConfig();
317
-			$logger = $c->getLogger();
318
-			$timeFactory = new TimeFactory();
319
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
320
-		});
321
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
322
-
323
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
324
-			$manager = $c->getUserManager();
325
-			$session = new \OC\Session\Memory('');
326
-			$timeFactory = new TimeFactory();
327
-			// Token providers might require a working database. This code
328
-			// might however be called when ownCloud is not yet setup.
329
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
331
-			} else {
332
-				$defaultTokenProvider = null;
333
-			}
334
-
335
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
336
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
337
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
338
-			});
339
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
340
-				/** @var $user \OC\User\User */
341
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
342
-			});
343
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
344
-				/** @var $user \OC\User\User */
345
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
346
-			});
347
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
348
-				/** @var $user \OC\User\User */
349
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
350
-			});
351
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
352
-				/** @var $user \OC\User\User */
353
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
354
-			});
355
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
356
-				/** @var $user \OC\User\User */
357
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
358
-			});
359
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
360
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
361
-			});
362
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
363
-				/** @var $user \OC\User\User */
364
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
365
-			});
366
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
367
-				/** @var $user \OC\User\User */
368
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
369
-			});
370
-			$userSession->listen('\OC\User', 'logout', function () {
371
-				\OC_Hook::emit('OC_User', 'logout', array());
372
-			});
373
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
374
-				/** @var $user \OC\User\User */
375
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
376
-			});
377
-			return $userSession;
378
-		});
379
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
380
-
381
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
382
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
383
-		});
384
-
385
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
386
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
387
-
388
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
389
-			return new \OC\AllConfig(
390
-				$c->getSystemConfig()
391
-			);
392
-		});
393
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
394
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
395
-
396
-		$this->registerService('SystemConfig', function ($c) use ($config) {
397
-			return new \OC\SystemConfig($config);
398
-		});
399
-
400
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
401
-			return new \OC\AppConfig($c->getDatabaseConnection());
402
-		});
403
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
404
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
405
-
406
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
407
-			return new \OC\L10N\Factory(
408
-				$c->getConfig(),
409
-				$c->getRequest(),
410
-				$c->getUserSession(),
411
-				\OC::$SERVERROOT
412
-			);
413
-		});
414
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
415
-
416
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
417
-			$config = $c->getConfig();
418
-			$cacheFactory = $c->getMemCacheFactory();
419
-			$request = $c->getRequest();
420
-			return new \OC\URLGenerator(
421
-				$config,
422
-				$cacheFactory,
423
-				$request
424
-			);
425
-		});
426
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
427
-
428
-		$this->registerService('AppHelper', function ($c) {
429
-			return new \OC\AppHelper();
430
-		});
431
-		$this->registerAlias('AppFetcher', AppFetcher::class);
432
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
433
-
434
-		$this->registerService(\OCP\ICache::class, function ($c) {
435
-			return new Cache\File();
436
-		});
437
-		$this->registerAlias('UserCache', \OCP\ICache::class);
438
-
439
-		$this->registerService(Factory::class, function (Server $c) {
440
-
441
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
442
-				'\\OC\\Memcache\\ArrayCache',
443
-				'\\OC\\Memcache\\ArrayCache',
444
-				'\\OC\\Memcache\\ArrayCache'
445
-			);
446
-			$config = $c->getConfig();
447
-			$request = $c->getRequest();
448
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
449
-
450
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
-				$v = \OC_App::getAppVersions();
452
-				$v['core'] = implode(',', \OC_Util::getVersion());
453
-				$version = implode(',', $v);
454
-				$instanceId = \OC_Util::getInstanceId();
455
-				$path = \OC::$SERVERROOT;
456
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
457
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
-					$config->getSystemValue('memcache.local', null),
459
-					$config->getSystemValue('memcache.distributed', null),
460
-					$config->getSystemValue('memcache.locking', null)
461
-				);
462
-			}
463
-			return $arrayCacheFactory;
464
-
465
-		});
466
-		$this->registerAlias('MemCacheFactory', Factory::class);
467
-		$this->registerAlias(ICacheFactory::class, Factory::class);
468
-
469
-		$this->registerService('RedisFactory', function (Server $c) {
470
-			$systemConfig = $c->getSystemConfig();
471
-			return new RedisFactory($systemConfig);
472
-		});
473
-
474
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
475
-			return new \OC\Activity\Manager(
476
-				$c->getRequest(),
477
-				$c->getUserSession(),
478
-				$c->getConfig(),
479
-				$c->query(IValidator::class)
480
-			);
481
-		});
482
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
483
-
484
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
485
-			return new \OC\Activity\EventMerger(
486
-				$c->getL10N('lib')
487
-			);
488
-		});
489
-		$this->registerAlias(IValidator::class, Validator::class);
490
-
491
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
492
-			return new AvatarManager(
493
-				$c->getUserManager(),
494
-				$c->getAppDataDir('avatar'),
495
-				$c->getL10N('lib'),
496
-				$c->getLogger(),
497
-				$c->getConfig()
498
-			);
499
-		});
500
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
501
-
502
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
503
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
504
-			$logger = Log::getLogClass($logType);
505
-			call_user_func(array($logger, 'init'));
506
-
507
-			return new Log($logger);
508
-		});
509
-		$this->registerAlias('Logger', \OCP\ILogger::class);
510
-
511
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
512
-			$config = $c->getConfig();
513
-			return new \OC\BackgroundJob\JobList(
514
-				$c->getDatabaseConnection(),
515
-				$config,
516
-				new TimeFactory()
517
-			);
518
-		});
519
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
520
-
521
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
522
-			$cacheFactory = $c->getMemCacheFactory();
523
-			$logger = $c->getLogger();
524
-			if ($cacheFactory->isAvailable()) {
525
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
526
-			} else {
527
-				$router = new \OC\Route\Router($logger);
528
-			}
529
-			return $router;
530
-		});
531
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
532
-
533
-		$this->registerService(\OCP\ISearch::class, function ($c) {
534
-			return new Search();
535
-		});
536
-		$this->registerAlias('Search', \OCP\ISearch::class);
537
-
538
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
539
-			return new \OC\Security\RateLimiting\Limiter(
540
-				$this->getUserSession(),
541
-				$this->getRequest(),
542
-				new \OC\AppFramework\Utility\TimeFactory(),
543
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
544
-			);
545
-		});
546
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
547
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
548
-				$this->getMemCacheFactory(),
549
-				new \OC\AppFramework\Utility\TimeFactory()
550
-			);
551
-		});
552
-
553
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
554
-			return new SecureRandom();
555
-		});
556
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
557
-
558
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
559
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
560
-		});
561
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
562
-
563
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
564
-			return new Hasher($c->getConfig());
565
-		});
566
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
567
-
568
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
569
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
570
-		});
571
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
572
-
573
-		$this->registerService(IDBConnection::class, function (Server $c) {
574
-			$systemConfig = $c->getSystemConfig();
575
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
576
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
577
-			if (!$factory->isValidType($type)) {
578
-				throw new \OC\DatabaseException('Invalid database type');
579
-			}
580
-			$connectionParams = $factory->createConnectionParams();
581
-			$connection = $factory->getConnection($type, $connectionParams);
582
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
583
-			return $connection;
584
-		});
585
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
586
-
587
-		$this->registerService('HTTPHelper', function (Server $c) {
588
-			$config = $c->getConfig();
589
-			return new HTTPHelper(
590
-				$config,
591
-				$c->getHTTPClientService()
592
-			);
593
-		});
594
-
595
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
596
-			$user = \OC_User::getUser();
597
-			$uid = $user ? $user : null;
598
-			return new ClientService(
599
-				$c->getConfig(),
600
-				new \OC\Security\CertificateManager(
601
-					$uid,
602
-					new View(),
603
-					$c->getConfig(),
604
-					$c->getLogger(),
605
-					$c->getSecureRandom()
606
-				)
607
-			);
608
-		});
609
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
610
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
611
-			$eventLogger = new EventLogger();
612
-			if ($c->getSystemConfig()->getValue('debug', false)) {
613
-				// In debug mode, module is being activated by default
614
-				$eventLogger->activate();
615
-			}
616
-			return $eventLogger;
617
-		});
618
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
619
-
620
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
621
-			$queryLogger = new QueryLogger();
622
-			if ($c->getSystemConfig()->getValue('debug', false)) {
623
-				// In debug mode, module is being activated by default
624
-				$queryLogger->activate();
625
-			}
626
-			return $queryLogger;
627
-		});
628
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
629
-
630
-		$this->registerService(TempManager::class, function (Server $c) {
631
-			return new TempManager(
632
-				$c->getLogger(),
633
-				$c->getConfig()
634
-			);
635
-		});
636
-		$this->registerAlias('TempManager', TempManager::class);
637
-		$this->registerAlias(ITempManager::class, TempManager::class);
638
-
639
-		$this->registerService(AppManager::class, function (Server $c) {
640
-			return new \OC\App\AppManager(
641
-				$c->getUserSession(),
642
-				$c->getAppConfig(),
643
-				$c->getGroupManager(),
644
-				$c->getMemCacheFactory(),
645
-				$c->getEventDispatcher()
646
-			);
647
-		});
648
-		$this->registerAlias('AppManager', AppManager::class);
649
-		$this->registerAlias(IAppManager::class, AppManager::class);
650
-
651
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
652
-			return new DateTimeZone(
653
-				$c->getConfig(),
654
-				$c->getSession()
655
-			);
656
-		});
657
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
658
-
659
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
660
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
661
-
662
-			return new DateTimeFormatter(
663
-				$c->getDateTimeZone()->getTimeZone(),
664
-				$c->getL10N('lib', $language)
665
-			);
666
-		});
667
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
668
-
669
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
670
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
671
-			$listener = new UserMountCacheListener($mountCache);
672
-			$listener->listen($c->getUserManager());
673
-			return $mountCache;
674
-		});
675
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
676
-
677
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
678
-			$loader = \OC\Files\Filesystem::getLoader();
679
-			$mountCache = $c->query('UserMountCache');
680
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
681
-
682
-			// builtin providers
683
-
684
-			$config = $c->getConfig();
685
-			$manager->registerProvider(new CacheMountProvider($config));
686
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
687
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
688
-
689
-			return $manager;
690
-		});
691
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
692
-
693
-		$this->registerService('IniWrapper', function ($c) {
694
-			return new IniGetWrapper();
695
-		});
696
-		$this->registerService('AsyncCommandBus', function (Server $c) {
697
-			$jobList = $c->getJobList();
698
-			return new AsyncBus($jobList);
699
-		});
700
-		$this->registerService('TrustedDomainHelper', function ($c) {
701
-			return new TrustedDomainHelper($this->getConfig());
702
-		});
703
-		$this->registerService('Throttler', function(Server $c) {
704
-			return new Throttler(
705
-				$c->getDatabaseConnection(),
706
-				new TimeFactory(),
707
-				$c->getLogger(),
708
-				$c->getConfig()
709
-			);
710
-		});
711
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
712
-			// IConfig and IAppManager requires a working database. This code
713
-			// might however be called when ownCloud is not yet setup.
714
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
715
-				$config = $c->getConfig();
716
-				$appManager = $c->getAppManager();
717
-			} else {
718
-				$config = null;
719
-				$appManager = null;
720
-			}
721
-
722
-			return new Checker(
723
-					new EnvironmentHelper(),
724
-					new FileAccessHelper(),
725
-					new AppLocator(),
726
-					$config,
727
-					$c->getMemCacheFactory(),
728
-					$appManager,
729
-					$c->getTempManager()
730
-			);
731
-		});
732
-		$this->registerService(\OCP\IRequest::class, function ($c) {
733
-			if (isset($this['urlParams'])) {
734
-				$urlParams = $this['urlParams'];
735
-			} else {
736
-				$urlParams = [];
737
-			}
738
-
739
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
740
-				&& in_array('fakeinput', stream_get_wrappers())
741
-			) {
742
-				$stream = 'fakeinput://data';
743
-			} else {
744
-				$stream = 'php://input';
745
-			}
746
-
747
-			return new Request(
748
-				[
749
-					'get' => $_GET,
750
-					'post' => $_POST,
751
-					'files' => $_FILES,
752
-					'server' => $_SERVER,
753
-					'env' => $_ENV,
754
-					'cookies' => $_COOKIE,
755
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
756
-						? $_SERVER['REQUEST_METHOD']
757
-						: null,
758
-					'urlParams' => $urlParams,
759
-				],
760
-				$this->getSecureRandom(),
761
-				$this->getConfig(),
762
-				$this->getCsrfTokenManager(),
763
-				$stream
764
-			);
765
-		});
766
-		$this->registerAlias('Request', \OCP\IRequest::class);
767
-
768
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
769
-			return new Mailer(
770
-				$c->getConfig(),
771
-				$c->getLogger(),
772
-				$c->query(Defaults::class),
773
-				$c->getURLGenerator(),
774
-				$c->getL10N('lib')
775
-			);
776
-		});
777
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
778
-
779
-		$this->registerService('LDAPProvider', function(Server $c) {
780
-			$config = $c->getConfig();
781
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
782
-			if(is_null($factoryClass)) {
783
-				throw new \Exception('ldapProviderFactory not set');
784
-			}
785
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
786
-			$factory = new $factoryClass($this);
787
-			return $factory->getLDAPProvider();
788
-		});
789
-		$this->registerService(ILockingProvider::class, function (Server $c) {
790
-			$ini = $c->getIniWrapper();
791
-			$config = $c->getConfig();
792
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
793
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
794
-				/** @var \OC\Memcache\Factory $memcacheFactory */
795
-				$memcacheFactory = $c->getMemCacheFactory();
796
-				$memcache = $memcacheFactory->createLocking('lock');
797
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
798
-					return new MemcacheLockingProvider($memcache, $ttl);
799
-				}
800
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
801
-			}
802
-			return new NoopLockingProvider();
803
-		});
804
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
805
-
806
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
807
-			return new \OC\Files\Mount\Manager();
808
-		});
809
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
810
-
811
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
812
-			return new \OC\Files\Type\Detection(
813
-				$c->getURLGenerator(),
814
-				\OC::$configDir,
815
-				\OC::$SERVERROOT . '/resources/config/'
816
-			);
817
-		});
818
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
819
-
820
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
821
-			return new \OC\Files\Type\Loader(
822
-				$c->getDatabaseConnection()
823
-			);
824
-		});
825
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
826
-		$this->registerService(BundleFetcher::class, function () {
827
-			return new BundleFetcher($this->getL10N('lib'));
828
-		});
829
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
830
-			return new Manager(
831
-				$c->query(IValidator::class)
832
-			);
833
-		});
834
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
835
-
836
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
837
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
838
-			$manager->registerCapability(function () use ($c) {
839
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
840
-			});
841
-			$manager->registerCapability(function () use ($c) {
842
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
843
-			});
844
-			return $manager;
845
-		});
846
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
847
-
848
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
849
-			$config = $c->getConfig();
850
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
851
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
852
-			$factory = new $factoryClass($this);
853
-			return $factory->getManager();
854
-		});
855
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
856
-
857
-		$this->registerService('ThemingDefaults', function(Server $c) {
858
-			/*
131
+    /** @var string */
132
+    private $webRoot;
133
+
134
+    /**
135
+     * @param string $webRoot
136
+     * @param \OC\Config $config
137
+     */
138
+    public function __construct($webRoot, \OC\Config $config) {
139
+        parent::__construct();
140
+        $this->webRoot = $webRoot;
141
+
142
+        $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
143
+            return $c;
144
+        });
145
+
146
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
147
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
148
+
149
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
150
+
151
+
152
+
153
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
154
+            return new PreviewManager(
155
+                $c->getConfig(),
156
+                $c->getRootFolder(),
157
+                $c->getAppDataDir('preview'),
158
+                $c->getEventDispatcher(),
159
+                $c->getSession()->get('user_id')
160
+            );
161
+        });
162
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
163
+
164
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
165
+            return new \OC\Preview\Watcher(
166
+                $c->getAppDataDir('preview')
167
+            );
168
+        });
169
+
170
+        $this->registerService('EncryptionManager', function (Server $c) {
171
+            $view = new View();
172
+            $util = new Encryption\Util(
173
+                $view,
174
+                $c->getUserManager(),
175
+                $c->getGroupManager(),
176
+                $c->getConfig()
177
+            );
178
+            return new Encryption\Manager(
179
+                $c->getConfig(),
180
+                $c->getLogger(),
181
+                $c->getL10N('core'),
182
+                new View(),
183
+                $util,
184
+                new ArrayCache()
185
+            );
186
+        });
187
+
188
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
189
+            $util = new Encryption\Util(
190
+                new View(),
191
+                $c->getUserManager(),
192
+                $c->getGroupManager(),
193
+                $c->getConfig()
194
+            );
195
+            return new Encryption\File(
196
+                $util,
197
+                $c->getRootFolder(),
198
+                $c->getShareManager()
199
+            );
200
+        });
201
+
202
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
203
+            $view = new View();
204
+            $util = new Encryption\Util(
205
+                $view,
206
+                $c->getUserManager(),
207
+                $c->getGroupManager(),
208
+                $c->getConfig()
209
+            );
210
+
211
+            return new Encryption\Keys\Storage($view, $util);
212
+        });
213
+        $this->registerService('TagMapper', function (Server $c) {
214
+            return new TagMapper($c->getDatabaseConnection());
215
+        });
216
+
217
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
218
+            $tagMapper = $c->query('TagMapper');
219
+            return new TagManager($tagMapper, $c->getUserSession());
220
+        });
221
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
222
+
223
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
224
+            $config = $c->getConfig();
225
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
226
+            /** @var \OC\SystemTag\ManagerFactory $factory */
227
+            $factory = new $factoryClass($this);
228
+            return $factory;
229
+        });
230
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
231
+            return $c->query('SystemTagManagerFactory')->getManager();
232
+        });
233
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
234
+
235
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
236
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
237
+        });
238
+        $this->registerService('RootFolder', function (Server $c) {
239
+            $manager = \OC\Files\Filesystem::getMountManager(null);
240
+            $view = new View();
241
+            $root = new Root(
242
+                $manager,
243
+                $view,
244
+                null,
245
+                $c->getUserMountCache(),
246
+                $this->getLogger(),
247
+                $this->getUserManager()
248
+            );
249
+            $connector = new HookConnector($root, $view);
250
+            $connector->viewToNode();
251
+
252
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
253
+            $previewConnector->connectWatcher();
254
+
255
+            return $root;
256
+        });
257
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
258
+
259
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
260
+            return new LazyRoot(function() use ($c) {
261
+                return $c->query('RootFolder');
262
+            });
263
+        });
264
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
265
+
266
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
267
+            $config = $c->getConfig();
268
+            return new \OC\User\Manager($config);
269
+        });
270
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
271
+
272
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
273
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
274
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
275
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
276
+            });
277
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
278
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
279
+            });
280
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
281
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
282
+            });
283
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
284
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
285
+            });
286
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
288
+            });
289
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
290
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
292
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
293
+            });
294
+            return $groupManager;
295
+        });
296
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
297
+
298
+        $this->registerService(Store::class, function(Server $c) {
299
+            $session = $c->getSession();
300
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
301
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
302
+            } else {
303
+                $tokenProvider = null;
304
+            }
305
+            $logger = $c->getLogger();
306
+            return new Store($session, $logger, $tokenProvider);
307
+        });
308
+        $this->registerAlias(IStore::class, Store::class);
309
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
310
+            $dbConnection = $c->getDatabaseConnection();
311
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
312
+        });
313
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
314
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
315
+            $crypto = $c->getCrypto();
316
+            $config = $c->getConfig();
317
+            $logger = $c->getLogger();
318
+            $timeFactory = new TimeFactory();
319
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
320
+        });
321
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
322
+
323
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
324
+            $manager = $c->getUserManager();
325
+            $session = new \OC\Session\Memory('');
326
+            $timeFactory = new TimeFactory();
327
+            // Token providers might require a working database. This code
328
+            // might however be called when ownCloud is not yet setup.
329
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
330
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
331
+            } else {
332
+                $defaultTokenProvider = null;
333
+            }
334
+
335
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
336
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
337
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
338
+            });
339
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
340
+                /** @var $user \OC\User\User */
341
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
342
+            });
343
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
344
+                /** @var $user \OC\User\User */
345
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
346
+            });
347
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
348
+                /** @var $user \OC\User\User */
349
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
350
+            });
351
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
352
+                /** @var $user \OC\User\User */
353
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
354
+            });
355
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
356
+                /** @var $user \OC\User\User */
357
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
358
+            });
359
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
360
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
361
+            });
362
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
363
+                /** @var $user \OC\User\User */
364
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
365
+            });
366
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
367
+                /** @var $user \OC\User\User */
368
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
369
+            });
370
+            $userSession->listen('\OC\User', 'logout', function () {
371
+                \OC_Hook::emit('OC_User', 'logout', array());
372
+            });
373
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
374
+                /** @var $user \OC\User\User */
375
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
376
+            });
377
+            return $userSession;
378
+        });
379
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
380
+
381
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
382
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
383
+        });
384
+
385
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
386
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
387
+
388
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
389
+            return new \OC\AllConfig(
390
+                $c->getSystemConfig()
391
+            );
392
+        });
393
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
394
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
395
+
396
+        $this->registerService('SystemConfig', function ($c) use ($config) {
397
+            return new \OC\SystemConfig($config);
398
+        });
399
+
400
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
401
+            return new \OC\AppConfig($c->getDatabaseConnection());
402
+        });
403
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
404
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
405
+
406
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
407
+            return new \OC\L10N\Factory(
408
+                $c->getConfig(),
409
+                $c->getRequest(),
410
+                $c->getUserSession(),
411
+                \OC::$SERVERROOT
412
+            );
413
+        });
414
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
415
+
416
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
417
+            $config = $c->getConfig();
418
+            $cacheFactory = $c->getMemCacheFactory();
419
+            $request = $c->getRequest();
420
+            return new \OC\URLGenerator(
421
+                $config,
422
+                $cacheFactory,
423
+                $request
424
+            );
425
+        });
426
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
427
+
428
+        $this->registerService('AppHelper', function ($c) {
429
+            return new \OC\AppHelper();
430
+        });
431
+        $this->registerAlias('AppFetcher', AppFetcher::class);
432
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
433
+
434
+        $this->registerService(\OCP\ICache::class, function ($c) {
435
+            return new Cache\File();
436
+        });
437
+        $this->registerAlias('UserCache', \OCP\ICache::class);
438
+
439
+        $this->registerService(Factory::class, function (Server $c) {
440
+
441
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
442
+                '\\OC\\Memcache\\ArrayCache',
443
+                '\\OC\\Memcache\\ArrayCache',
444
+                '\\OC\\Memcache\\ArrayCache'
445
+            );
446
+            $config = $c->getConfig();
447
+            $request = $c->getRequest();
448
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
449
+
450
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
451
+                $v = \OC_App::getAppVersions();
452
+                $v['core'] = implode(',', \OC_Util::getVersion());
453
+                $version = implode(',', $v);
454
+                $instanceId = \OC_Util::getInstanceId();
455
+                $path = \OC::$SERVERROOT;
456
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
457
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
458
+                    $config->getSystemValue('memcache.local', null),
459
+                    $config->getSystemValue('memcache.distributed', null),
460
+                    $config->getSystemValue('memcache.locking', null)
461
+                );
462
+            }
463
+            return $arrayCacheFactory;
464
+
465
+        });
466
+        $this->registerAlias('MemCacheFactory', Factory::class);
467
+        $this->registerAlias(ICacheFactory::class, Factory::class);
468
+
469
+        $this->registerService('RedisFactory', function (Server $c) {
470
+            $systemConfig = $c->getSystemConfig();
471
+            return new RedisFactory($systemConfig);
472
+        });
473
+
474
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
475
+            return new \OC\Activity\Manager(
476
+                $c->getRequest(),
477
+                $c->getUserSession(),
478
+                $c->getConfig(),
479
+                $c->query(IValidator::class)
480
+            );
481
+        });
482
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
483
+
484
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
485
+            return new \OC\Activity\EventMerger(
486
+                $c->getL10N('lib')
487
+            );
488
+        });
489
+        $this->registerAlias(IValidator::class, Validator::class);
490
+
491
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
492
+            return new AvatarManager(
493
+                $c->getUserManager(),
494
+                $c->getAppDataDir('avatar'),
495
+                $c->getL10N('lib'),
496
+                $c->getLogger(),
497
+                $c->getConfig()
498
+            );
499
+        });
500
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
501
+
502
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
503
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
504
+            $logger = Log::getLogClass($logType);
505
+            call_user_func(array($logger, 'init'));
506
+
507
+            return new Log($logger);
508
+        });
509
+        $this->registerAlias('Logger', \OCP\ILogger::class);
510
+
511
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
512
+            $config = $c->getConfig();
513
+            return new \OC\BackgroundJob\JobList(
514
+                $c->getDatabaseConnection(),
515
+                $config,
516
+                new TimeFactory()
517
+            );
518
+        });
519
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
520
+
521
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
522
+            $cacheFactory = $c->getMemCacheFactory();
523
+            $logger = $c->getLogger();
524
+            if ($cacheFactory->isAvailable()) {
525
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
526
+            } else {
527
+                $router = new \OC\Route\Router($logger);
528
+            }
529
+            return $router;
530
+        });
531
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
532
+
533
+        $this->registerService(\OCP\ISearch::class, function ($c) {
534
+            return new Search();
535
+        });
536
+        $this->registerAlias('Search', \OCP\ISearch::class);
537
+
538
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
539
+            return new \OC\Security\RateLimiting\Limiter(
540
+                $this->getUserSession(),
541
+                $this->getRequest(),
542
+                new \OC\AppFramework\Utility\TimeFactory(),
543
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
544
+            );
545
+        });
546
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
547
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
548
+                $this->getMemCacheFactory(),
549
+                new \OC\AppFramework\Utility\TimeFactory()
550
+            );
551
+        });
552
+
553
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
554
+            return new SecureRandom();
555
+        });
556
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
557
+
558
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
559
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
560
+        });
561
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
562
+
563
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
564
+            return new Hasher($c->getConfig());
565
+        });
566
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
567
+
568
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
569
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
570
+        });
571
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
572
+
573
+        $this->registerService(IDBConnection::class, function (Server $c) {
574
+            $systemConfig = $c->getSystemConfig();
575
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
576
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
577
+            if (!$factory->isValidType($type)) {
578
+                throw new \OC\DatabaseException('Invalid database type');
579
+            }
580
+            $connectionParams = $factory->createConnectionParams();
581
+            $connection = $factory->getConnection($type, $connectionParams);
582
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
583
+            return $connection;
584
+        });
585
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
586
+
587
+        $this->registerService('HTTPHelper', function (Server $c) {
588
+            $config = $c->getConfig();
589
+            return new HTTPHelper(
590
+                $config,
591
+                $c->getHTTPClientService()
592
+            );
593
+        });
594
+
595
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
596
+            $user = \OC_User::getUser();
597
+            $uid = $user ? $user : null;
598
+            return new ClientService(
599
+                $c->getConfig(),
600
+                new \OC\Security\CertificateManager(
601
+                    $uid,
602
+                    new View(),
603
+                    $c->getConfig(),
604
+                    $c->getLogger(),
605
+                    $c->getSecureRandom()
606
+                )
607
+            );
608
+        });
609
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
610
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
611
+            $eventLogger = new EventLogger();
612
+            if ($c->getSystemConfig()->getValue('debug', false)) {
613
+                // In debug mode, module is being activated by default
614
+                $eventLogger->activate();
615
+            }
616
+            return $eventLogger;
617
+        });
618
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
619
+
620
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
621
+            $queryLogger = new QueryLogger();
622
+            if ($c->getSystemConfig()->getValue('debug', false)) {
623
+                // In debug mode, module is being activated by default
624
+                $queryLogger->activate();
625
+            }
626
+            return $queryLogger;
627
+        });
628
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
629
+
630
+        $this->registerService(TempManager::class, function (Server $c) {
631
+            return new TempManager(
632
+                $c->getLogger(),
633
+                $c->getConfig()
634
+            );
635
+        });
636
+        $this->registerAlias('TempManager', TempManager::class);
637
+        $this->registerAlias(ITempManager::class, TempManager::class);
638
+
639
+        $this->registerService(AppManager::class, function (Server $c) {
640
+            return new \OC\App\AppManager(
641
+                $c->getUserSession(),
642
+                $c->getAppConfig(),
643
+                $c->getGroupManager(),
644
+                $c->getMemCacheFactory(),
645
+                $c->getEventDispatcher()
646
+            );
647
+        });
648
+        $this->registerAlias('AppManager', AppManager::class);
649
+        $this->registerAlias(IAppManager::class, AppManager::class);
650
+
651
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
652
+            return new DateTimeZone(
653
+                $c->getConfig(),
654
+                $c->getSession()
655
+            );
656
+        });
657
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
658
+
659
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
660
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
661
+
662
+            return new DateTimeFormatter(
663
+                $c->getDateTimeZone()->getTimeZone(),
664
+                $c->getL10N('lib', $language)
665
+            );
666
+        });
667
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
668
+
669
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
670
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
671
+            $listener = new UserMountCacheListener($mountCache);
672
+            $listener->listen($c->getUserManager());
673
+            return $mountCache;
674
+        });
675
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
676
+
677
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
678
+            $loader = \OC\Files\Filesystem::getLoader();
679
+            $mountCache = $c->query('UserMountCache');
680
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
681
+
682
+            // builtin providers
683
+
684
+            $config = $c->getConfig();
685
+            $manager->registerProvider(new CacheMountProvider($config));
686
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
687
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
688
+
689
+            return $manager;
690
+        });
691
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
692
+
693
+        $this->registerService('IniWrapper', function ($c) {
694
+            return new IniGetWrapper();
695
+        });
696
+        $this->registerService('AsyncCommandBus', function (Server $c) {
697
+            $jobList = $c->getJobList();
698
+            return new AsyncBus($jobList);
699
+        });
700
+        $this->registerService('TrustedDomainHelper', function ($c) {
701
+            return new TrustedDomainHelper($this->getConfig());
702
+        });
703
+        $this->registerService('Throttler', function(Server $c) {
704
+            return new Throttler(
705
+                $c->getDatabaseConnection(),
706
+                new TimeFactory(),
707
+                $c->getLogger(),
708
+                $c->getConfig()
709
+            );
710
+        });
711
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
712
+            // IConfig and IAppManager requires a working database. This code
713
+            // might however be called when ownCloud is not yet setup.
714
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
715
+                $config = $c->getConfig();
716
+                $appManager = $c->getAppManager();
717
+            } else {
718
+                $config = null;
719
+                $appManager = null;
720
+            }
721
+
722
+            return new Checker(
723
+                    new EnvironmentHelper(),
724
+                    new FileAccessHelper(),
725
+                    new AppLocator(),
726
+                    $config,
727
+                    $c->getMemCacheFactory(),
728
+                    $appManager,
729
+                    $c->getTempManager()
730
+            );
731
+        });
732
+        $this->registerService(\OCP\IRequest::class, function ($c) {
733
+            if (isset($this['urlParams'])) {
734
+                $urlParams = $this['urlParams'];
735
+            } else {
736
+                $urlParams = [];
737
+            }
738
+
739
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
740
+                && in_array('fakeinput', stream_get_wrappers())
741
+            ) {
742
+                $stream = 'fakeinput://data';
743
+            } else {
744
+                $stream = 'php://input';
745
+            }
746
+
747
+            return new Request(
748
+                [
749
+                    'get' => $_GET,
750
+                    'post' => $_POST,
751
+                    'files' => $_FILES,
752
+                    'server' => $_SERVER,
753
+                    'env' => $_ENV,
754
+                    'cookies' => $_COOKIE,
755
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
756
+                        ? $_SERVER['REQUEST_METHOD']
757
+                        : null,
758
+                    'urlParams' => $urlParams,
759
+                ],
760
+                $this->getSecureRandom(),
761
+                $this->getConfig(),
762
+                $this->getCsrfTokenManager(),
763
+                $stream
764
+            );
765
+        });
766
+        $this->registerAlias('Request', \OCP\IRequest::class);
767
+
768
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
769
+            return new Mailer(
770
+                $c->getConfig(),
771
+                $c->getLogger(),
772
+                $c->query(Defaults::class),
773
+                $c->getURLGenerator(),
774
+                $c->getL10N('lib')
775
+            );
776
+        });
777
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
778
+
779
+        $this->registerService('LDAPProvider', function(Server $c) {
780
+            $config = $c->getConfig();
781
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
782
+            if(is_null($factoryClass)) {
783
+                throw new \Exception('ldapProviderFactory not set');
784
+            }
785
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
786
+            $factory = new $factoryClass($this);
787
+            return $factory->getLDAPProvider();
788
+        });
789
+        $this->registerService(ILockingProvider::class, function (Server $c) {
790
+            $ini = $c->getIniWrapper();
791
+            $config = $c->getConfig();
792
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
793
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
794
+                /** @var \OC\Memcache\Factory $memcacheFactory */
795
+                $memcacheFactory = $c->getMemCacheFactory();
796
+                $memcache = $memcacheFactory->createLocking('lock');
797
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
798
+                    return new MemcacheLockingProvider($memcache, $ttl);
799
+                }
800
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
801
+            }
802
+            return new NoopLockingProvider();
803
+        });
804
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
805
+
806
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
807
+            return new \OC\Files\Mount\Manager();
808
+        });
809
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
810
+
811
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
812
+            return new \OC\Files\Type\Detection(
813
+                $c->getURLGenerator(),
814
+                \OC::$configDir,
815
+                \OC::$SERVERROOT . '/resources/config/'
816
+            );
817
+        });
818
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
819
+
820
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
821
+            return new \OC\Files\Type\Loader(
822
+                $c->getDatabaseConnection()
823
+            );
824
+        });
825
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
826
+        $this->registerService(BundleFetcher::class, function () {
827
+            return new BundleFetcher($this->getL10N('lib'));
828
+        });
829
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
830
+            return new Manager(
831
+                $c->query(IValidator::class)
832
+            );
833
+        });
834
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
835
+
836
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
837
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
838
+            $manager->registerCapability(function () use ($c) {
839
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
840
+            });
841
+            $manager->registerCapability(function () use ($c) {
842
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
843
+            });
844
+            return $manager;
845
+        });
846
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
847
+
848
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
849
+            $config = $c->getConfig();
850
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
851
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
852
+            $factory = new $factoryClass($this);
853
+            return $factory->getManager();
854
+        });
855
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
856
+
857
+        $this->registerService('ThemingDefaults', function(Server $c) {
858
+            /*
859 859
 			 * Dark magic for autoloader.
860 860
 			 * If we do a class_exists it will try to load the class which will
861 861
 			 * make composer cache the result. Resulting in errors when enabling
862 862
 			 * the theming app.
863 863
 			 */
864
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
865
-			if (isset($prefixes['OCA\\Theming\\'])) {
866
-				$classExists = true;
867
-			} else {
868
-				$classExists = false;
869
-			}
870
-
871
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
872
-				return new ThemingDefaults(
873
-					$c->getConfig(),
874
-					$c->getL10N('theming'),
875
-					$c->getURLGenerator(),
876
-					$c->getAppDataDir('theming'),
877
-					$c->getMemCacheFactory(),
878
-					new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
879
-				);
880
-			}
881
-			return new \OC_Defaults();
882
-		});
883
-		$this->registerService(SCSSCacher::class, function(Server $c) {
884
-			/** @var Factory $cacheFactory */
885
-			$cacheFactory = $c->query(Factory::class);
886
-			return new SCSSCacher(
887
-				$c->getLogger(),
888
-				$c->query(\OC\Files\AppData\Factory::class),
889
-				$c->getURLGenerator(),
890
-				$c->getConfig(),
891
-				$c->getThemingDefaults(),
892
-				\OC::$SERVERROOT,
893
-				$cacheFactory->create('SCSS')
894
-			);
895
-		});
896
-		$this->registerService(EventDispatcher::class, function () {
897
-			return new EventDispatcher();
898
-		});
899
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
900
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
901
-
902
-		$this->registerService('CryptoWrapper', function (Server $c) {
903
-			// FIXME: Instantiiated here due to cyclic dependency
904
-			$request = new Request(
905
-				[
906
-					'get' => $_GET,
907
-					'post' => $_POST,
908
-					'files' => $_FILES,
909
-					'server' => $_SERVER,
910
-					'env' => $_ENV,
911
-					'cookies' => $_COOKIE,
912
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
913
-						? $_SERVER['REQUEST_METHOD']
914
-						: null,
915
-				],
916
-				$c->getSecureRandom(),
917
-				$c->getConfig()
918
-			);
919
-
920
-			return new CryptoWrapper(
921
-				$c->getConfig(),
922
-				$c->getCrypto(),
923
-				$c->getSecureRandom(),
924
-				$request
925
-			);
926
-		});
927
-		$this->registerService('CsrfTokenManager', function (Server $c) {
928
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
929
-
930
-			return new CsrfTokenManager(
931
-				$tokenGenerator,
932
-				$c->query(SessionStorage::class)
933
-			);
934
-		});
935
-		$this->registerService(SessionStorage::class, function (Server $c) {
936
-			return new SessionStorage($c->getSession());
937
-		});
938
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
939
-			return new ContentSecurityPolicyManager();
940
-		});
941
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
942
-
943
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
944
-			return new ContentSecurityPolicyNonceManager(
945
-				$c->getCsrfTokenManager(),
946
-				$c->getRequest()
947
-			);
948
-		});
949
-
950
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
951
-			$config = $c->getConfig();
952
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
953
-			/** @var \OCP\Share\IProviderFactory $factory */
954
-			$factory = new $factoryClass($this);
955
-
956
-			$manager = new \OC\Share20\Manager(
957
-				$c->getLogger(),
958
-				$c->getConfig(),
959
-				$c->getSecureRandom(),
960
-				$c->getHasher(),
961
-				$c->getMountManager(),
962
-				$c->getGroupManager(),
963
-				$c->getL10N('core'),
964
-				$factory,
965
-				$c->getUserManager(),
966
-				$c->getLazyRootFolder(),
967
-				$c->getEventDispatcher(),
968
-				$c->getMailer(),
969
-				$c->getURLGenerator(),
970
-				$c->getThemingDefaults()
971
-			);
972
-
973
-			return $manager;
974
-		});
975
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
976
-
977
-		$this->registerService('SettingsManager', function(Server $c) {
978
-			$manager = new \OC\Settings\Manager(
979
-				$c->getLogger(),
980
-				$c->getDatabaseConnection(),
981
-				$c->getL10N('lib'),
982
-				$c->getConfig(),
983
-				$c->getEncryptionManager(),
984
-				$c->getUserManager(),
985
-				$c->getLockingProvider(),
986
-				$c->getRequest(),
987
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
988
-				$c->getURLGenerator(),
989
-				$c->query(AccountManager::class),
990
-				$c->getGroupManager(),
991
-				$c->getL10NFactory(),
992
-				$c->getThemingDefaults(),
993
-				$c->getAppManager()
994
-			);
995
-			return $manager;
996
-		});
997
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
998
-			return new \OC\Files\AppData\Factory(
999
-				$c->getRootFolder(),
1000
-				$c->getSystemConfig()
1001
-			);
1002
-		});
1003
-
1004
-		$this->registerService('LockdownManager', function (Server $c) {
1005
-			return new LockdownManager(function() use ($c) {
1006
-				return $c->getSession();
1007
-			});
1008
-		});
1009
-
1010
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1011
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1012
-		});
1013
-
1014
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1015
-			return new CloudIdManager();
1016
-		});
1017
-
1018
-		/* To trick DI since we don't extend the DIContainer here */
1019
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1020
-			return new CleanPreviewsBackgroundJob(
1021
-				$c->getRootFolder(),
1022
-				$c->getLogger(),
1023
-				$c->getJobList(),
1024
-				new TimeFactory()
1025
-			);
1026
-		});
1027
-
1028
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1029
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1030
-
1031
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1032
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1033
-
1034
-		$this->registerService(Defaults::class, function (Server $c) {
1035
-			return new Defaults(
1036
-				$c->getThemingDefaults()
1037
-			);
1038
-		});
1039
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1040
-
1041
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1042
-			return $c->query(\OCP\IUserSession::class)->getSession();
1043
-		});
1044
-
1045
-		$this->registerService(IShareHelper::class, function(Server $c) {
1046
-			return new ShareHelper(
1047
-				$c->query(\OCP\Share\IManager::class)
1048
-			);
1049
-		});
1050
-	}
1051
-
1052
-	/**
1053
-	 * @return \OCP\Contacts\IManager
1054
-	 */
1055
-	public function getContactsManager() {
1056
-		return $this->query('ContactsManager');
1057
-	}
1058
-
1059
-	/**
1060
-	 * @return \OC\Encryption\Manager
1061
-	 */
1062
-	public function getEncryptionManager() {
1063
-		return $this->query('EncryptionManager');
1064
-	}
1065
-
1066
-	/**
1067
-	 * @return \OC\Encryption\File
1068
-	 */
1069
-	public function getEncryptionFilesHelper() {
1070
-		return $this->query('EncryptionFileHelper');
1071
-	}
1072
-
1073
-	/**
1074
-	 * @return \OCP\Encryption\Keys\IStorage
1075
-	 */
1076
-	public function getEncryptionKeyStorage() {
1077
-		return $this->query('EncryptionKeyStorage');
1078
-	}
1079
-
1080
-	/**
1081
-	 * The current request object holding all information about the request
1082
-	 * currently being processed is returned from this method.
1083
-	 * In case the current execution was not initiated by a web request null is returned
1084
-	 *
1085
-	 * @return \OCP\IRequest
1086
-	 */
1087
-	public function getRequest() {
1088
-		return $this->query('Request');
1089
-	}
1090
-
1091
-	/**
1092
-	 * Returns the preview manager which can create preview images for a given file
1093
-	 *
1094
-	 * @return \OCP\IPreview
1095
-	 */
1096
-	public function getPreviewManager() {
1097
-		return $this->query('PreviewManager');
1098
-	}
1099
-
1100
-	/**
1101
-	 * Returns the tag manager which can get and set tags for different object types
1102
-	 *
1103
-	 * @see \OCP\ITagManager::load()
1104
-	 * @return \OCP\ITagManager
1105
-	 */
1106
-	public function getTagManager() {
1107
-		return $this->query('TagManager');
1108
-	}
1109
-
1110
-	/**
1111
-	 * Returns the system-tag manager
1112
-	 *
1113
-	 * @return \OCP\SystemTag\ISystemTagManager
1114
-	 *
1115
-	 * @since 9.0.0
1116
-	 */
1117
-	public function getSystemTagManager() {
1118
-		return $this->query('SystemTagManager');
1119
-	}
1120
-
1121
-	/**
1122
-	 * Returns the system-tag object mapper
1123
-	 *
1124
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1125
-	 *
1126
-	 * @since 9.0.0
1127
-	 */
1128
-	public function getSystemTagObjectMapper() {
1129
-		return $this->query('SystemTagObjectMapper');
1130
-	}
1131
-
1132
-	/**
1133
-	 * Returns the avatar manager, used for avatar functionality
1134
-	 *
1135
-	 * @return \OCP\IAvatarManager
1136
-	 */
1137
-	public function getAvatarManager() {
1138
-		return $this->query('AvatarManager');
1139
-	}
1140
-
1141
-	/**
1142
-	 * Returns the root folder of ownCloud's data directory
1143
-	 *
1144
-	 * @return \OCP\Files\IRootFolder
1145
-	 */
1146
-	public function getRootFolder() {
1147
-		return $this->query('LazyRootFolder');
1148
-	}
1149
-
1150
-	/**
1151
-	 * Returns the root folder of ownCloud's data directory
1152
-	 * This is the lazy variant so this gets only initialized once it
1153
-	 * is actually used.
1154
-	 *
1155
-	 * @return \OCP\Files\IRootFolder
1156
-	 */
1157
-	public function getLazyRootFolder() {
1158
-		return $this->query('LazyRootFolder');
1159
-	}
1160
-
1161
-	/**
1162
-	 * Returns a view to ownCloud's files folder
1163
-	 *
1164
-	 * @param string $userId user ID
1165
-	 * @return \OCP\Files\Folder|null
1166
-	 */
1167
-	public function getUserFolder($userId = null) {
1168
-		if ($userId === null) {
1169
-			$user = $this->getUserSession()->getUser();
1170
-			if (!$user) {
1171
-				return null;
1172
-			}
1173
-			$userId = $user->getUID();
1174
-		}
1175
-		$root = $this->getRootFolder();
1176
-		return $root->getUserFolder($userId);
1177
-	}
1178
-
1179
-	/**
1180
-	 * Returns an app-specific view in ownClouds data directory
1181
-	 *
1182
-	 * @return \OCP\Files\Folder
1183
-	 * @deprecated since 9.2.0 use IAppData
1184
-	 */
1185
-	public function getAppFolder() {
1186
-		$dir = '/' . \OC_App::getCurrentApp();
1187
-		$root = $this->getRootFolder();
1188
-		if (!$root->nodeExists($dir)) {
1189
-			$folder = $root->newFolder($dir);
1190
-		} else {
1191
-			$folder = $root->get($dir);
1192
-		}
1193
-		return $folder;
1194
-	}
1195
-
1196
-	/**
1197
-	 * @return \OC\User\Manager
1198
-	 */
1199
-	public function getUserManager() {
1200
-		return $this->query('UserManager');
1201
-	}
1202
-
1203
-	/**
1204
-	 * @return \OC\Group\Manager
1205
-	 */
1206
-	public function getGroupManager() {
1207
-		return $this->query('GroupManager');
1208
-	}
1209
-
1210
-	/**
1211
-	 * @return \OC\User\Session
1212
-	 */
1213
-	public function getUserSession() {
1214
-		return $this->query('UserSession');
1215
-	}
1216
-
1217
-	/**
1218
-	 * @return \OCP\ISession
1219
-	 */
1220
-	public function getSession() {
1221
-		return $this->query('UserSession')->getSession();
1222
-	}
1223
-
1224
-	/**
1225
-	 * @param \OCP\ISession $session
1226
-	 */
1227
-	public function setSession(\OCP\ISession $session) {
1228
-		$this->query(SessionStorage::class)->setSession($session);
1229
-		$this->query('UserSession')->setSession($session);
1230
-		$this->query(Store::class)->setSession($session);
1231
-	}
1232
-
1233
-	/**
1234
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1235
-	 */
1236
-	public function getTwoFactorAuthManager() {
1237
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1238
-	}
1239
-
1240
-	/**
1241
-	 * @return \OC\NavigationManager
1242
-	 */
1243
-	public function getNavigationManager() {
1244
-		return $this->query('NavigationManager');
1245
-	}
1246
-
1247
-	/**
1248
-	 * @return \OCP\IConfig
1249
-	 */
1250
-	public function getConfig() {
1251
-		return $this->query('AllConfig');
1252
-	}
1253
-
1254
-	/**
1255
-	 * @internal For internal use only
1256
-	 * @return \OC\SystemConfig
1257
-	 */
1258
-	public function getSystemConfig() {
1259
-		return $this->query('SystemConfig');
1260
-	}
1261
-
1262
-	/**
1263
-	 * Returns the app config manager
1264
-	 *
1265
-	 * @return \OCP\IAppConfig
1266
-	 */
1267
-	public function getAppConfig() {
1268
-		return $this->query('AppConfig');
1269
-	}
1270
-
1271
-	/**
1272
-	 * @return \OCP\L10N\IFactory
1273
-	 */
1274
-	public function getL10NFactory() {
1275
-		return $this->query('L10NFactory');
1276
-	}
1277
-
1278
-	/**
1279
-	 * get an L10N instance
1280
-	 *
1281
-	 * @param string $app appid
1282
-	 * @param string $lang
1283
-	 * @return IL10N
1284
-	 */
1285
-	public function getL10N($app, $lang = null) {
1286
-		return $this->getL10NFactory()->get($app, $lang);
1287
-	}
1288
-
1289
-	/**
1290
-	 * @return \OCP\IURLGenerator
1291
-	 */
1292
-	public function getURLGenerator() {
1293
-		return $this->query('URLGenerator');
1294
-	}
1295
-
1296
-	/**
1297
-	 * @return \OCP\IHelper
1298
-	 */
1299
-	public function getHelper() {
1300
-		return $this->query('AppHelper');
1301
-	}
1302
-
1303
-	/**
1304
-	 * @return AppFetcher
1305
-	 */
1306
-	public function getAppFetcher() {
1307
-		return $this->query(AppFetcher::class);
1308
-	}
1309
-
1310
-	/**
1311
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1312
-	 * getMemCacheFactory() instead.
1313
-	 *
1314
-	 * @return \OCP\ICache
1315
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1316
-	 */
1317
-	public function getCache() {
1318
-		return $this->query('UserCache');
1319
-	}
1320
-
1321
-	/**
1322
-	 * Returns an \OCP\CacheFactory instance
1323
-	 *
1324
-	 * @return \OCP\ICacheFactory
1325
-	 */
1326
-	public function getMemCacheFactory() {
1327
-		return $this->query('MemCacheFactory');
1328
-	}
1329
-
1330
-	/**
1331
-	 * Returns an \OC\RedisFactory instance
1332
-	 *
1333
-	 * @return \OC\RedisFactory
1334
-	 */
1335
-	public function getGetRedisFactory() {
1336
-		return $this->query('RedisFactory');
1337
-	}
1338
-
1339
-
1340
-	/**
1341
-	 * Returns the current session
1342
-	 *
1343
-	 * @return \OCP\IDBConnection
1344
-	 */
1345
-	public function getDatabaseConnection() {
1346
-		return $this->query('DatabaseConnection');
1347
-	}
1348
-
1349
-	/**
1350
-	 * Returns the activity manager
1351
-	 *
1352
-	 * @return \OCP\Activity\IManager
1353
-	 */
1354
-	public function getActivityManager() {
1355
-		return $this->query('ActivityManager');
1356
-	}
1357
-
1358
-	/**
1359
-	 * Returns an job list for controlling background jobs
1360
-	 *
1361
-	 * @return \OCP\BackgroundJob\IJobList
1362
-	 */
1363
-	public function getJobList() {
1364
-		return $this->query('JobList');
1365
-	}
1366
-
1367
-	/**
1368
-	 * Returns a logger instance
1369
-	 *
1370
-	 * @return \OCP\ILogger
1371
-	 */
1372
-	public function getLogger() {
1373
-		return $this->query('Logger');
1374
-	}
1375
-
1376
-	/**
1377
-	 * Returns a router for generating and matching urls
1378
-	 *
1379
-	 * @return \OCP\Route\IRouter
1380
-	 */
1381
-	public function getRouter() {
1382
-		return $this->query('Router');
1383
-	}
1384
-
1385
-	/**
1386
-	 * Returns a search instance
1387
-	 *
1388
-	 * @return \OCP\ISearch
1389
-	 */
1390
-	public function getSearch() {
1391
-		return $this->query('Search');
1392
-	}
1393
-
1394
-	/**
1395
-	 * Returns a SecureRandom instance
1396
-	 *
1397
-	 * @return \OCP\Security\ISecureRandom
1398
-	 */
1399
-	public function getSecureRandom() {
1400
-		return $this->query('SecureRandom');
1401
-	}
1402
-
1403
-	/**
1404
-	 * Returns a Crypto instance
1405
-	 *
1406
-	 * @return \OCP\Security\ICrypto
1407
-	 */
1408
-	public function getCrypto() {
1409
-		return $this->query('Crypto');
1410
-	}
1411
-
1412
-	/**
1413
-	 * Returns a Hasher instance
1414
-	 *
1415
-	 * @return \OCP\Security\IHasher
1416
-	 */
1417
-	public function getHasher() {
1418
-		return $this->query('Hasher');
1419
-	}
1420
-
1421
-	/**
1422
-	 * Returns a CredentialsManager instance
1423
-	 *
1424
-	 * @return \OCP\Security\ICredentialsManager
1425
-	 */
1426
-	public function getCredentialsManager() {
1427
-		return $this->query('CredentialsManager');
1428
-	}
1429
-
1430
-	/**
1431
-	 * Returns an instance of the HTTP helper class
1432
-	 *
1433
-	 * @deprecated Use getHTTPClientService()
1434
-	 * @return \OC\HTTPHelper
1435
-	 */
1436
-	public function getHTTPHelper() {
1437
-		return $this->query('HTTPHelper');
1438
-	}
1439
-
1440
-	/**
1441
-	 * Get the certificate manager for the user
1442
-	 *
1443
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1444
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1445
-	 */
1446
-	public function getCertificateManager($userId = '') {
1447
-		if ($userId === '') {
1448
-			$userSession = $this->getUserSession();
1449
-			$user = $userSession->getUser();
1450
-			if (is_null($user)) {
1451
-				return null;
1452
-			}
1453
-			$userId = $user->getUID();
1454
-		}
1455
-		return new CertificateManager(
1456
-			$userId,
1457
-			new View(),
1458
-			$this->getConfig(),
1459
-			$this->getLogger(),
1460
-			$this->getSecureRandom()
1461
-		);
1462
-	}
1463
-
1464
-	/**
1465
-	 * Returns an instance of the HTTP client service
1466
-	 *
1467
-	 * @return \OCP\Http\Client\IClientService
1468
-	 */
1469
-	public function getHTTPClientService() {
1470
-		return $this->query('HttpClientService');
1471
-	}
1472
-
1473
-	/**
1474
-	 * Create a new event source
1475
-	 *
1476
-	 * @return \OCP\IEventSource
1477
-	 */
1478
-	public function createEventSource() {
1479
-		return new \OC_EventSource();
1480
-	}
1481
-
1482
-	/**
1483
-	 * Get the active event logger
1484
-	 *
1485
-	 * The returned logger only logs data when debug mode is enabled
1486
-	 *
1487
-	 * @return \OCP\Diagnostics\IEventLogger
1488
-	 */
1489
-	public function getEventLogger() {
1490
-		return $this->query('EventLogger');
1491
-	}
1492
-
1493
-	/**
1494
-	 * Get the active query logger
1495
-	 *
1496
-	 * The returned logger only logs data when debug mode is enabled
1497
-	 *
1498
-	 * @return \OCP\Diagnostics\IQueryLogger
1499
-	 */
1500
-	public function getQueryLogger() {
1501
-		return $this->query('QueryLogger');
1502
-	}
1503
-
1504
-	/**
1505
-	 * Get the manager for temporary files and folders
1506
-	 *
1507
-	 * @return \OCP\ITempManager
1508
-	 */
1509
-	public function getTempManager() {
1510
-		return $this->query('TempManager');
1511
-	}
1512
-
1513
-	/**
1514
-	 * Get the app manager
1515
-	 *
1516
-	 * @return \OCP\App\IAppManager
1517
-	 */
1518
-	public function getAppManager() {
1519
-		return $this->query('AppManager');
1520
-	}
1521
-
1522
-	/**
1523
-	 * Creates a new mailer
1524
-	 *
1525
-	 * @return \OCP\Mail\IMailer
1526
-	 */
1527
-	public function getMailer() {
1528
-		return $this->query('Mailer');
1529
-	}
1530
-
1531
-	/**
1532
-	 * Get the webroot
1533
-	 *
1534
-	 * @return string
1535
-	 */
1536
-	public function getWebRoot() {
1537
-		return $this->webRoot;
1538
-	}
1539
-
1540
-	/**
1541
-	 * @return \OC\OCSClient
1542
-	 */
1543
-	public function getOcsClient() {
1544
-		return $this->query('OcsClient');
1545
-	}
1546
-
1547
-	/**
1548
-	 * @return \OCP\IDateTimeZone
1549
-	 */
1550
-	public function getDateTimeZone() {
1551
-		return $this->query('DateTimeZone');
1552
-	}
1553
-
1554
-	/**
1555
-	 * @return \OCP\IDateTimeFormatter
1556
-	 */
1557
-	public function getDateTimeFormatter() {
1558
-		return $this->query('DateTimeFormatter');
1559
-	}
1560
-
1561
-	/**
1562
-	 * @return \OCP\Files\Config\IMountProviderCollection
1563
-	 */
1564
-	public function getMountProviderCollection() {
1565
-		return $this->query('MountConfigManager');
1566
-	}
1567
-
1568
-	/**
1569
-	 * Get the IniWrapper
1570
-	 *
1571
-	 * @return IniGetWrapper
1572
-	 */
1573
-	public function getIniWrapper() {
1574
-		return $this->query('IniWrapper');
1575
-	}
1576
-
1577
-	/**
1578
-	 * @return \OCP\Command\IBus
1579
-	 */
1580
-	public function getCommandBus() {
1581
-		return $this->query('AsyncCommandBus');
1582
-	}
1583
-
1584
-	/**
1585
-	 * Get the trusted domain helper
1586
-	 *
1587
-	 * @return TrustedDomainHelper
1588
-	 */
1589
-	public function getTrustedDomainHelper() {
1590
-		return $this->query('TrustedDomainHelper');
1591
-	}
1592
-
1593
-	/**
1594
-	 * Get the locking provider
1595
-	 *
1596
-	 * @return \OCP\Lock\ILockingProvider
1597
-	 * @since 8.1.0
1598
-	 */
1599
-	public function getLockingProvider() {
1600
-		return $this->query('LockingProvider');
1601
-	}
1602
-
1603
-	/**
1604
-	 * @return \OCP\Files\Mount\IMountManager
1605
-	 **/
1606
-	function getMountManager() {
1607
-		return $this->query('MountManager');
1608
-	}
1609
-
1610
-	/** @return \OCP\Files\Config\IUserMountCache */
1611
-	function getUserMountCache() {
1612
-		return $this->query('UserMountCache');
1613
-	}
1614
-
1615
-	/**
1616
-	 * Get the MimeTypeDetector
1617
-	 *
1618
-	 * @return \OCP\Files\IMimeTypeDetector
1619
-	 */
1620
-	public function getMimeTypeDetector() {
1621
-		return $this->query('MimeTypeDetector');
1622
-	}
1623
-
1624
-	/**
1625
-	 * Get the MimeTypeLoader
1626
-	 *
1627
-	 * @return \OCP\Files\IMimeTypeLoader
1628
-	 */
1629
-	public function getMimeTypeLoader() {
1630
-		return $this->query('MimeTypeLoader');
1631
-	}
1632
-
1633
-	/**
1634
-	 * Get the manager of all the capabilities
1635
-	 *
1636
-	 * @return \OC\CapabilitiesManager
1637
-	 */
1638
-	public function getCapabilitiesManager() {
1639
-		return $this->query('CapabilitiesManager');
1640
-	}
1641
-
1642
-	/**
1643
-	 * Get the EventDispatcher
1644
-	 *
1645
-	 * @return EventDispatcherInterface
1646
-	 * @since 8.2.0
1647
-	 */
1648
-	public function getEventDispatcher() {
1649
-		return $this->query('EventDispatcher');
1650
-	}
1651
-
1652
-	/**
1653
-	 * Get the Notification Manager
1654
-	 *
1655
-	 * @return \OCP\Notification\IManager
1656
-	 * @since 8.2.0
1657
-	 */
1658
-	public function getNotificationManager() {
1659
-		return $this->query('NotificationManager');
1660
-	}
1661
-
1662
-	/**
1663
-	 * @return \OCP\Comments\ICommentsManager
1664
-	 */
1665
-	public function getCommentsManager() {
1666
-		return $this->query('CommentsManager');
1667
-	}
1668
-
1669
-	/**
1670
-	 * @return \OCA\Theming\ThemingDefaults
1671
-	 */
1672
-	public function getThemingDefaults() {
1673
-		return $this->query('ThemingDefaults');
1674
-	}
1675
-
1676
-	/**
1677
-	 * @return \OC\IntegrityCheck\Checker
1678
-	 */
1679
-	public function getIntegrityCodeChecker() {
1680
-		return $this->query('IntegrityCodeChecker');
1681
-	}
1682
-
1683
-	/**
1684
-	 * @return \OC\Session\CryptoWrapper
1685
-	 */
1686
-	public function getSessionCryptoWrapper() {
1687
-		return $this->query('CryptoWrapper');
1688
-	}
1689
-
1690
-	/**
1691
-	 * @return CsrfTokenManager
1692
-	 */
1693
-	public function getCsrfTokenManager() {
1694
-		return $this->query('CsrfTokenManager');
1695
-	}
1696
-
1697
-	/**
1698
-	 * @return Throttler
1699
-	 */
1700
-	public function getBruteForceThrottler() {
1701
-		return $this->query('Throttler');
1702
-	}
1703
-
1704
-	/**
1705
-	 * @return IContentSecurityPolicyManager
1706
-	 */
1707
-	public function getContentSecurityPolicyManager() {
1708
-		return $this->query('ContentSecurityPolicyManager');
1709
-	}
1710
-
1711
-	/**
1712
-	 * @return ContentSecurityPolicyNonceManager
1713
-	 */
1714
-	public function getContentSecurityPolicyNonceManager() {
1715
-		return $this->query('ContentSecurityPolicyNonceManager');
1716
-	}
1717
-
1718
-	/**
1719
-	 * Not a public API as of 8.2, wait for 9.0
1720
-	 *
1721
-	 * @return \OCA\Files_External\Service\BackendService
1722
-	 */
1723
-	public function getStoragesBackendService() {
1724
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1725
-	}
1726
-
1727
-	/**
1728
-	 * Not a public API as of 8.2, wait for 9.0
1729
-	 *
1730
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1731
-	 */
1732
-	public function getGlobalStoragesService() {
1733
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1734
-	}
1735
-
1736
-	/**
1737
-	 * Not a public API as of 8.2, wait for 9.0
1738
-	 *
1739
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1740
-	 */
1741
-	public function getUserGlobalStoragesService() {
1742
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1743
-	}
1744
-
1745
-	/**
1746
-	 * Not a public API as of 8.2, wait for 9.0
1747
-	 *
1748
-	 * @return \OCA\Files_External\Service\UserStoragesService
1749
-	 */
1750
-	public function getUserStoragesService() {
1751
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1752
-	}
1753
-
1754
-	/**
1755
-	 * @return \OCP\Share\IManager
1756
-	 */
1757
-	public function getShareManager() {
1758
-		return $this->query('ShareManager');
1759
-	}
1760
-
1761
-	/**
1762
-	 * Returns the LDAP Provider
1763
-	 *
1764
-	 * @return \OCP\LDAP\ILDAPProvider
1765
-	 */
1766
-	public function getLDAPProvider() {
1767
-		return $this->query('LDAPProvider');
1768
-	}
1769
-
1770
-	/**
1771
-	 * @return \OCP\Settings\IManager
1772
-	 */
1773
-	public function getSettingsManager() {
1774
-		return $this->query('SettingsManager');
1775
-	}
1776
-
1777
-	/**
1778
-	 * @return \OCP\Files\IAppData
1779
-	 */
1780
-	public function getAppDataDir($app) {
1781
-		/** @var \OC\Files\AppData\Factory $factory */
1782
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1783
-		return $factory->get($app);
1784
-	}
1785
-
1786
-	/**
1787
-	 * @return \OCP\Lockdown\ILockdownManager
1788
-	 */
1789
-	public function getLockdownManager() {
1790
-		return $this->query('LockdownManager');
1791
-	}
1792
-
1793
-	/**
1794
-	 * @return \OCP\Federation\ICloudIdManager
1795
-	 */
1796
-	public function getCloudIdManager() {
1797
-		return $this->query(ICloudIdManager::class);
1798
-	}
864
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
865
+            if (isset($prefixes['OCA\\Theming\\'])) {
866
+                $classExists = true;
867
+            } else {
868
+                $classExists = false;
869
+            }
870
+
871
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
872
+                return new ThemingDefaults(
873
+                    $c->getConfig(),
874
+                    $c->getL10N('theming'),
875
+                    $c->getURLGenerator(),
876
+                    $c->getAppDataDir('theming'),
877
+                    $c->getMemCacheFactory(),
878
+                    new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming'))
879
+                );
880
+            }
881
+            return new \OC_Defaults();
882
+        });
883
+        $this->registerService(SCSSCacher::class, function(Server $c) {
884
+            /** @var Factory $cacheFactory */
885
+            $cacheFactory = $c->query(Factory::class);
886
+            return new SCSSCacher(
887
+                $c->getLogger(),
888
+                $c->query(\OC\Files\AppData\Factory::class),
889
+                $c->getURLGenerator(),
890
+                $c->getConfig(),
891
+                $c->getThemingDefaults(),
892
+                \OC::$SERVERROOT,
893
+                $cacheFactory->create('SCSS')
894
+            );
895
+        });
896
+        $this->registerService(EventDispatcher::class, function () {
897
+            return new EventDispatcher();
898
+        });
899
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
900
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
901
+
902
+        $this->registerService('CryptoWrapper', function (Server $c) {
903
+            // FIXME: Instantiiated here due to cyclic dependency
904
+            $request = new Request(
905
+                [
906
+                    'get' => $_GET,
907
+                    'post' => $_POST,
908
+                    'files' => $_FILES,
909
+                    'server' => $_SERVER,
910
+                    'env' => $_ENV,
911
+                    'cookies' => $_COOKIE,
912
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
913
+                        ? $_SERVER['REQUEST_METHOD']
914
+                        : null,
915
+                ],
916
+                $c->getSecureRandom(),
917
+                $c->getConfig()
918
+            );
919
+
920
+            return new CryptoWrapper(
921
+                $c->getConfig(),
922
+                $c->getCrypto(),
923
+                $c->getSecureRandom(),
924
+                $request
925
+            );
926
+        });
927
+        $this->registerService('CsrfTokenManager', function (Server $c) {
928
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
929
+
930
+            return new CsrfTokenManager(
931
+                $tokenGenerator,
932
+                $c->query(SessionStorage::class)
933
+            );
934
+        });
935
+        $this->registerService(SessionStorage::class, function (Server $c) {
936
+            return new SessionStorage($c->getSession());
937
+        });
938
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
939
+            return new ContentSecurityPolicyManager();
940
+        });
941
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
942
+
943
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
944
+            return new ContentSecurityPolicyNonceManager(
945
+                $c->getCsrfTokenManager(),
946
+                $c->getRequest()
947
+            );
948
+        });
949
+
950
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
951
+            $config = $c->getConfig();
952
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
953
+            /** @var \OCP\Share\IProviderFactory $factory */
954
+            $factory = new $factoryClass($this);
955
+
956
+            $manager = new \OC\Share20\Manager(
957
+                $c->getLogger(),
958
+                $c->getConfig(),
959
+                $c->getSecureRandom(),
960
+                $c->getHasher(),
961
+                $c->getMountManager(),
962
+                $c->getGroupManager(),
963
+                $c->getL10N('core'),
964
+                $factory,
965
+                $c->getUserManager(),
966
+                $c->getLazyRootFolder(),
967
+                $c->getEventDispatcher(),
968
+                $c->getMailer(),
969
+                $c->getURLGenerator(),
970
+                $c->getThemingDefaults()
971
+            );
972
+
973
+            return $manager;
974
+        });
975
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
976
+
977
+        $this->registerService('SettingsManager', function(Server $c) {
978
+            $manager = new \OC\Settings\Manager(
979
+                $c->getLogger(),
980
+                $c->getDatabaseConnection(),
981
+                $c->getL10N('lib'),
982
+                $c->getConfig(),
983
+                $c->getEncryptionManager(),
984
+                $c->getUserManager(),
985
+                $c->getLockingProvider(),
986
+                $c->getRequest(),
987
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
988
+                $c->getURLGenerator(),
989
+                $c->query(AccountManager::class),
990
+                $c->getGroupManager(),
991
+                $c->getL10NFactory(),
992
+                $c->getThemingDefaults(),
993
+                $c->getAppManager()
994
+            );
995
+            return $manager;
996
+        });
997
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
998
+            return new \OC\Files\AppData\Factory(
999
+                $c->getRootFolder(),
1000
+                $c->getSystemConfig()
1001
+            );
1002
+        });
1003
+
1004
+        $this->registerService('LockdownManager', function (Server $c) {
1005
+            return new LockdownManager(function() use ($c) {
1006
+                return $c->getSession();
1007
+            });
1008
+        });
1009
+
1010
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1011
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1012
+        });
1013
+
1014
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1015
+            return new CloudIdManager();
1016
+        });
1017
+
1018
+        /* To trick DI since we don't extend the DIContainer here */
1019
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1020
+            return new CleanPreviewsBackgroundJob(
1021
+                $c->getRootFolder(),
1022
+                $c->getLogger(),
1023
+                $c->getJobList(),
1024
+                new TimeFactory()
1025
+            );
1026
+        });
1027
+
1028
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1029
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1030
+
1031
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1032
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1033
+
1034
+        $this->registerService(Defaults::class, function (Server $c) {
1035
+            return new Defaults(
1036
+                $c->getThemingDefaults()
1037
+            );
1038
+        });
1039
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1040
+
1041
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1042
+            return $c->query(\OCP\IUserSession::class)->getSession();
1043
+        });
1044
+
1045
+        $this->registerService(IShareHelper::class, function(Server $c) {
1046
+            return new ShareHelper(
1047
+                $c->query(\OCP\Share\IManager::class)
1048
+            );
1049
+        });
1050
+    }
1051
+
1052
+    /**
1053
+     * @return \OCP\Contacts\IManager
1054
+     */
1055
+    public function getContactsManager() {
1056
+        return $this->query('ContactsManager');
1057
+    }
1058
+
1059
+    /**
1060
+     * @return \OC\Encryption\Manager
1061
+     */
1062
+    public function getEncryptionManager() {
1063
+        return $this->query('EncryptionManager');
1064
+    }
1065
+
1066
+    /**
1067
+     * @return \OC\Encryption\File
1068
+     */
1069
+    public function getEncryptionFilesHelper() {
1070
+        return $this->query('EncryptionFileHelper');
1071
+    }
1072
+
1073
+    /**
1074
+     * @return \OCP\Encryption\Keys\IStorage
1075
+     */
1076
+    public function getEncryptionKeyStorage() {
1077
+        return $this->query('EncryptionKeyStorage');
1078
+    }
1079
+
1080
+    /**
1081
+     * The current request object holding all information about the request
1082
+     * currently being processed is returned from this method.
1083
+     * In case the current execution was not initiated by a web request null is returned
1084
+     *
1085
+     * @return \OCP\IRequest
1086
+     */
1087
+    public function getRequest() {
1088
+        return $this->query('Request');
1089
+    }
1090
+
1091
+    /**
1092
+     * Returns the preview manager which can create preview images for a given file
1093
+     *
1094
+     * @return \OCP\IPreview
1095
+     */
1096
+    public function getPreviewManager() {
1097
+        return $this->query('PreviewManager');
1098
+    }
1099
+
1100
+    /**
1101
+     * Returns the tag manager which can get and set tags for different object types
1102
+     *
1103
+     * @see \OCP\ITagManager::load()
1104
+     * @return \OCP\ITagManager
1105
+     */
1106
+    public function getTagManager() {
1107
+        return $this->query('TagManager');
1108
+    }
1109
+
1110
+    /**
1111
+     * Returns the system-tag manager
1112
+     *
1113
+     * @return \OCP\SystemTag\ISystemTagManager
1114
+     *
1115
+     * @since 9.0.0
1116
+     */
1117
+    public function getSystemTagManager() {
1118
+        return $this->query('SystemTagManager');
1119
+    }
1120
+
1121
+    /**
1122
+     * Returns the system-tag object mapper
1123
+     *
1124
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1125
+     *
1126
+     * @since 9.0.0
1127
+     */
1128
+    public function getSystemTagObjectMapper() {
1129
+        return $this->query('SystemTagObjectMapper');
1130
+    }
1131
+
1132
+    /**
1133
+     * Returns the avatar manager, used for avatar functionality
1134
+     *
1135
+     * @return \OCP\IAvatarManager
1136
+     */
1137
+    public function getAvatarManager() {
1138
+        return $this->query('AvatarManager');
1139
+    }
1140
+
1141
+    /**
1142
+     * Returns the root folder of ownCloud's data directory
1143
+     *
1144
+     * @return \OCP\Files\IRootFolder
1145
+     */
1146
+    public function getRootFolder() {
1147
+        return $this->query('LazyRootFolder');
1148
+    }
1149
+
1150
+    /**
1151
+     * Returns the root folder of ownCloud's data directory
1152
+     * This is the lazy variant so this gets only initialized once it
1153
+     * is actually used.
1154
+     *
1155
+     * @return \OCP\Files\IRootFolder
1156
+     */
1157
+    public function getLazyRootFolder() {
1158
+        return $this->query('LazyRootFolder');
1159
+    }
1160
+
1161
+    /**
1162
+     * Returns a view to ownCloud's files folder
1163
+     *
1164
+     * @param string $userId user ID
1165
+     * @return \OCP\Files\Folder|null
1166
+     */
1167
+    public function getUserFolder($userId = null) {
1168
+        if ($userId === null) {
1169
+            $user = $this->getUserSession()->getUser();
1170
+            if (!$user) {
1171
+                return null;
1172
+            }
1173
+            $userId = $user->getUID();
1174
+        }
1175
+        $root = $this->getRootFolder();
1176
+        return $root->getUserFolder($userId);
1177
+    }
1178
+
1179
+    /**
1180
+     * Returns an app-specific view in ownClouds data directory
1181
+     *
1182
+     * @return \OCP\Files\Folder
1183
+     * @deprecated since 9.2.0 use IAppData
1184
+     */
1185
+    public function getAppFolder() {
1186
+        $dir = '/' . \OC_App::getCurrentApp();
1187
+        $root = $this->getRootFolder();
1188
+        if (!$root->nodeExists($dir)) {
1189
+            $folder = $root->newFolder($dir);
1190
+        } else {
1191
+            $folder = $root->get($dir);
1192
+        }
1193
+        return $folder;
1194
+    }
1195
+
1196
+    /**
1197
+     * @return \OC\User\Manager
1198
+     */
1199
+    public function getUserManager() {
1200
+        return $this->query('UserManager');
1201
+    }
1202
+
1203
+    /**
1204
+     * @return \OC\Group\Manager
1205
+     */
1206
+    public function getGroupManager() {
1207
+        return $this->query('GroupManager');
1208
+    }
1209
+
1210
+    /**
1211
+     * @return \OC\User\Session
1212
+     */
1213
+    public function getUserSession() {
1214
+        return $this->query('UserSession');
1215
+    }
1216
+
1217
+    /**
1218
+     * @return \OCP\ISession
1219
+     */
1220
+    public function getSession() {
1221
+        return $this->query('UserSession')->getSession();
1222
+    }
1223
+
1224
+    /**
1225
+     * @param \OCP\ISession $session
1226
+     */
1227
+    public function setSession(\OCP\ISession $session) {
1228
+        $this->query(SessionStorage::class)->setSession($session);
1229
+        $this->query('UserSession')->setSession($session);
1230
+        $this->query(Store::class)->setSession($session);
1231
+    }
1232
+
1233
+    /**
1234
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1235
+     */
1236
+    public function getTwoFactorAuthManager() {
1237
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1238
+    }
1239
+
1240
+    /**
1241
+     * @return \OC\NavigationManager
1242
+     */
1243
+    public function getNavigationManager() {
1244
+        return $this->query('NavigationManager');
1245
+    }
1246
+
1247
+    /**
1248
+     * @return \OCP\IConfig
1249
+     */
1250
+    public function getConfig() {
1251
+        return $this->query('AllConfig');
1252
+    }
1253
+
1254
+    /**
1255
+     * @internal For internal use only
1256
+     * @return \OC\SystemConfig
1257
+     */
1258
+    public function getSystemConfig() {
1259
+        return $this->query('SystemConfig');
1260
+    }
1261
+
1262
+    /**
1263
+     * Returns the app config manager
1264
+     *
1265
+     * @return \OCP\IAppConfig
1266
+     */
1267
+    public function getAppConfig() {
1268
+        return $this->query('AppConfig');
1269
+    }
1270
+
1271
+    /**
1272
+     * @return \OCP\L10N\IFactory
1273
+     */
1274
+    public function getL10NFactory() {
1275
+        return $this->query('L10NFactory');
1276
+    }
1277
+
1278
+    /**
1279
+     * get an L10N instance
1280
+     *
1281
+     * @param string $app appid
1282
+     * @param string $lang
1283
+     * @return IL10N
1284
+     */
1285
+    public function getL10N($app, $lang = null) {
1286
+        return $this->getL10NFactory()->get($app, $lang);
1287
+    }
1288
+
1289
+    /**
1290
+     * @return \OCP\IURLGenerator
1291
+     */
1292
+    public function getURLGenerator() {
1293
+        return $this->query('URLGenerator');
1294
+    }
1295
+
1296
+    /**
1297
+     * @return \OCP\IHelper
1298
+     */
1299
+    public function getHelper() {
1300
+        return $this->query('AppHelper');
1301
+    }
1302
+
1303
+    /**
1304
+     * @return AppFetcher
1305
+     */
1306
+    public function getAppFetcher() {
1307
+        return $this->query(AppFetcher::class);
1308
+    }
1309
+
1310
+    /**
1311
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1312
+     * getMemCacheFactory() instead.
1313
+     *
1314
+     * @return \OCP\ICache
1315
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1316
+     */
1317
+    public function getCache() {
1318
+        return $this->query('UserCache');
1319
+    }
1320
+
1321
+    /**
1322
+     * Returns an \OCP\CacheFactory instance
1323
+     *
1324
+     * @return \OCP\ICacheFactory
1325
+     */
1326
+    public function getMemCacheFactory() {
1327
+        return $this->query('MemCacheFactory');
1328
+    }
1329
+
1330
+    /**
1331
+     * Returns an \OC\RedisFactory instance
1332
+     *
1333
+     * @return \OC\RedisFactory
1334
+     */
1335
+    public function getGetRedisFactory() {
1336
+        return $this->query('RedisFactory');
1337
+    }
1338
+
1339
+
1340
+    /**
1341
+     * Returns the current session
1342
+     *
1343
+     * @return \OCP\IDBConnection
1344
+     */
1345
+    public function getDatabaseConnection() {
1346
+        return $this->query('DatabaseConnection');
1347
+    }
1348
+
1349
+    /**
1350
+     * Returns the activity manager
1351
+     *
1352
+     * @return \OCP\Activity\IManager
1353
+     */
1354
+    public function getActivityManager() {
1355
+        return $this->query('ActivityManager');
1356
+    }
1357
+
1358
+    /**
1359
+     * Returns an job list for controlling background jobs
1360
+     *
1361
+     * @return \OCP\BackgroundJob\IJobList
1362
+     */
1363
+    public function getJobList() {
1364
+        return $this->query('JobList');
1365
+    }
1366
+
1367
+    /**
1368
+     * Returns a logger instance
1369
+     *
1370
+     * @return \OCP\ILogger
1371
+     */
1372
+    public function getLogger() {
1373
+        return $this->query('Logger');
1374
+    }
1375
+
1376
+    /**
1377
+     * Returns a router for generating and matching urls
1378
+     *
1379
+     * @return \OCP\Route\IRouter
1380
+     */
1381
+    public function getRouter() {
1382
+        return $this->query('Router');
1383
+    }
1384
+
1385
+    /**
1386
+     * Returns a search instance
1387
+     *
1388
+     * @return \OCP\ISearch
1389
+     */
1390
+    public function getSearch() {
1391
+        return $this->query('Search');
1392
+    }
1393
+
1394
+    /**
1395
+     * Returns a SecureRandom instance
1396
+     *
1397
+     * @return \OCP\Security\ISecureRandom
1398
+     */
1399
+    public function getSecureRandom() {
1400
+        return $this->query('SecureRandom');
1401
+    }
1402
+
1403
+    /**
1404
+     * Returns a Crypto instance
1405
+     *
1406
+     * @return \OCP\Security\ICrypto
1407
+     */
1408
+    public function getCrypto() {
1409
+        return $this->query('Crypto');
1410
+    }
1411
+
1412
+    /**
1413
+     * Returns a Hasher instance
1414
+     *
1415
+     * @return \OCP\Security\IHasher
1416
+     */
1417
+    public function getHasher() {
1418
+        return $this->query('Hasher');
1419
+    }
1420
+
1421
+    /**
1422
+     * Returns a CredentialsManager instance
1423
+     *
1424
+     * @return \OCP\Security\ICredentialsManager
1425
+     */
1426
+    public function getCredentialsManager() {
1427
+        return $this->query('CredentialsManager');
1428
+    }
1429
+
1430
+    /**
1431
+     * Returns an instance of the HTTP helper class
1432
+     *
1433
+     * @deprecated Use getHTTPClientService()
1434
+     * @return \OC\HTTPHelper
1435
+     */
1436
+    public function getHTTPHelper() {
1437
+        return $this->query('HTTPHelper');
1438
+    }
1439
+
1440
+    /**
1441
+     * Get the certificate manager for the user
1442
+     *
1443
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1444
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1445
+     */
1446
+    public function getCertificateManager($userId = '') {
1447
+        if ($userId === '') {
1448
+            $userSession = $this->getUserSession();
1449
+            $user = $userSession->getUser();
1450
+            if (is_null($user)) {
1451
+                return null;
1452
+            }
1453
+            $userId = $user->getUID();
1454
+        }
1455
+        return new CertificateManager(
1456
+            $userId,
1457
+            new View(),
1458
+            $this->getConfig(),
1459
+            $this->getLogger(),
1460
+            $this->getSecureRandom()
1461
+        );
1462
+    }
1463
+
1464
+    /**
1465
+     * Returns an instance of the HTTP client service
1466
+     *
1467
+     * @return \OCP\Http\Client\IClientService
1468
+     */
1469
+    public function getHTTPClientService() {
1470
+        return $this->query('HttpClientService');
1471
+    }
1472
+
1473
+    /**
1474
+     * Create a new event source
1475
+     *
1476
+     * @return \OCP\IEventSource
1477
+     */
1478
+    public function createEventSource() {
1479
+        return new \OC_EventSource();
1480
+    }
1481
+
1482
+    /**
1483
+     * Get the active event logger
1484
+     *
1485
+     * The returned logger only logs data when debug mode is enabled
1486
+     *
1487
+     * @return \OCP\Diagnostics\IEventLogger
1488
+     */
1489
+    public function getEventLogger() {
1490
+        return $this->query('EventLogger');
1491
+    }
1492
+
1493
+    /**
1494
+     * Get the active query logger
1495
+     *
1496
+     * The returned logger only logs data when debug mode is enabled
1497
+     *
1498
+     * @return \OCP\Diagnostics\IQueryLogger
1499
+     */
1500
+    public function getQueryLogger() {
1501
+        return $this->query('QueryLogger');
1502
+    }
1503
+
1504
+    /**
1505
+     * Get the manager for temporary files and folders
1506
+     *
1507
+     * @return \OCP\ITempManager
1508
+     */
1509
+    public function getTempManager() {
1510
+        return $this->query('TempManager');
1511
+    }
1512
+
1513
+    /**
1514
+     * Get the app manager
1515
+     *
1516
+     * @return \OCP\App\IAppManager
1517
+     */
1518
+    public function getAppManager() {
1519
+        return $this->query('AppManager');
1520
+    }
1521
+
1522
+    /**
1523
+     * Creates a new mailer
1524
+     *
1525
+     * @return \OCP\Mail\IMailer
1526
+     */
1527
+    public function getMailer() {
1528
+        return $this->query('Mailer');
1529
+    }
1530
+
1531
+    /**
1532
+     * Get the webroot
1533
+     *
1534
+     * @return string
1535
+     */
1536
+    public function getWebRoot() {
1537
+        return $this->webRoot;
1538
+    }
1539
+
1540
+    /**
1541
+     * @return \OC\OCSClient
1542
+     */
1543
+    public function getOcsClient() {
1544
+        return $this->query('OcsClient');
1545
+    }
1546
+
1547
+    /**
1548
+     * @return \OCP\IDateTimeZone
1549
+     */
1550
+    public function getDateTimeZone() {
1551
+        return $this->query('DateTimeZone');
1552
+    }
1553
+
1554
+    /**
1555
+     * @return \OCP\IDateTimeFormatter
1556
+     */
1557
+    public function getDateTimeFormatter() {
1558
+        return $this->query('DateTimeFormatter');
1559
+    }
1560
+
1561
+    /**
1562
+     * @return \OCP\Files\Config\IMountProviderCollection
1563
+     */
1564
+    public function getMountProviderCollection() {
1565
+        return $this->query('MountConfigManager');
1566
+    }
1567
+
1568
+    /**
1569
+     * Get the IniWrapper
1570
+     *
1571
+     * @return IniGetWrapper
1572
+     */
1573
+    public function getIniWrapper() {
1574
+        return $this->query('IniWrapper');
1575
+    }
1576
+
1577
+    /**
1578
+     * @return \OCP\Command\IBus
1579
+     */
1580
+    public function getCommandBus() {
1581
+        return $this->query('AsyncCommandBus');
1582
+    }
1583
+
1584
+    /**
1585
+     * Get the trusted domain helper
1586
+     *
1587
+     * @return TrustedDomainHelper
1588
+     */
1589
+    public function getTrustedDomainHelper() {
1590
+        return $this->query('TrustedDomainHelper');
1591
+    }
1592
+
1593
+    /**
1594
+     * Get the locking provider
1595
+     *
1596
+     * @return \OCP\Lock\ILockingProvider
1597
+     * @since 8.1.0
1598
+     */
1599
+    public function getLockingProvider() {
1600
+        return $this->query('LockingProvider');
1601
+    }
1602
+
1603
+    /**
1604
+     * @return \OCP\Files\Mount\IMountManager
1605
+     **/
1606
+    function getMountManager() {
1607
+        return $this->query('MountManager');
1608
+    }
1609
+
1610
+    /** @return \OCP\Files\Config\IUserMountCache */
1611
+    function getUserMountCache() {
1612
+        return $this->query('UserMountCache');
1613
+    }
1614
+
1615
+    /**
1616
+     * Get the MimeTypeDetector
1617
+     *
1618
+     * @return \OCP\Files\IMimeTypeDetector
1619
+     */
1620
+    public function getMimeTypeDetector() {
1621
+        return $this->query('MimeTypeDetector');
1622
+    }
1623
+
1624
+    /**
1625
+     * Get the MimeTypeLoader
1626
+     *
1627
+     * @return \OCP\Files\IMimeTypeLoader
1628
+     */
1629
+    public function getMimeTypeLoader() {
1630
+        return $this->query('MimeTypeLoader');
1631
+    }
1632
+
1633
+    /**
1634
+     * Get the manager of all the capabilities
1635
+     *
1636
+     * @return \OC\CapabilitiesManager
1637
+     */
1638
+    public function getCapabilitiesManager() {
1639
+        return $this->query('CapabilitiesManager');
1640
+    }
1641
+
1642
+    /**
1643
+     * Get the EventDispatcher
1644
+     *
1645
+     * @return EventDispatcherInterface
1646
+     * @since 8.2.0
1647
+     */
1648
+    public function getEventDispatcher() {
1649
+        return $this->query('EventDispatcher');
1650
+    }
1651
+
1652
+    /**
1653
+     * Get the Notification Manager
1654
+     *
1655
+     * @return \OCP\Notification\IManager
1656
+     * @since 8.2.0
1657
+     */
1658
+    public function getNotificationManager() {
1659
+        return $this->query('NotificationManager');
1660
+    }
1661
+
1662
+    /**
1663
+     * @return \OCP\Comments\ICommentsManager
1664
+     */
1665
+    public function getCommentsManager() {
1666
+        return $this->query('CommentsManager');
1667
+    }
1668
+
1669
+    /**
1670
+     * @return \OCA\Theming\ThemingDefaults
1671
+     */
1672
+    public function getThemingDefaults() {
1673
+        return $this->query('ThemingDefaults');
1674
+    }
1675
+
1676
+    /**
1677
+     * @return \OC\IntegrityCheck\Checker
1678
+     */
1679
+    public function getIntegrityCodeChecker() {
1680
+        return $this->query('IntegrityCodeChecker');
1681
+    }
1682
+
1683
+    /**
1684
+     * @return \OC\Session\CryptoWrapper
1685
+     */
1686
+    public function getSessionCryptoWrapper() {
1687
+        return $this->query('CryptoWrapper');
1688
+    }
1689
+
1690
+    /**
1691
+     * @return CsrfTokenManager
1692
+     */
1693
+    public function getCsrfTokenManager() {
1694
+        return $this->query('CsrfTokenManager');
1695
+    }
1696
+
1697
+    /**
1698
+     * @return Throttler
1699
+     */
1700
+    public function getBruteForceThrottler() {
1701
+        return $this->query('Throttler');
1702
+    }
1703
+
1704
+    /**
1705
+     * @return IContentSecurityPolicyManager
1706
+     */
1707
+    public function getContentSecurityPolicyManager() {
1708
+        return $this->query('ContentSecurityPolicyManager');
1709
+    }
1710
+
1711
+    /**
1712
+     * @return ContentSecurityPolicyNonceManager
1713
+     */
1714
+    public function getContentSecurityPolicyNonceManager() {
1715
+        return $this->query('ContentSecurityPolicyNonceManager');
1716
+    }
1717
+
1718
+    /**
1719
+     * Not a public API as of 8.2, wait for 9.0
1720
+     *
1721
+     * @return \OCA\Files_External\Service\BackendService
1722
+     */
1723
+    public function getStoragesBackendService() {
1724
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1725
+    }
1726
+
1727
+    /**
1728
+     * Not a public API as of 8.2, wait for 9.0
1729
+     *
1730
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1731
+     */
1732
+    public function getGlobalStoragesService() {
1733
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1734
+    }
1735
+
1736
+    /**
1737
+     * Not a public API as of 8.2, wait for 9.0
1738
+     *
1739
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1740
+     */
1741
+    public function getUserGlobalStoragesService() {
1742
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1743
+    }
1744
+
1745
+    /**
1746
+     * Not a public API as of 8.2, wait for 9.0
1747
+     *
1748
+     * @return \OCA\Files_External\Service\UserStoragesService
1749
+     */
1750
+    public function getUserStoragesService() {
1751
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1752
+    }
1753
+
1754
+    /**
1755
+     * @return \OCP\Share\IManager
1756
+     */
1757
+    public function getShareManager() {
1758
+        return $this->query('ShareManager');
1759
+    }
1760
+
1761
+    /**
1762
+     * Returns the LDAP Provider
1763
+     *
1764
+     * @return \OCP\LDAP\ILDAPProvider
1765
+     */
1766
+    public function getLDAPProvider() {
1767
+        return $this->query('LDAPProvider');
1768
+    }
1769
+
1770
+    /**
1771
+     * @return \OCP\Settings\IManager
1772
+     */
1773
+    public function getSettingsManager() {
1774
+        return $this->query('SettingsManager');
1775
+    }
1776
+
1777
+    /**
1778
+     * @return \OCP\Files\IAppData
1779
+     */
1780
+    public function getAppDataDir($app) {
1781
+        /** @var \OC\Files\AppData\Factory $factory */
1782
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1783
+        return $factory->get($app);
1784
+    }
1785
+
1786
+    /**
1787
+     * @return \OCP\Lockdown\ILockdownManager
1788
+     */
1789
+    public function getLockdownManager() {
1790
+        return $this->query('LockdownManager');
1791
+    }
1792
+
1793
+    /**
1794
+     * @return \OCP\Federation\ICloudIdManager
1795
+     */
1796
+    public function getCloudIdManager() {
1797
+        return $this->query(ICloudIdManager::class);
1798
+    }
1799 1799
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/RemoteShare.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
27 27
 
28 28
 class RemoteShare implements ISetting {
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 */
36
-	public function __construct(IL10N $l) {
37
-		$this->l = $l;
38
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     */
36
+    public function __construct(IL10N $l) {
37
+        $this->l = $l;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string Lowercase a-z and underscore only identifier
42
-	 * @since 11.0.0
43
-	 */
44
-	public function getIdentifier() {
45
-		return 'remote_share';
46
-	}
40
+    /**
41
+     * @return string Lowercase a-z and underscore only identifier
42
+     * @since 11.0.0
43
+     */
44
+    public function getIdentifier() {
45
+        return 'remote_share';
46
+    }
47 47
 
48
-	/**
49
-	 * @return string A translated string
50
-	 * @since 11.0.0
51
-	 */
52
-	public function getName() {
53
-		return $this->l->t('A file or folder was shared from <strong>another server</strong>');
54
-	}
48
+    /**
49
+     * @return string A translated string
50
+     * @since 11.0.0
51
+     */
52
+    public function getName() {
53
+        return $this->l->t('A file or folder was shared from <strong>another server</strong>');
54
+    }
55 55
 
56
-	/**
57
-	 * @return int whether the filter should be rather on the top or bottom of
58
-	 * the admin section. The filters are arranged in ascending order of the
59
-	 * priority values. It is required to return a value between 0 and 100.
60
-	 * @since 11.0.0
61
-	 */
62
-	public function getPriority() {
63
-		return 11;
64
-	}
56
+    /**
57
+     * @return int whether the filter should be rather on the top or bottom of
58
+     * the admin section. The filters are arranged in ascending order of the
59
+     * priority values. It is required to return a value between 0 and 100.
60
+     * @since 11.0.0
61
+     */
62
+    public function getPriority() {
63
+        return 11;
64
+    }
65 65
 
66
-	/**
67
-	 * @return bool True when the option can be changed for the stream
68
-	 * @since 11.0.0
69
-	 */
70
-	public function canChangeStream() {
71
-		return true;
72
-	}
66
+    /**
67
+     * @return bool True when the option can be changed for the stream
68
+     * @since 11.0.0
69
+     */
70
+    public function canChangeStream() {
71
+        return true;
72
+    }
73 73
 
74
-	/**
75
-	 * @return bool True when the option can be changed for the stream
76
-	 * @since 11.0.0
77
-	 */
78
-	public function isDefaultEnabledStream() {
79
-		return true;
80
-	}
74
+    /**
75
+     * @return bool True when the option can be changed for the stream
76
+     * @since 11.0.0
77
+     */
78
+    public function isDefaultEnabledStream() {
79
+        return true;
80
+    }
81 81
 
82
-	/**
83
-	 * @return bool True when the option can be changed for the mail
84
-	 * @since 11.0.0
85
-	 */
86
-	public function canChangeMail() {
87
-		return true;
88
-	}
82
+    /**
83
+     * @return bool True when the option can be changed for the mail
84
+     * @since 11.0.0
85
+     */
86
+    public function canChangeMail() {
87
+        return true;
88
+    }
89 89
 
90
-	/**
91
-	 * @return bool True when the option can be changed for the stream
92
-	 * @since 11.0.0
93
-	 */
94
-	public function isDefaultEnabledMail() {
95
-		return false;
96
-	}
90
+    /**
91
+     * @return bool True when the option can be changed for the stream
92
+     * @since 11.0.0
93
+     */
94
+    public function isDefaultEnabledMail() {
95
+        return false;
96
+    }
97 97
 }
98 98
 
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/Shared.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
27 27
 
28 28
 class Shared implements ISetting {
29 29
 
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 */
36
-	public function __construct(IL10N $l) {
37
-		$this->l = $l;
38
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     */
36
+    public function __construct(IL10N $l) {
37
+        $this->l = $l;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string Lowercase a-z and underscore only identifier
42
-	 * @since 11.0.0
43
-	 */
44
-	public function getIdentifier() {
45
-		return 'shared';
46
-	}
40
+    /**
41
+     * @return string Lowercase a-z and underscore only identifier
42
+     * @since 11.0.0
43
+     */
44
+    public function getIdentifier() {
45
+        return 'shared';
46
+    }
47 47
 
48
-	/**
49
-	 * @return string A translated string
50
-	 * @since 11.0.0
51
-	 */
52
-	public function getName() {
53
-		return $this->l->t('A file or folder has been <strong>shared</strong>');
54
-	}
48
+    /**
49
+     * @return string A translated string
50
+     * @since 11.0.0
51
+     */
52
+    public function getName() {
53
+        return $this->l->t('A file or folder has been <strong>shared</strong>');
54
+    }
55 55
 
56
-	/**
57
-	 * @return int whether the filter should be rather on the top or bottom of
58
-	 * the admin section. The filters are arranged in ascending order of the
59
-	 * priority values. It is required to return a value between 0 and 100.
60
-	 * @since 11.0.0
61
-	 */
62
-	public function getPriority() {
63
-		return 10;
64
-	}
56
+    /**
57
+     * @return int whether the filter should be rather on the top or bottom of
58
+     * the admin section. The filters are arranged in ascending order of the
59
+     * priority values. It is required to return a value between 0 and 100.
60
+     * @since 11.0.0
61
+     */
62
+    public function getPriority() {
63
+        return 10;
64
+    }
65 65
 
66
-	/**
67
-	 * @return bool True when the option can be changed for the stream
68
-	 * @since 11.0.0
69
-	 */
70
-	public function canChangeStream() {
71
-		return true;
72
-	}
66
+    /**
67
+     * @return bool True when the option can be changed for the stream
68
+     * @since 11.0.0
69
+     */
70
+    public function canChangeStream() {
71
+        return true;
72
+    }
73 73
 
74
-	/**
75
-	 * @return bool True when the option can be changed for the stream
76
-	 * @since 11.0.0
77
-	 */
78
-	public function isDefaultEnabledStream() {
79
-		return true;
80
-	}
74
+    /**
75
+     * @return bool True when the option can be changed for the stream
76
+     * @since 11.0.0
77
+     */
78
+    public function isDefaultEnabledStream() {
79
+        return true;
80
+    }
81 81
 
82
-	/**
83
-	 * @return bool True when the option can be changed for the mail
84
-	 * @since 11.0.0
85
-	 */
86
-	public function canChangeMail() {
87
-		return true;
88
-	}
82
+    /**
83
+     * @return bool True when the option can be changed for the mail
84
+     * @since 11.0.0
85
+     */
86
+    public function canChangeMail() {
87
+        return true;
88
+    }
89 89
 
90
-	/**
91
-	 * @return bool True when the option can be changed for the stream
92
-	 * @since 11.0.0
93
-	 */
94
-	public function isDefaultEnabledMail() {
95
-		return false;
96
-	}
90
+    /**
91
+     * @return bool True when the option can be changed for the stream
92
+     * @since 11.0.0
93
+     */
94
+    public function isDefaultEnabledMail() {
95
+        return false;
96
+    }
97 97
 }
98 98
 
Please login to merge, or discard this patch.