Completed
Pull Request — master (#4303)
by Björn
23:11 queued 10:06
created
apps/sharebymail/lib/ShareByMailProvider.php 3 patches
Doc Comments   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	 * publish activity if a file/folder was shared by mail
238 238
 	 *
239 239
 	 * @param $subject
240
-	 * @param $parameters
241
-	 * @param $affectedUser
240
+	 * @param string[] $parameters
241
+	 * @param string $affectedUser
242 242
 	 * @param $fileId
243
-	 * @param $filePath
243
+	 * @param string $filePath
244 244
 	 */
245 245
 	protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246 246
 		$event = $this->activityManager->generateEvent();
@@ -293,6 +293,12 @@  discard block
 block discarded – undo
293 293
 
294 294
 	}
295 295
 
296
+	/**
297
+	 * @param string $link
298
+	 * @param string $owner
299
+	 * @param string $initiator
300
+	 * @param string $shareWith
301
+	 */
296 302
 	protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297 303
 		$ownerUser = $this->userManager->get($owner);
298 304
 		$initiatorUser = $this->userManager->get($initiator);
@@ -326,6 +332,7 @@  discard block
 block discarded – undo
326 332
 	 * @param $link
327 333
 	 * @param $owner
328 334
 	 * @param $initiator
335
+	 * @param string $template
329 336
 	 * @return string plain text mail
330 337
 	 * @throws HintException
331 338
 	 */
@@ -497,6 +504,7 @@  discard block
 block discarded – undo
497 504
 	 * @param string $uidOwner
498 505
 	 * @param int $permissions
499 506
 	 * @param string $token
507
+	 * @param string $password
500 508
 	 * @return int
501 509
 	 */
502 510
 	protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
@@ -890,7 +898,7 @@  discard block
 block discarded – undo
890 898
 	/**
891 899
 	 * get database row of a give share
892 900
 	 *
893
-	 * @param $id
901
+	 * @param integer $id
894 902
 	 * @return array
895 903
 	 * @throws ShareNotFound
896 904
 	 */
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
 				$share->getShareOwner(),
280 280
 				$share->getSharedBy(), $share->getSharedWith());
281 281
 		} catch (HintException $hintException) {
282
-			$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
282
+			$this->logger->error('Failed to send share by mail: '.$hintException->getMessage());
283 283
 			$this->removeShareFromTable($shareId);
284 284
 			throw $hintException;
285 285
 		} catch (\Exception $e) {
286
-			$this->logger->error('Failed to send share by mail: ' . $e->getMessage());
286
+			$this->logger->error('Failed to send share by mail: '.$e->getMessage());
287 287
 			$this->removeShareFromTable($shareId);
288 288
 			throw new HintException('Failed to send share by mail',
289 289
 				$this->l->t('Failed to send share by E-mail'));
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301 301
 		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302 302
 		if ($owner === $initiator) {
303
-			$subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
303
+			$subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304 304
 		} else {
305
-			$subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
305
+			$subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306 306
 		}
307 307
 
308 308
 		$message = $this->mailer->createMessage();
@@ -332,11 +332,11 @@  discard block
 block discarded – undo
332 332
 	protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333 333
 
334 334
 		$mailBodyTemplate = new Template('sharebymail', $template, '');
335
-		$mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
-		$mailBodyTemplate->assign ('link', $link);
337
-		$mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
-		$mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
-		$mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
335
+		$mailBodyTemplate->assign('filename', \OCP\Util::sanitizeHTML($filename));
336
+		$mailBodyTemplate->assign('link', $link);
337
+		$mailBodyTemplate->assign('owner', \OCP\Util::sanitizeHTML($owner));
338
+		$mailBodyTemplate->assign('initiator', \OCP\Util::sanitizeHTML($initiator));
339
+		$mailBodyTemplate->assign('onBehalfOf', $initiator !== $owner);
340 340
 		$mailBody = $mailBodyTemplate->fetchPage();
341 341
 
342 342
 		if (is_string($mailBody)) {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		$initiatorUser = $this->userManager->get($initiator);
366 366
 		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367 367
 		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
-		$subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
368
+		$subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369 369
 
370 370
 		$message = $this->mailer->createMessage();
371 371
 		$arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 			);
406 406
 		}
407 407
 
408
-		$subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
408
+		$subject = (string) $this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
409 409
 
410 410
 		$message = $this->mailer->createMessage();
411 411
 		$arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 		$mailBodyTemplate = new Template('sharebymail', $template, '');
437 437
 
438 438
 		foreach ($arguments as $key => $value) {
439
-			$mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
439
+			$mailBodyTemplate->assign($key, \OCP\Util::sanitizeHTML($value));
440 440
 		}
441 441
 
442 442
 		$mailBody = $mailBodyTemplate->fetchPage();
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 */
458 458
 	protected function generateToken($size = 15) {
459 459
 		$token = $this->secureRandom->generate(
460
-			$size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
460
+			$size, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS);
461 461
 		return $token;
462 462
 	}
463 463
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 			->orderBy('id');
479 479
 
480 480
 		$cursor = $qb->execute();
481
-		while($data = $cursor->fetch()) {
481
+		while ($data = $cursor->fetch()) {
482 482
 			$children[] = $this->createShareObject($data);
483 483
 		}
484 484
 		$cursor->closeCursor();
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$qb->execute();
523 523
 		$id = $qb->getLastInsertId();
524 524
 
525
-		return (int)$id;
525
+		return (int) $id;
526 526
 	}
527 527
 
528 528
 	/**
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		// a real password was given
540 540
 		$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
541 541
 
542
-		if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
542
+		if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
543 543
 			$this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
544 544
 		}
545 545
 		/*
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 
634 634
 		$cursor = $qb->execute();
635 635
 		$shares = [];
636
-		while($data = $cursor->fetch()) {
636
+		while ($data = $cursor->fetch()) {
637 637
 			$shares[] = $this->createShareObject($data);
638 638
 		}
639 639
 		$cursor->closeCursor();
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 			->execute();
686 686
 
687 687
 		$shares = [];
688
-		while($data = $cursor->fetch()) {
688
+		while ($data = $cursor->fetch()) {
689 689
 			$shares[] = $this->createShareObject($data);
690 690
 		}
691 691
 		$cursor->closeCursor();
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
 
725 725
 		$cursor = $qb->execute();
726 726
 
727
-		while($data = $cursor->fetch()) {
727
+		while ($data = $cursor->fetch()) {
728 728
 			$shares[] = $this->createShareObject($data);
729 729
 		}
730 730
 		$cursor->closeCursor();
@@ -787,15 +787,15 @@  discard block
 block discarded – undo
787 787
 	protected function createShareObject($data) {
788 788
 
789 789
 		$share = new Share($this->rootFolder, $this->userManager);
790
-		$share->setId((int)$data['id'])
791
-			->setShareType((int)$data['share_type'])
792
-			->setPermissions((int)$data['permissions'])
790
+		$share->setId((int) $data['id'])
791
+			->setShareType((int) $data['share_type'])
792
+			->setPermissions((int) $data['permissions'])
793 793
 			->setTarget($data['file_target'])
794
-			->setMailSend((bool)$data['mail_send'])
794
+			->setMailSend((bool) $data['mail_send'])
795 795
 			->setToken($data['token']);
796 796
 
797 797
 		$shareTime = new \DateTime();
798
-		$shareTime->setTimestamp((int)$data['stime']);
798
+		$shareTime->setTimestamp((int) $data['stime']);
799 799
 		$share->setShareTime($shareTime);
800 800
 		$share->setSharedWith($data['share_with']);
801 801
 		$share->setPassword($data['password']);
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 		} else {
807 807
 			//OLD SHARE
808 808
 			$share->setSharedBy($data['uid_owner']);
809
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
809
+			$path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
810 810
 
811 811
 			$owner = $path->getOwner();
812 812
 			$share->setShareOwner($owner->getUID());
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 			}
820 820
 		}
821 821
 
822
-		$share->setNodeId((int)$data['file_source']);
822
+		$share->setNodeId((int) $data['file_source']);
823 823
 		$share->setNodeType($data['item_type']);
824 824
 
825 825
 		$share->setProviderId($this->identifier());
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
 			);
939 939
 		}
940 940
 
941
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
941
+		$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
942 942
 		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
943 943
 
944 944
 		$qb->orderBy('id');
Please login to merge, or discard this patch.
Indentation   +887 added lines, -887 removed lines patch added patch discarded remove patch
@@ -51,905 +51,905 @@
 block discarded – undo
51 51
  */
52 52
 class ShareByMailProvider implements IShareProvider {
53 53
 
54
-	/** @var  IDBConnection */
55
-	private $dbConnection;
56
-
57
-	/** @var ILogger */
58
-	private $logger;
59
-
60
-	/** @var ISecureRandom */
61
-	private $secureRandom;
62
-
63
-	/** @var IUserManager */
64
-	private $userManager;
65
-
66
-	/** @var IRootFolder */
67
-	private $rootFolder;
68
-
69
-	/** @var IL10N */
70
-	private $l;
71
-
72
-	/** @var IMailer */
73
-	private $mailer;
74
-
75
-	/** @var IURLGenerator */
76
-	private $urlGenerator;
77
-
78
-	/** @var IManager  */
79
-	private $activityManager;
80
-
81
-	/** @var SettingsManager */
82
-	private $settingsManager;
83
-
84
-	/** @var IHasher */
85
-	private $hasher;
86
-
87
-	/**
88
-	 * Return the identifier of this provider.
89
-	 *
90
-	 * @return string Containing only [a-zA-Z0-9]
91
-	 */
92
-	public function identifier() {
93
-		return 'ocMailShare';
94
-	}
95
-
96
-	/**
97
-	 * DefaultShareProvider constructor.
98
-	 *
99
-	 * @param IDBConnection $connection
100
-	 * @param ISecureRandom $secureRandom
101
-	 * @param IUserManager $userManager
102
-	 * @param IRootFolder $rootFolder
103
-	 * @param IL10N $l
104
-	 * @param ILogger $logger
105
-	 * @param IMailer $mailer
106
-	 * @param IURLGenerator $urlGenerator
107
-	 * @param IManager $activityManager
108
-	 * @param SettingsManager $settingsManager
109
-	 * @param IHasher $hasher
110
-	 */
111
-	public function __construct(
112
-		IDBConnection $connection,
113
-		ISecureRandom $secureRandom,
114
-		IUserManager $userManager,
115
-		IRootFolder $rootFolder,
116
-		IL10N $l,
117
-		ILogger $logger,
118
-		IMailer $mailer,
119
-		IURLGenerator $urlGenerator,
120
-		IManager $activityManager,
121
-		SettingsManager $settingsManager,
122
-		IHasher $hasher
123
-	) {
124
-		$this->dbConnection = $connection;
125
-		$this->secureRandom = $secureRandom;
126
-		$this->userManager = $userManager;
127
-		$this->rootFolder = $rootFolder;
128
-		$this->l = $l;
129
-		$this->logger = $logger;
130
-		$this->mailer = $mailer;
131
-		$this->urlGenerator = $urlGenerator;
132
-		$this->activityManager = $activityManager;
133
-		$this->settingsManager = $settingsManager;
134
-		$this->hasher = $hasher;
135
-	}
136
-
137
-	/**
138
-	 * Share a path
139
-	 *
140
-	 * @param IShare $share
141
-	 * @return IShare The share object
142
-	 * @throws ShareNotFound
143
-	 * @throws \Exception
144
-	 */
145
-	public function create(IShare $share) {
146
-
147
-		$shareWith = $share->getSharedWith();
148
-		/*
54
+    /** @var  IDBConnection */
55
+    private $dbConnection;
56
+
57
+    /** @var ILogger */
58
+    private $logger;
59
+
60
+    /** @var ISecureRandom */
61
+    private $secureRandom;
62
+
63
+    /** @var IUserManager */
64
+    private $userManager;
65
+
66
+    /** @var IRootFolder */
67
+    private $rootFolder;
68
+
69
+    /** @var IL10N */
70
+    private $l;
71
+
72
+    /** @var IMailer */
73
+    private $mailer;
74
+
75
+    /** @var IURLGenerator */
76
+    private $urlGenerator;
77
+
78
+    /** @var IManager  */
79
+    private $activityManager;
80
+
81
+    /** @var SettingsManager */
82
+    private $settingsManager;
83
+
84
+    /** @var IHasher */
85
+    private $hasher;
86
+
87
+    /**
88
+     * Return the identifier of this provider.
89
+     *
90
+     * @return string Containing only [a-zA-Z0-9]
91
+     */
92
+    public function identifier() {
93
+        return 'ocMailShare';
94
+    }
95
+
96
+    /**
97
+     * DefaultShareProvider constructor.
98
+     *
99
+     * @param IDBConnection $connection
100
+     * @param ISecureRandom $secureRandom
101
+     * @param IUserManager $userManager
102
+     * @param IRootFolder $rootFolder
103
+     * @param IL10N $l
104
+     * @param ILogger $logger
105
+     * @param IMailer $mailer
106
+     * @param IURLGenerator $urlGenerator
107
+     * @param IManager $activityManager
108
+     * @param SettingsManager $settingsManager
109
+     * @param IHasher $hasher
110
+     */
111
+    public function __construct(
112
+        IDBConnection $connection,
113
+        ISecureRandom $secureRandom,
114
+        IUserManager $userManager,
115
+        IRootFolder $rootFolder,
116
+        IL10N $l,
117
+        ILogger $logger,
118
+        IMailer $mailer,
119
+        IURLGenerator $urlGenerator,
120
+        IManager $activityManager,
121
+        SettingsManager $settingsManager,
122
+        IHasher $hasher
123
+    ) {
124
+        $this->dbConnection = $connection;
125
+        $this->secureRandom = $secureRandom;
126
+        $this->userManager = $userManager;
127
+        $this->rootFolder = $rootFolder;
128
+        $this->l = $l;
129
+        $this->logger = $logger;
130
+        $this->mailer = $mailer;
131
+        $this->urlGenerator = $urlGenerator;
132
+        $this->activityManager = $activityManager;
133
+        $this->settingsManager = $settingsManager;
134
+        $this->hasher = $hasher;
135
+    }
136
+
137
+    /**
138
+     * Share a path
139
+     *
140
+     * @param IShare $share
141
+     * @return IShare The share object
142
+     * @throws ShareNotFound
143
+     * @throws \Exception
144
+     */
145
+    public function create(IShare $share) {
146
+
147
+        $shareWith = $share->getSharedWith();
148
+        /*
149 149
 		 * Check if file is not already shared with the remote user
150 150
 		 */
151
-		$alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
152
-		if (!empty($alreadyShared)) {
153
-			$message = 'Sharing %s failed, this item is already shared with %s';
154
-			$message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
155
-			$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
156
-			throw new \Exception($message_t);
157
-		}
158
-
159
-		// if the admin enforces a password for all mail shares we create a
160
-		// random password and send it to the recipient
161
-		$password = '';
162
-		$passwordEnforced = $this->settingsManager->enforcePasswordProtection();
163
-		if ($passwordEnforced) {
164
-			$password = $this->autoGeneratePassword($share);
165
-		}
166
-
167
-		$shareId = $this->createMailShare($share);
168
-		$send = $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $password);
169
-		if ($passwordEnforced && $send === false) {
170
-			$this->sendPasswordToOwner($share->getNode()->getName(), $share->getSharedBy(), $shareWith, $password);
171
-		}
172
-		$this->createActivity($share);
173
-		$data = $this->getRawShare($shareId);
174
-
175
-		return $this->createShareObject($data);
176
-
177
-	}
178
-
179
-	/**
180
-	 * auto generate password in case of password enforcement on mail shares
181
-	 *
182
-	 * @param IShare $share
183
-	 * @return string
184
-	 * @throws \Exception
185
-	 */
186
-	protected function autoGeneratePassword($share) {
187
-		$initiatorUser = $this->userManager->get($share->getSharedBy());
188
-		$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
189
-		$allowPasswordByMail = $this->settingsManager->sendPasswordByMail();
190
-
191
-		if ($initiatorEMailAddress === null && !$allowPasswordByMail) {
192
-			throw new \Exception(
193
-				$this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
194
-			);
195
-		}
196
-
197
-		$password = $this->generateToken(8);
198
-		$share->setPassword($this->hasher->hash($password));
199
-
200
-		return $password;
201
-	}
202
-
203
-	/**
204
-	 * create activity if a file/folder was shared by mail
205
-	 *
206
-	 * @param IShare $share
207
-	 */
208
-	protected function createActivity(IShare $share) {
209
-
210
-		$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
211
-
212
-		$this->publishActivity(
213
-			Activity::SUBJECT_SHARED_EMAIL_SELF,
214
-			[$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
215
-			$share->getSharedBy(),
216
-			$share->getNode()->getId(),
217
-			$userFolder->getRelativePath($share->getNode()->getPath())
218
-		);
219
-
220
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
221
-			$ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
222
-			$fileId = $share->getNode()->getId();
223
-			$nodes = $ownerFolder->getById($fileId);
224
-			$ownerPath = $nodes[0]->getPath();
225
-			$this->publishActivity(
226
-				Activity::SUBJECT_SHARED_EMAIL_BY,
227
-				[$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
228
-				$share->getShareOwner(),
229
-				$fileId,
230
-				$ownerFolder->getRelativePath($ownerPath)
231
-			);
232
-		}
233
-
234
-	}
235
-
236
-	/**
237
-	 * publish activity if a file/folder was shared by mail
238
-	 *
239
-	 * @param $subject
240
-	 * @param $parameters
241
-	 * @param $affectedUser
242
-	 * @param $fileId
243
-	 * @param $filePath
244
-	 */
245
-	protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246
-		$event = $this->activityManager->generateEvent();
247
-		$event->setApp('sharebymail')
248
-			->setType('shared')
249
-			->setSubject($subject, $parameters)
250
-			->setAffectedUser($affectedUser)
251
-			->setObject('files', $fileId, $filePath);
252
-		$this->activityManager->publish($event);
253
-
254
-	}
255
-
256
-	/**
257
-	 * @param IShare $share
258
-	 * @return int
259
-	 * @throws \Exception
260
-	 */
261
-	protected function createMailShare(IShare $share) {
262
-		$share->setToken($this->generateToken());
263
-		$shareId = $this->addShareToDB(
264
-			$share->getNodeId(),
265
-			$share->getNodeType(),
266
-			$share->getSharedWith(),
267
-			$share->getSharedBy(),
268
-			$share->getShareOwner(),
269
-			$share->getPermissions(),
270
-			$share->getToken(),
271
-			$share->getPassword()
272
-		);
273
-
274
-		try {
275
-			$link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
276
-				['token' => $share->getToken()]);
277
-			$this->sendMailNotification($share->getNode()->getName(),
278
-				$link,
279
-				$share->getShareOwner(),
280
-				$share->getSharedBy(), $share->getSharedWith());
281
-		} catch (HintException $hintException) {
282
-			$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
283
-			$this->removeShareFromTable($shareId);
284
-			throw $hintException;
285
-		} catch (\Exception $e) {
286
-			$this->logger->error('Failed to send share by mail: ' . $e->getMessage());
287
-			$this->removeShareFromTable($shareId);
288
-			throw new HintException('Failed to send share by mail',
289
-				$this->l->t('Failed to send share by E-mail'));
290
-		}
291
-
292
-		return $shareId;
293
-
294
-	}
295
-
296
-	protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297
-		$ownerUser = $this->userManager->get($owner);
298
-		$initiatorUser = $this->userManager->get($initiator);
299
-		$ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
300
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301
-		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302
-		if ($owner === $initiator) {
303
-			$subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304
-		} else {
305
-			$subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306
-		}
307
-
308
-		$message = $this->mailer->createMessage();
309
-		$htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
310
-		$textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
311
-		$message->setTo([$shareWith]);
312
-		if ($initiatorEmailAddress !== null) {
313
-			$message->setFrom([$initiatorEmailAddress]);
314
-		}
315
-		$message->setSubject($subject);
316
-		$message->setBody($textBody, 'text/plain');
317
-		$message->setHtmlBody($htmlBody);
318
-		$this->mailer->send($message);
319
-
320
-	}
321
-
322
-	/**
323
-	 * create mail body
324
-	 *
325
-	 * @param $filename
326
-	 * @param $link
327
-	 * @param $owner
328
-	 * @param $initiator
329
-	 * @return string plain text mail
330
-	 * @throws HintException
331
-	 */
332
-	protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333
-
334
-		$mailBodyTemplate = new Template('sharebymail', $template, '');
335
-		$mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
-		$mailBodyTemplate->assign ('link', $link);
337
-		$mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
-		$mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
-		$mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
340
-		$mailBody = $mailBodyTemplate->fetchPage();
341
-
342
-		if (is_string($mailBody)) {
343
-			return $mailBody;
344
-		}
345
-
346
-		throw new HintException('Failed to create the E-mail',
347
-			$this->l->t('Failed to create the E-mail'));
348
-	}
349
-
350
-	/**
351
-	 * send password to recipient of a mail share
352
-	 *
353
-	 * @param string $filename
354
-	 * @param string $initiator
355
-	 * @param string $shareWith
356
-	 * @param string $password
357
-	 * @return bool
358
-	 */
359
-	protected function sendPassword($filename, $initiator, $shareWith, $password) {
360
-
361
-		if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
362
-			return false;
363
-		}
364
-
365
-		$initiatorUser = $this->userManager->get($initiator);
366
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367
-		$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
-		$subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369
-
370
-		$message = $this->mailer->createMessage();
371
-		$arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
372
-		$htmlBody = $this->createMailBodyToSendPassword('mailpassword', $arguments);
373
-		$textBody = $this->createMailBodyToSendPassword('altmailpassword', $arguments);
374
-		$message->setTo([$shareWith]);
375
-		if ($initiatorEmailAddress !== null) {
376
-			$message->setFrom([$initiatorEmailAddress]);
377
-		}
378
-		$message->setSubject($subject);
379
-		$message->setBody($textBody, 'text/plain');
380
-		$message->setHtmlBody($htmlBody);
381
-		$this->mailer->send($message);
382
-
383
-		return true;
384
-	}
385
-
386
-	/**
387
-	 * send auto generated password to the owner. This happens if the admin enforces
388
-	 * a password for mail shares and forbid to send the password by mail to the recipient
389
-	 *
390
-	 * @param string $filename
391
-	 * @param string $initiator
392
-	 * @param string $shareWith
393
-	 * @param string $password
394
-	 * @throws \Exception
395
-	 */
396
-	protected function sendPasswordToOwner($filename, $initiator, $shareWith, $password) {
397
-
398
-		$initiatorUser = $this->userManager->get($initiator);
399
-		$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
400
-
401
-		if ($initiatorEMailAddress === null) {
402
-			throw new \Exception(
403
-				$this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
404
-			);
405
-		}
406
-
407
-		$subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
408
-
409
-		$message = $this->mailer->createMessage();
410
-		$arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
411
-		$htmlBody = $this->createMailBodyToSendPassword('mailpasswordowner', $arguments);
412
-		$textBody = $this->createMailBodyToSendPassword('altmailpasswordowner', $arguments);
413
-		if ($initiatorEMailAddress) {
414
-			$message->setFrom([$initiatorUser->getEMailAddress()]);
415
-		}
416
-		$message->setTo([$initiatorEMailAddress]);
417
-		$message->setFrom([$initiatorEMailAddress]);
418
-		$message->setSubject($subject);
419
-		$message->setBody($textBody, 'text/plain');
420
-		$message->setHtmlBody($htmlBody);
421
-		$this->mailer->send($message);
422
-
423
-	}
424
-
425
-	/**
426
-	 * create mail body to send password to recipient
427
-	 *
428
-	 * @param string $template
429
-	 * @param array $arguments
430
-	 * @return string plain text mail
431
-	 * @throws HintException
432
-	 */
433
-	protected function createMailBodyToSendPassword($template, array $arguments) {
434
-
435
-		$mailBodyTemplate = new Template('sharebymail', $template, '');
436
-
437
-		foreach ($arguments as $key => $value) {
438
-			$mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
439
-		}
440
-
441
-		$mailBody = $mailBodyTemplate->fetchPage();
442
-
443
-		if (is_string($mailBody)) {
444
-			return $mailBody;
445
-		}
446
-
447
-		throw new HintException('Failed to create the E-mail',
448
-			$this->l->t('Failed to create the E-mail'));
449
-	}
450
-
451
-
452
-	/**
453
-	 * generate share token
454
-	 *
455
-	 * @return string
456
-	 */
457
-	protected function generateToken($size = 15) {
458
-		$token = $this->secureRandom->generate(
459
-			$size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
460
-		return $token;
461
-	}
462
-
463
-	/**
464
-	 * Get all children of this share
465
-	 *
466
-	 * @param IShare $parent
467
-	 * @return IShare[]
468
-	 */
469
-	public function getChildren(IShare $parent) {
470
-		$children = [];
471
-
472
-		$qb = $this->dbConnection->getQueryBuilder();
473
-		$qb->select('*')
474
-			->from('share')
475
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
476
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
477
-			->orderBy('id');
478
-
479
-		$cursor = $qb->execute();
480
-		while($data = $cursor->fetch()) {
481
-			$children[] = $this->createShareObject($data);
482
-		}
483
-		$cursor->closeCursor();
484
-
485
-		return $children;
486
-	}
487
-
488
-	/**
489
-	 * add share to the database and return the ID
490
-	 *
491
-	 * @param int $itemSource
492
-	 * @param string $itemType
493
-	 * @param string $shareWith
494
-	 * @param string $sharedBy
495
-	 * @param string $uidOwner
496
-	 * @param int $permissions
497
-	 * @param string $token
498
-	 * @return int
499
-	 */
500
-	protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
501
-		$qb = $this->dbConnection->getQueryBuilder();
502
-		$qb->insert('share')
503
-			->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
504
-			->setValue('item_type', $qb->createNamedParameter($itemType))
505
-			->setValue('item_source', $qb->createNamedParameter($itemSource))
506
-			->setValue('file_source', $qb->createNamedParameter($itemSource))
507
-			->setValue('share_with', $qb->createNamedParameter($shareWith))
508
-			->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
509
-			->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
510
-			->setValue('permissions', $qb->createNamedParameter($permissions))
511
-			->setValue('token', $qb->createNamedParameter($token))
512
-			->setValue('password', $qb->createNamedParameter($password))
513
-			->setValue('stime', $qb->createNamedParameter(time()));
514
-
515
-		/*
151
+        $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
152
+        if (!empty($alreadyShared)) {
153
+            $message = 'Sharing %s failed, this item is already shared with %s';
154
+            $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
155
+            $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
156
+            throw new \Exception($message_t);
157
+        }
158
+
159
+        // if the admin enforces a password for all mail shares we create a
160
+        // random password and send it to the recipient
161
+        $password = '';
162
+        $passwordEnforced = $this->settingsManager->enforcePasswordProtection();
163
+        if ($passwordEnforced) {
164
+            $password = $this->autoGeneratePassword($share);
165
+        }
166
+
167
+        $shareId = $this->createMailShare($share);
168
+        $send = $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $password);
169
+        if ($passwordEnforced && $send === false) {
170
+            $this->sendPasswordToOwner($share->getNode()->getName(), $share->getSharedBy(), $shareWith, $password);
171
+        }
172
+        $this->createActivity($share);
173
+        $data = $this->getRawShare($shareId);
174
+
175
+        return $this->createShareObject($data);
176
+
177
+    }
178
+
179
+    /**
180
+     * auto generate password in case of password enforcement on mail shares
181
+     *
182
+     * @param IShare $share
183
+     * @return string
184
+     * @throws \Exception
185
+     */
186
+    protected function autoGeneratePassword($share) {
187
+        $initiatorUser = $this->userManager->get($share->getSharedBy());
188
+        $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
189
+        $allowPasswordByMail = $this->settingsManager->sendPasswordByMail();
190
+
191
+        if ($initiatorEMailAddress === null && !$allowPasswordByMail) {
192
+            throw new \Exception(
193
+                $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
194
+            );
195
+        }
196
+
197
+        $password = $this->generateToken(8);
198
+        $share->setPassword($this->hasher->hash($password));
199
+
200
+        return $password;
201
+    }
202
+
203
+    /**
204
+     * create activity if a file/folder was shared by mail
205
+     *
206
+     * @param IShare $share
207
+     */
208
+    protected function createActivity(IShare $share) {
209
+
210
+        $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
211
+
212
+        $this->publishActivity(
213
+            Activity::SUBJECT_SHARED_EMAIL_SELF,
214
+            [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
215
+            $share->getSharedBy(),
216
+            $share->getNode()->getId(),
217
+            $userFolder->getRelativePath($share->getNode()->getPath())
218
+        );
219
+
220
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
221
+            $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
222
+            $fileId = $share->getNode()->getId();
223
+            $nodes = $ownerFolder->getById($fileId);
224
+            $ownerPath = $nodes[0]->getPath();
225
+            $this->publishActivity(
226
+                Activity::SUBJECT_SHARED_EMAIL_BY,
227
+                [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
228
+                $share->getShareOwner(),
229
+                $fileId,
230
+                $ownerFolder->getRelativePath($ownerPath)
231
+            );
232
+        }
233
+
234
+    }
235
+
236
+    /**
237
+     * publish activity if a file/folder was shared by mail
238
+     *
239
+     * @param $subject
240
+     * @param $parameters
241
+     * @param $affectedUser
242
+     * @param $fileId
243
+     * @param $filePath
244
+     */
245
+    protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
246
+        $event = $this->activityManager->generateEvent();
247
+        $event->setApp('sharebymail')
248
+            ->setType('shared')
249
+            ->setSubject($subject, $parameters)
250
+            ->setAffectedUser($affectedUser)
251
+            ->setObject('files', $fileId, $filePath);
252
+        $this->activityManager->publish($event);
253
+
254
+    }
255
+
256
+    /**
257
+     * @param IShare $share
258
+     * @return int
259
+     * @throws \Exception
260
+     */
261
+    protected function createMailShare(IShare $share) {
262
+        $share->setToken($this->generateToken());
263
+        $shareId = $this->addShareToDB(
264
+            $share->getNodeId(),
265
+            $share->getNodeType(),
266
+            $share->getSharedWith(),
267
+            $share->getSharedBy(),
268
+            $share->getShareOwner(),
269
+            $share->getPermissions(),
270
+            $share->getToken(),
271
+            $share->getPassword()
272
+        );
273
+
274
+        try {
275
+            $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
276
+                ['token' => $share->getToken()]);
277
+            $this->sendMailNotification($share->getNode()->getName(),
278
+                $link,
279
+                $share->getShareOwner(),
280
+                $share->getSharedBy(), $share->getSharedWith());
281
+        } catch (HintException $hintException) {
282
+            $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
283
+            $this->removeShareFromTable($shareId);
284
+            throw $hintException;
285
+        } catch (\Exception $e) {
286
+            $this->logger->error('Failed to send share by mail: ' . $e->getMessage());
287
+            $this->removeShareFromTable($shareId);
288
+            throw new HintException('Failed to send share by mail',
289
+                $this->l->t('Failed to send share by E-mail'));
290
+        }
291
+
292
+        return $shareId;
293
+
294
+    }
295
+
296
+    protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
297
+        $ownerUser = $this->userManager->get($owner);
298
+        $initiatorUser = $this->userManager->get($initiator);
299
+        $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
300
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
301
+        $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
302
+        if ($owner === $initiator) {
303
+            $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
304
+        } else {
305
+            $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
306
+        }
307
+
308
+        $message = $this->mailer->createMessage();
309
+        $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
310
+        $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
311
+        $message->setTo([$shareWith]);
312
+        if ($initiatorEmailAddress !== null) {
313
+            $message->setFrom([$initiatorEmailAddress]);
314
+        }
315
+        $message->setSubject($subject);
316
+        $message->setBody($textBody, 'text/plain');
317
+        $message->setHtmlBody($htmlBody);
318
+        $this->mailer->send($message);
319
+
320
+    }
321
+
322
+    /**
323
+     * create mail body
324
+     *
325
+     * @param $filename
326
+     * @param $link
327
+     * @param $owner
328
+     * @param $initiator
329
+     * @return string plain text mail
330
+     * @throws HintException
331
+     */
332
+    protected function createMailBody($template, $filename, $link, $owner, $initiator) {
333
+
334
+        $mailBodyTemplate = new Template('sharebymail', $template, '');
335
+        $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename));
336
+        $mailBodyTemplate->assign ('link', $link);
337
+        $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner));
338
+        $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator));
339
+        $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
340
+        $mailBody = $mailBodyTemplate->fetchPage();
341
+
342
+        if (is_string($mailBody)) {
343
+            return $mailBody;
344
+        }
345
+
346
+        throw new HintException('Failed to create the E-mail',
347
+            $this->l->t('Failed to create the E-mail'));
348
+    }
349
+
350
+    /**
351
+     * send password to recipient of a mail share
352
+     *
353
+     * @param string $filename
354
+     * @param string $initiator
355
+     * @param string $shareWith
356
+     * @param string $password
357
+     * @return bool
358
+     */
359
+    protected function sendPassword($filename, $initiator, $shareWith, $password) {
360
+
361
+        if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
362
+            return false;
363
+        }
364
+
365
+        $initiatorUser = $this->userManager->get($initiator);
366
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
367
+        $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
368
+        $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]);
369
+
370
+        $message = $this->mailer->createMessage();
371
+        $arguments = ['filename' => $filename, 'initiator' => $initiator, 'password' => $password];
372
+        $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $arguments);
373
+        $textBody = $this->createMailBodyToSendPassword('altmailpassword', $arguments);
374
+        $message->setTo([$shareWith]);
375
+        if ($initiatorEmailAddress !== null) {
376
+            $message->setFrom([$initiatorEmailAddress]);
377
+        }
378
+        $message->setSubject($subject);
379
+        $message->setBody($textBody, 'text/plain');
380
+        $message->setHtmlBody($htmlBody);
381
+        $this->mailer->send($message);
382
+
383
+        return true;
384
+    }
385
+
386
+    /**
387
+     * send auto generated password to the owner. This happens if the admin enforces
388
+     * a password for mail shares and forbid to send the password by mail to the recipient
389
+     *
390
+     * @param string $filename
391
+     * @param string $initiator
392
+     * @param string $shareWith
393
+     * @param string $password
394
+     * @throws \Exception
395
+     */
396
+    protected function sendPasswordToOwner($filename, $initiator, $shareWith, $password) {
397
+
398
+        $initiatorUser = $this->userManager->get($initiator);
399
+        $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
400
+
401
+        if ($initiatorEMailAddress === null) {
402
+            throw new \Exception(
403
+                $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.")
404
+            );
405
+        }
406
+
407
+        $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]);
408
+
409
+        $message = $this->mailer->createMessage();
410
+        $arguments = ['filename' => $filename, 'recipient' => $shareWith, 'password' => $password];
411
+        $htmlBody = $this->createMailBodyToSendPassword('mailpasswordowner', $arguments);
412
+        $textBody = $this->createMailBodyToSendPassword('altmailpasswordowner', $arguments);
413
+        if ($initiatorEMailAddress) {
414
+            $message->setFrom([$initiatorUser->getEMailAddress()]);
415
+        }
416
+        $message->setTo([$initiatorEMailAddress]);
417
+        $message->setFrom([$initiatorEMailAddress]);
418
+        $message->setSubject($subject);
419
+        $message->setBody($textBody, 'text/plain');
420
+        $message->setHtmlBody($htmlBody);
421
+        $this->mailer->send($message);
422
+
423
+    }
424
+
425
+    /**
426
+     * create mail body to send password to recipient
427
+     *
428
+     * @param string $template
429
+     * @param array $arguments
430
+     * @return string plain text mail
431
+     * @throws HintException
432
+     */
433
+    protected function createMailBodyToSendPassword($template, array $arguments) {
434
+
435
+        $mailBodyTemplate = new Template('sharebymail', $template, '');
436
+
437
+        foreach ($arguments as $key => $value) {
438
+            $mailBodyTemplate->assign ($key, \OCP\Util::sanitizeHTML($value));
439
+        }
440
+
441
+        $mailBody = $mailBodyTemplate->fetchPage();
442
+
443
+        if (is_string($mailBody)) {
444
+            return $mailBody;
445
+        }
446
+
447
+        throw new HintException('Failed to create the E-mail',
448
+            $this->l->t('Failed to create the E-mail'));
449
+    }
450
+
451
+
452
+    /**
453
+     * generate share token
454
+     *
455
+     * @return string
456
+     */
457
+    protected function generateToken($size = 15) {
458
+        $token = $this->secureRandom->generate(
459
+            $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
460
+        return $token;
461
+    }
462
+
463
+    /**
464
+     * Get all children of this share
465
+     *
466
+     * @param IShare $parent
467
+     * @return IShare[]
468
+     */
469
+    public function getChildren(IShare $parent) {
470
+        $children = [];
471
+
472
+        $qb = $this->dbConnection->getQueryBuilder();
473
+        $qb->select('*')
474
+            ->from('share')
475
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
476
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
477
+            ->orderBy('id');
478
+
479
+        $cursor = $qb->execute();
480
+        while($data = $cursor->fetch()) {
481
+            $children[] = $this->createShareObject($data);
482
+        }
483
+        $cursor->closeCursor();
484
+
485
+        return $children;
486
+    }
487
+
488
+    /**
489
+     * add share to the database and return the ID
490
+     *
491
+     * @param int $itemSource
492
+     * @param string $itemType
493
+     * @param string $shareWith
494
+     * @param string $sharedBy
495
+     * @param string $uidOwner
496
+     * @param int $permissions
497
+     * @param string $token
498
+     * @return int
499
+     */
500
+    protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) {
501
+        $qb = $this->dbConnection->getQueryBuilder();
502
+        $qb->insert('share')
503
+            ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
504
+            ->setValue('item_type', $qb->createNamedParameter($itemType))
505
+            ->setValue('item_source', $qb->createNamedParameter($itemSource))
506
+            ->setValue('file_source', $qb->createNamedParameter($itemSource))
507
+            ->setValue('share_with', $qb->createNamedParameter($shareWith))
508
+            ->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
509
+            ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
510
+            ->setValue('permissions', $qb->createNamedParameter($permissions))
511
+            ->setValue('token', $qb->createNamedParameter($token))
512
+            ->setValue('password', $qb->createNamedParameter($password))
513
+            ->setValue('stime', $qb->createNamedParameter(time()));
514
+
515
+        /*
516 516
 		 * Added to fix https://github.com/owncloud/core/issues/22215
517 517
 		 * Can be removed once we get rid of ajax/share.php
518 518
 		 */
519
-		$qb->setValue('file_target', $qb->createNamedParameter(''));
519
+        $qb->setValue('file_target', $qb->createNamedParameter(''));
520 520
 
521
-		$qb->execute();
522
-		$id = $qb->getLastInsertId();
521
+        $qb->execute();
522
+        $id = $qb->getLastInsertId();
523 523
 
524
-		return (int)$id;
525
-	}
524
+        return (int)$id;
525
+    }
526 526
 
527
-	/**
528
-	 * Update a share
529
-	 *
530
-	 * @param IShare $share
531
-	 * @param string|null $plainTextPassword
532
-	 * @return IShare The share object
533
-	 */
534
-	public function update(IShare $share, $plainTextPassword = null) {
527
+    /**
528
+     * Update a share
529
+     *
530
+     * @param IShare $share
531
+     * @param string|null $plainTextPassword
532
+     * @return IShare The share object
533
+     */
534
+    public function update(IShare $share, $plainTextPassword = null) {
535 535
 
536
-		$originalShare = $this->getShareById($share->getId());
536
+        $originalShare = $this->getShareById($share->getId());
537 537
 
538
-		// a real password was given
539
-		$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
538
+        // a real password was given
539
+        $validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
540 540
 
541
-		if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
542
-			$this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
543
-		}
544
-		/*
541
+        if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
542
+            $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
543
+        }
544
+        /*
545 545
 		 * We allow updating the permissions and password of mail shares
546 546
 		 */
547
-		$qb = $this->dbConnection->getQueryBuilder();
548
-		$qb->update('share')
549
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
550
-			->set('permissions', $qb->createNamedParameter($share->getPermissions()))
551
-			->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
552
-			->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
553
-			->set('password', $qb->createNamedParameter($share->getPassword()))
554
-			->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
555
-			->execute();
556
-
557
-		return $share;
558
-	}
559
-
560
-	/**
561
-	 * @inheritdoc
562
-	 */
563
-	public function move(IShare $share, $recipient) {
564
-		/**
565
-		 * nothing to do here, mail shares are only outgoing shares
566
-		 */
567
-		return $share;
568
-	}
569
-
570
-	/**
571
-	 * Delete a share (owner unShares the file)
572
-	 *
573
-	 * @param IShare $share
574
-	 */
575
-	public function delete(IShare $share) {
576
-		$this->removeShareFromTable($share->getId());
577
-	}
578
-
579
-	/**
580
-	 * @inheritdoc
581
-	 */
582
-	public function deleteFromSelf(IShare $share, $recipient) {
583
-		// nothing to do here, mail shares are only outgoing shares
584
-		return;
585
-	}
586
-
587
-	/**
588
-	 * @inheritdoc
589
-	 */
590
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
591
-		$qb = $this->dbConnection->getQueryBuilder();
592
-		$qb->select('*')
593
-			->from('share');
594
-
595
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
596
-
597
-		/**
598
-		 * Reshares for this user are shares where they are the owner.
599
-		 */
600
-		if ($reshares === false) {
601
-			//Special case for old shares created via the web UI
602
-			$or1 = $qb->expr()->andX(
603
-				$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
604
-				$qb->expr()->isNull('uid_initiator')
605
-			);
606
-
607
-			$qb->andWhere(
608
-				$qb->expr()->orX(
609
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
610
-					$or1
611
-				)
612
-			);
613
-		} else {
614
-			$qb->andWhere(
615
-				$qb->expr()->orX(
616
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
617
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
618
-				)
619
-			);
620
-		}
621
-
622
-		if ($node !== null) {
623
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
624
-		}
625
-
626
-		if ($limit !== -1) {
627
-			$qb->setMaxResults($limit);
628
-		}
629
-
630
-		$qb->setFirstResult($offset);
631
-		$qb->orderBy('id');
632
-
633
-		$cursor = $qb->execute();
634
-		$shares = [];
635
-		while($data = $cursor->fetch()) {
636
-			$shares[] = $this->createShareObject($data);
637
-		}
638
-		$cursor->closeCursor();
639
-
640
-		return $shares;
641
-	}
642
-
643
-	/**
644
-	 * @inheritdoc
645
-	 */
646
-	public function getShareById($id, $recipientId = null) {
647
-		$qb = $this->dbConnection->getQueryBuilder();
648
-
649
-		$qb->select('*')
650
-			->from('share')
651
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
652
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
653
-
654
-		$cursor = $qb->execute();
655
-		$data = $cursor->fetch();
656
-		$cursor->closeCursor();
657
-
658
-		if ($data === false) {
659
-			throw new ShareNotFound();
660
-		}
661
-
662
-		try {
663
-			$share = $this->createShareObject($data);
664
-		} catch (InvalidShare $e) {
665
-			throw new ShareNotFound();
666
-		}
667
-
668
-		return $share;
669
-	}
670
-
671
-	/**
672
-	 * Get shares for a given path
673
-	 *
674
-	 * @param \OCP\Files\Node $path
675
-	 * @return IShare[]
676
-	 */
677
-	public function getSharesByPath(Node $path) {
678
-		$qb = $this->dbConnection->getQueryBuilder();
679
-
680
-		$cursor = $qb->select('*')
681
-			->from('share')
682
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
683
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
684
-			->execute();
685
-
686
-		$shares = [];
687
-		while($data = $cursor->fetch()) {
688
-			$shares[] = $this->createShareObject($data);
689
-		}
690
-		$cursor->closeCursor();
691
-
692
-		return $shares;
693
-	}
694
-
695
-	/**
696
-	 * @inheritdoc
697
-	 */
698
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
699
-		/** @var IShare[] $shares */
700
-		$shares = [];
701
-
702
-		//Get shares directly with this user
703
-		$qb = $this->dbConnection->getQueryBuilder();
704
-		$qb->select('*')
705
-			->from('share');
706
-
707
-		// Order by id
708
-		$qb->orderBy('id');
709
-
710
-		// Set limit and offset
711
-		if ($limit !== -1) {
712
-			$qb->setMaxResults($limit);
713
-		}
714
-		$qb->setFirstResult($offset);
715
-
716
-		$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
717
-		$qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
718
-
719
-		// Filter by node if provided
720
-		if ($node !== null) {
721
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
722
-		}
723
-
724
-		$cursor = $qb->execute();
725
-
726
-		while($data = $cursor->fetch()) {
727
-			$shares[] = $this->createShareObject($data);
728
-		}
729
-		$cursor->closeCursor();
730
-
731
-
732
-		return $shares;
733
-	}
734
-
735
-	/**
736
-	 * Get a share by token
737
-	 *
738
-	 * @param string $token
739
-	 * @return IShare
740
-	 * @throws ShareNotFound
741
-	 */
742
-	public function getShareByToken($token) {
743
-		$qb = $this->dbConnection->getQueryBuilder();
744
-
745
-		$cursor = $qb->select('*')
746
-			->from('share')
747
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
748
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
749
-			->execute();
750
-
751
-		$data = $cursor->fetch();
752
-
753
-		if ($data === false) {
754
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
755
-		}
756
-
757
-		try {
758
-			$share = $this->createShareObject($data);
759
-		} catch (InvalidShare $e) {
760
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
761
-		}
762
-
763
-		return $share;
764
-	}
765
-
766
-	/**
767
-	 * remove share from table
768
-	 *
769
-	 * @param string $shareId
770
-	 */
771
-	protected function removeShareFromTable($shareId) {
772
-		$qb = $this->dbConnection->getQueryBuilder();
773
-		$qb->delete('share')
774
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
775
-		$qb->execute();
776
-	}
777
-
778
-	/**
779
-	 * Create a share object from an database row
780
-	 *
781
-	 * @param array $data
782
-	 * @return IShare
783
-	 * @throws InvalidShare
784
-	 * @throws ShareNotFound
785
-	 */
786
-	protected function createShareObject($data) {
787
-
788
-		$share = new Share($this->rootFolder, $this->userManager);
789
-		$share->setId((int)$data['id'])
790
-			->setShareType((int)$data['share_type'])
791
-			->setPermissions((int)$data['permissions'])
792
-			->setTarget($data['file_target'])
793
-			->setMailSend((bool)$data['mail_send'])
794
-			->setToken($data['token']);
795
-
796
-		$shareTime = new \DateTime();
797
-		$shareTime->setTimestamp((int)$data['stime']);
798
-		$share->setShareTime($shareTime);
799
-		$share->setSharedWith($data['share_with']);
800
-		$share->setPassword($data['password']);
801
-
802
-		if ($data['uid_initiator'] !== null) {
803
-			$share->setShareOwner($data['uid_owner']);
804
-			$share->setSharedBy($data['uid_initiator']);
805
-		} else {
806
-			//OLD SHARE
807
-			$share->setSharedBy($data['uid_owner']);
808
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
809
-
810
-			$owner = $path->getOwner();
811
-			$share->setShareOwner($owner->getUID());
812
-		}
813
-
814
-		if ($data['expiration'] !== null) {
815
-			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
816
-			if ($expiration !== false) {
817
-				$share->setExpirationDate($expiration);
818
-			}
819
-		}
820
-
821
-		$share->setNodeId((int)$data['file_source']);
822
-		$share->setNodeType($data['item_type']);
823
-
824
-		$share->setProviderId($this->identifier());
825
-
826
-		return $share;
827
-	}
828
-
829
-	/**
830
-	 * Get the node with file $id for $user
831
-	 *
832
-	 * @param string $userId
833
-	 * @param int $id
834
-	 * @return \OCP\Files\File|\OCP\Files\Folder
835
-	 * @throws InvalidShare
836
-	 */
837
-	private function getNode($userId, $id) {
838
-		try {
839
-			$userFolder = $this->rootFolder->getUserFolder($userId);
840
-		} catch (NotFoundException $e) {
841
-			throw new InvalidShare();
842
-		}
843
-
844
-		$nodes = $userFolder->getById($id);
845
-
846
-		if (empty($nodes)) {
847
-			throw new InvalidShare();
848
-		}
849
-
850
-		return $nodes[0];
851
-	}
852
-
853
-	/**
854
-	 * A user is deleted from the system
855
-	 * So clean up the relevant shares.
856
-	 *
857
-	 * @param string $uid
858
-	 * @param int $shareType
859
-	 */
860
-	public function userDeleted($uid, $shareType) {
861
-		$qb = $this->dbConnection->getQueryBuilder();
862
-
863
-		$qb->delete('share')
864
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
865
-			->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
866
-			->execute();
867
-	}
868
-
869
-	/**
870
-	 * This provider does not support group shares
871
-	 *
872
-	 * @param string $gid
873
-	 */
874
-	public function groupDeleted($gid) {
875
-		return;
876
-	}
877
-
878
-	/**
879
-	 * This provider does not support group shares
880
-	 *
881
-	 * @param string $uid
882
-	 * @param string $gid
883
-	 */
884
-	public function userDeletedFromGroup($uid, $gid) {
885
-		return;
886
-	}
887
-
888
-	/**
889
-	 * get database row of a give share
890
-	 *
891
-	 * @param $id
892
-	 * @return array
893
-	 * @throws ShareNotFound
894
-	 */
895
-	protected function getRawShare($id) {
896
-
897
-		// Now fetch the inserted share and create a complete share object
898
-		$qb = $this->dbConnection->getQueryBuilder();
899
-		$qb->select('*')
900
-			->from('share')
901
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
902
-
903
-		$cursor = $qb->execute();
904
-		$data = $cursor->fetch();
905
-		$cursor->closeCursor();
906
-
907
-		if ($data === false) {
908
-			throw new ShareNotFound;
909
-		}
910
-
911
-		return $data;
912
-	}
913
-
914
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
915
-		$qb = $this->dbConnection->getQueryBuilder();
916
-		$qb->select('*')
917
-			->from('share', 's')
918
-			->andWhere($qb->expr()->orX(
919
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
920
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
921
-			))
922
-			->andWhere(
923
-				$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
924
-			);
925
-
926
-		/**
927
-		 * Reshares for this user are shares where they are the owner.
928
-		 */
929
-		if ($reshares === false) {
930
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
931
-		} else {
932
-			$qb->andWhere(
933
-				$qb->expr()->orX(
934
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
935
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
936
-				)
937
-			);
938
-		}
939
-
940
-		$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
941
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
942
-
943
-		$qb->orderBy('id');
944
-
945
-		$cursor = $qb->execute();
946
-		$shares = [];
947
-		while ($data = $cursor->fetch()) {
948
-			$shares[$data['fileid']][] = $this->createShareObject($data);
949
-		}
950
-		$cursor->closeCursor();
951
-
952
-		return $shares;
953
-	}
547
+        $qb = $this->dbConnection->getQueryBuilder();
548
+        $qb->update('share')
549
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
550
+            ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
551
+            ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
552
+            ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
553
+            ->set('password', $qb->createNamedParameter($share->getPassword()))
554
+            ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
555
+            ->execute();
556
+
557
+        return $share;
558
+    }
559
+
560
+    /**
561
+     * @inheritdoc
562
+     */
563
+    public function move(IShare $share, $recipient) {
564
+        /**
565
+         * nothing to do here, mail shares are only outgoing shares
566
+         */
567
+        return $share;
568
+    }
569
+
570
+    /**
571
+     * Delete a share (owner unShares the file)
572
+     *
573
+     * @param IShare $share
574
+     */
575
+    public function delete(IShare $share) {
576
+        $this->removeShareFromTable($share->getId());
577
+    }
578
+
579
+    /**
580
+     * @inheritdoc
581
+     */
582
+    public function deleteFromSelf(IShare $share, $recipient) {
583
+        // nothing to do here, mail shares are only outgoing shares
584
+        return;
585
+    }
586
+
587
+    /**
588
+     * @inheritdoc
589
+     */
590
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
591
+        $qb = $this->dbConnection->getQueryBuilder();
592
+        $qb->select('*')
593
+            ->from('share');
594
+
595
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
596
+
597
+        /**
598
+         * Reshares for this user are shares where they are the owner.
599
+         */
600
+        if ($reshares === false) {
601
+            //Special case for old shares created via the web UI
602
+            $or1 = $qb->expr()->andX(
603
+                $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
604
+                $qb->expr()->isNull('uid_initiator')
605
+            );
606
+
607
+            $qb->andWhere(
608
+                $qb->expr()->orX(
609
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
610
+                    $or1
611
+                )
612
+            );
613
+        } else {
614
+            $qb->andWhere(
615
+                $qb->expr()->orX(
616
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
617
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
618
+                )
619
+            );
620
+        }
621
+
622
+        if ($node !== null) {
623
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
624
+        }
625
+
626
+        if ($limit !== -1) {
627
+            $qb->setMaxResults($limit);
628
+        }
629
+
630
+        $qb->setFirstResult($offset);
631
+        $qb->orderBy('id');
632
+
633
+        $cursor = $qb->execute();
634
+        $shares = [];
635
+        while($data = $cursor->fetch()) {
636
+            $shares[] = $this->createShareObject($data);
637
+        }
638
+        $cursor->closeCursor();
639
+
640
+        return $shares;
641
+    }
642
+
643
+    /**
644
+     * @inheritdoc
645
+     */
646
+    public function getShareById($id, $recipientId = null) {
647
+        $qb = $this->dbConnection->getQueryBuilder();
648
+
649
+        $qb->select('*')
650
+            ->from('share')
651
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
652
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
653
+
654
+        $cursor = $qb->execute();
655
+        $data = $cursor->fetch();
656
+        $cursor->closeCursor();
657
+
658
+        if ($data === false) {
659
+            throw new ShareNotFound();
660
+        }
661
+
662
+        try {
663
+            $share = $this->createShareObject($data);
664
+        } catch (InvalidShare $e) {
665
+            throw new ShareNotFound();
666
+        }
667
+
668
+        return $share;
669
+    }
670
+
671
+    /**
672
+     * Get shares for a given path
673
+     *
674
+     * @param \OCP\Files\Node $path
675
+     * @return IShare[]
676
+     */
677
+    public function getSharesByPath(Node $path) {
678
+        $qb = $this->dbConnection->getQueryBuilder();
679
+
680
+        $cursor = $qb->select('*')
681
+            ->from('share')
682
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
683
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
684
+            ->execute();
685
+
686
+        $shares = [];
687
+        while($data = $cursor->fetch()) {
688
+            $shares[] = $this->createShareObject($data);
689
+        }
690
+        $cursor->closeCursor();
691
+
692
+        return $shares;
693
+    }
694
+
695
+    /**
696
+     * @inheritdoc
697
+     */
698
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
699
+        /** @var IShare[] $shares */
700
+        $shares = [];
701
+
702
+        //Get shares directly with this user
703
+        $qb = $this->dbConnection->getQueryBuilder();
704
+        $qb->select('*')
705
+            ->from('share');
706
+
707
+        // Order by id
708
+        $qb->orderBy('id');
709
+
710
+        // Set limit and offset
711
+        if ($limit !== -1) {
712
+            $qb->setMaxResults($limit);
713
+        }
714
+        $qb->setFirstResult($offset);
715
+
716
+        $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
717
+        $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
718
+
719
+        // Filter by node if provided
720
+        if ($node !== null) {
721
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
722
+        }
723
+
724
+        $cursor = $qb->execute();
725
+
726
+        while($data = $cursor->fetch()) {
727
+            $shares[] = $this->createShareObject($data);
728
+        }
729
+        $cursor->closeCursor();
730
+
731
+
732
+        return $shares;
733
+    }
734
+
735
+    /**
736
+     * Get a share by token
737
+     *
738
+     * @param string $token
739
+     * @return IShare
740
+     * @throws ShareNotFound
741
+     */
742
+    public function getShareByToken($token) {
743
+        $qb = $this->dbConnection->getQueryBuilder();
744
+
745
+        $cursor = $qb->select('*')
746
+            ->from('share')
747
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
748
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
749
+            ->execute();
750
+
751
+        $data = $cursor->fetch();
752
+
753
+        if ($data === false) {
754
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
755
+        }
756
+
757
+        try {
758
+            $share = $this->createShareObject($data);
759
+        } catch (InvalidShare $e) {
760
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
761
+        }
762
+
763
+        return $share;
764
+    }
765
+
766
+    /**
767
+     * remove share from table
768
+     *
769
+     * @param string $shareId
770
+     */
771
+    protected function removeShareFromTable($shareId) {
772
+        $qb = $this->dbConnection->getQueryBuilder();
773
+        $qb->delete('share')
774
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
775
+        $qb->execute();
776
+    }
777
+
778
+    /**
779
+     * Create a share object from an database row
780
+     *
781
+     * @param array $data
782
+     * @return IShare
783
+     * @throws InvalidShare
784
+     * @throws ShareNotFound
785
+     */
786
+    protected function createShareObject($data) {
787
+
788
+        $share = new Share($this->rootFolder, $this->userManager);
789
+        $share->setId((int)$data['id'])
790
+            ->setShareType((int)$data['share_type'])
791
+            ->setPermissions((int)$data['permissions'])
792
+            ->setTarget($data['file_target'])
793
+            ->setMailSend((bool)$data['mail_send'])
794
+            ->setToken($data['token']);
795
+
796
+        $shareTime = new \DateTime();
797
+        $shareTime->setTimestamp((int)$data['stime']);
798
+        $share->setShareTime($shareTime);
799
+        $share->setSharedWith($data['share_with']);
800
+        $share->setPassword($data['password']);
801
+
802
+        if ($data['uid_initiator'] !== null) {
803
+            $share->setShareOwner($data['uid_owner']);
804
+            $share->setSharedBy($data['uid_initiator']);
805
+        } else {
806
+            //OLD SHARE
807
+            $share->setSharedBy($data['uid_owner']);
808
+            $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
809
+
810
+            $owner = $path->getOwner();
811
+            $share->setShareOwner($owner->getUID());
812
+        }
813
+
814
+        if ($data['expiration'] !== null) {
815
+            $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
816
+            if ($expiration !== false) {
817
+                $share->setExpirationDate($expiration);
818
+            }
819
+        }
820
+
821
+        $share->setNodeId((int)$data['file_source']);
822
+        $share->setNodeType($data['item_type']);
823
+
824
+        $share->setProviderId($this->identifier());
825
+
826
+        return $share;
827
+    }
828
+
829
+    /**
830
+     * Get the node with file $id for $user
831
+     *
832
+     * @param string $userId
833
+     * @param int $id
834
+     * @return \OCP\Files\File|\OCP\Files\Folder
835
+     * @throws InvalidShare
836
+     */
837
+    private function getNode($userId, $id) {
838
+        try {
839
+            $userFolder = $this->rootFolder->getUserFolder($userId);
840
+        } catch (NotFoundException $e) {
841
+            throw new InvalidShare();
842
+        }
843
+
844
+        $nodes = $userFolder->getById($id);
845
+
846
+        if (empty($nodes)) {
847
+            throw new InvalidShare();
848
+        }
849
+
850
+        return $nodes[0];
851
+    }
852
+
853
+    /**
854
+     * A user is deleted from the system
855
+     * So clean up the relevant shares.
856
+     *
857
+     * @param string $uid
858
+     * @param int $shareType
859
+     */
860
+    public function userDeleted($uid, $shareType) {
861
+        $qb = $this->dbConnection->getQueryBuilder();
862
+
863
+        $qb->delete('share')
864
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
865
+            ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
866
+            ->execute();
867
+    }
868
+
869
+    /**
870
+     * This provider does not support group shares
871
+     *
872
+     * @param string $gid
873
+     */
874
+    public function groupDeleted($gid) {
875
+        return;
876
+    }
877
+
878
+    /**
879
+     * This provider does not support group shares
880
+     *
881
+     * @param string $uid
882
+     * @param string $gid
883
+     */
884
+    public function userDeletedFromGroup($uid, $gid) {
885
+        return;
886
+    }
887
+
888
+    /**
889
+     * get database row of a give share
890
+     *
891
+     * @param $id
892
+     * @return array
893
+     * @throws ShareNotFound
894
+     */
895
+    protected function getRawShare($id) {
896
+
897
+        // Now fetch the inserted share and create a complete share object
898
+        $qb = $this->dbConnection->getQueryBuilder();
899
+        $qb->select('*')
900
+            ->from('share')
901
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
902
+
903
+        $cursor = $qb->execute();
904
+        $data = $cursor->fetch();
905
+        $cursor->closeCursor();
906
+
907
+        if ($data === false) {
908
+            throw new ShareNotFound;
909
+        }
910
+
911
+        return $data;
912
+    }
913
+
914
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
915
+        $qb = $this->dbConnection->getQueryBuilder();
916
+        $qb->select('*')
917
+            ->from('share', 's')
918
+            ->andWhere($qb->expr()->orX(
919
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
920
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
921
+            ))
922
+            ->andWhere(
923
+                $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
924
+            );
925
+
926
+        /**
927
+         * Reshares for this user are shares where they are the owner.
928
+         */
929
+        if ($reshares === false) {
930
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
931
+        } else {
932
+            $qb->andWhere(
933
+                $qb->expr()->orX(
934
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
935
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
936
+                )
937
+            );
938
+        }
939
+
940
+        $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
941
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
942
+
943
+        $qb->orderBy('id');
944
+
945
+        $cursor = $qb->execute();
946
+        $shares = [];
947
+        while ($data = $cursor->fetch()) {
948
+            $shares[$data['fileid']][] = $this->createShareObject($data);
949
+        }
950
+        $cursor->closeCursor();
951
+
952
+        return $shares;
953
+    }
954 954
 
955 955
 }
Please login to merge, or discard this patch.
lib/private/Share20/ProviderFactory.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -41,226 +41,226 @@
 block discarded – undo
41 41
  */
42 42
 class ProviderFactory implements IProviderFactory {
43 43
 
44
-	/** @var IServerContainer */
45
-	private $serverContainer;
46
-	/** @var DefaultShareProvider */
47
-	private $defaultProvider = null;
48
-	/** @var FederatedShareProvider */
49
-	private $federatedProvider = null;
50
-	/** @var  ShareByMailProvider */
51
-	private $shareByMailProvider;
52
-	/** @var  \OCA\Circles\ShareByCircleProvider;
53
-	 * ShareByCircleProvider */
54
-	private $shareByCircleProvider;
55
-
56
-	/**
57
-	 * IProviderFactory constructor.
58
-	 *
59
-	 * @param IServerContainer $serverContainer
60
-	 */
61
-	public function __construct(IServerContainer $serverContainer) {
62
-		$this->serverContainer = $serverContainer;
63
-	}
64
-
65
-	/**
66
-	 * Create the default share provider.
67
-	 *
68
-	 * @return DefaultShareProvider
69
-	 */
70
-	protected function defaultShareProvider() {
71
-		if ($this->defaultProvider === null) {
72
-			$this->defaultProvider = new DefaultShareProvider(
73
-				$this->serverContainer->getDatabaseConnection(),
74
-				$this->serverContainer->getUserManager(),
75
-				$this->serverContainer->getGroupManager(),
76
-				$this->serverContainer->getLazyRootFolder()
77
-			);
78
-		}
79
-
80
-		return $this->defaultProvider;
81
-	}
82
-
83
-	/**
84
-	 * Create the federated share provider
85
-	 *
86
-	 * @return FederatedShareProvider
87
-	 */
88
-	protected function federatedShareProvider() {
89
-		if ($this->federatedProvider === null) {
90
-			/*
44
+    /** @var IServerContainer */
45
+    private $serverContainer;
46
+    /** @var DefaultShareProvider */
47
+    private $defaultProvider = null;
48
+    /** @var FederatedShareProvider */
49
+    private $federatedProvider = null;
50
+    /** @var  ShareByMailProvider */
51
+    private $shareByMailProvider;
52
+    /** @var  \OCA\Circles\ShareByCircleProvider;
53
+     * ShareByCircleProvider */
54
+    private $shareByCircleProvider;
55
+
56
+    /**
57
+     * IProviderFactory constructor.
58
+     *
59
+     * @param IServerContainer $serverContainer
60
+     */
61
+    public function __construct(IServerContainer $serverContainer) {
62
+        $this->serverContainer = $serverContainer;
63
+    }
64
+
65
+    /**
66
+     * Create the default share provider.
67
+     *
68
+     * @return DefaultShareProvider
69
+     */
70
+    protected function defaultShareProvider() {
71
+        if ($this->defaultProvider === null) {
72
+            $this->defaultProvider = new DefaultShareProvider(
73
+                $this->serverContainer->getDatabaseConnection(),
74
+                $this->serverContainer->getUserManager(),
75
+                $this->serverContainer->getGroupManager(),
76
+                $this->serverContainer->getLazyRootFolder()
77
+            );
78
+        }
79
+
80
+        return $this->defaultProvider;
81
+    }
82
+
83
+    /**
84
+     * Create the federated share provider
85
+     *
86
+     * @return FederatedShareProvider
87
+     */
88
+    protected function federatedShareProvider() {
89
+        if ($this->federatedProvider === null) {
90
+            /*
91 91
 			 * Check if the app is enabled
92 92
 			 */
93
-			$appManager = $this->serverContainer->getAppManager();
94
-			if (!$appManager->isEnabledForUser('federatedfilesharing')) {
95
-				return null;
96
-			}
93
+            $appManager = $this->serverContainer->getAppManager();
94
+            if (!$appManager->isEnabledForUser('federatedfilesharing')) {
95
+                return null;
96
+            }
97 97
 
98
-			/*
98
+            /*
99 99
 			 * TODO: add factory to federated sharing app
100 100
 			 */
101
-			$l = $this->serverContainer->getL10N('federatedfilessharing');
102
-			$addressHandler = new AddressHandler(
103
-				$this->serverContainer->getURLGenerator(),
104
-				$l,
105
-				$this->serverContainer->getCloudIdManager()
106
-			);
107
-			$discoveryManager = new DiscoveryManager(
108
-				$this->serverContainer->getMemCacheFactory(),
109
-				$this->serverContainer->getHTTPClientService()
110
-			);
111
-			$notifications = new Notifications(
112
-				$addressHandler,
113
-				$this->serverContainer->getHTTPClientService(),
114
-				$discoveryManager,
115
-				$this->serverContainer->getJobList()
116
-			);
117
-			$tokenHandler = new TokenHandler(
118
-				$this->serverContainer->getSecureRandom()
119
-			);
120
-
121
-			$this->federatedProvider = new FederatedShareProvider(
122
-				$this->serverContainer->getDatabaseConnection(),
123
-				$addressHandler,
124
-				$notifications,
125
-				$tokenHandler,
126
-				$l,
127
-				$this->serverContainer->getLogger(),
128
-				$this->serverContainer->getLazyRootFolder(),
129
-				$this->serverContainer->getConfig(),
130
-				$this->serverContainer->getUserManager(),
131
-				$this->serverContainer->getCloudIdManager()
132
-			);
133
-		}
134
-
135
-		return $this->federatedProvider;
136
-	}
137
-
138
-	/**
139
-	 * Create the federated share provider
140
-	 *
141
-	 * @return ShareByMailProvider
142
-	 */
143
-	protected function getShareByMailProvider() {
144
-		if ($this->shareByMailProvider === null) {
145
-			/*
101
+            $l = $this->serverContainer->getL10N('federatedfilessharing');
102
+            $addressHandler = new AddressHandler(
103
+                $this->serverContainer->getURLGenerator(),
104
+                $l,
105
+                $this->serverContainer->getCloudIdManager()
106
+            );
107
+            $discoveryManager = new DiscoveryManager(
108
+                $this->serverContainer->getMemCacheFactory(),
109
+                $this->serverContainer->getHTTPClientService()
110
+            );
111
+            $notifications = new Notifications(
112
+                $addressHandler,
113
+                $this->serverContainer->getHTTPClientService(),
114
+                $discoveryManager,
115
+                $this->serverContainer->getJobList()
116
+            );
117
+            $tokenHandler = new TokenHandler(
118
+                $this->serverContainer->getSecureRandom()
119
+            );
120
+
121
+            $this->federatedProvider = new FederatedShareProvider(
122
+                $this->serverContainer->getDatabaseConnection(),
123
+                $addressHandler,
124
+                $notifications,
125
+                $tokenHandler,
126
+                $l,
127
+                $this->serverContainer->getLogger(),
128
+                $this->serverContainer->getLazyRootFolder(),
129
+                $this->serverContainer->getConfig(),
130
+                $this->serverContainer->getUserManager(),
131
+                $this->serverContainer->getCloudIdManager()
132
+            );
133
+        }
134
+
135
+        return $this->federatedProvider;
136
+    }
137
+
138
+    /**
139
+     * Create the federated share provider
140
+     *
141
+     * @return ShareByMailProvider
142
+     */
143
+    protected function getShareByMailProvider() {
144
+        if ($this->shareByMailProvider === null) {
145
+            /*
146 146
 			 * Check if the app is enabled
147 147
 			 */
148
-			$appManager = $this->serverContainer->getAppManager();
149
-			if (!$appManager->isEnabledForUser('sharebymail')) {
150
-				return null;
151
-			}
152
-
153
-			$settingsManager = new SettingsManager($this->serverContainer->getConfig());
154
-
155
-			$this->shareByMailProvider = new ShareByMailProvider(
156
-				$this->serverContainer->getDatabaseConnection(),
157
-				$this->serverContainer->getSecureRandom(),
158
-				$this->serverContainer->getUserManager(),
159
-				$this->serverContainer->getLazyRootFolder(),
160
-				$this->serverContainer->getL10N('sharebymail'),
161
-				$this->serverContainer->getLogger(),
162
-				$this->serverContainer->getMailer(),
163
-				$this->serverContainer->getURLGenerator(),
164
-				$this->serverContainer->getActivityManager(),
165
-				$settingsManager,
166
-				$this->serverContainer->getHasher()
167
-			);
168
-		}
169
-
170
-		return $this->shareByMailProvider;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Create the circle share provider
176
-	 *
177
-	 * @return FederatedShareProvider
178
-	 */
179
-	protected function getShareByCircleProvider() {
180
-
181
-		$appManager = $this->serverContainer->getAppManager();
182
-		if (!$appManager->isEnabledForUser('circles')) {
183
-			return null;
184
-		}
185
-
186
-
187
-		if ($this->shareByCircleProvider === null) {
188
-
189
-			$this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
190
-				$this->serverContainer->getDatabaseConnection(),
191
-				$this->serverContainer->getSecureRandom(),
192
-				$this->serverContainer->getUserManager(),
193
-				$this->serverContainer->getLazyRootFolder(),
194
-				$this->serverContainer->getL10N('circles'),
195
-				$this->serverContainer->getLogger(),
196
-				$this->serverContainer->getURLGenerator()
197
-			);
198
-		}
199
-
200
-		return $this->shareByCircleProvider;
201
-	}
202
-
203
-
204
-	/**
205
-	 * @inheritdoc
206
-	 */
207
-	public function getProvider($id) {
208
-		$provider = null;
209
-		if ($id === 'ocinternal') {
210
-			$provider = $this->defaultShareProvider();
211
-		} else if ($id === 'ocFederatedSharing') {
212
-			$provider = $this->federatedShareProvider();
213
-		} else if ($id === 'ocMailShare') {
214
-			$provider = $this->getShareByMailProvider();
215
-		} else if ($id === 'ocCircleShare') {
216
-			$provider = $this->getShareByCircleProvider();
217
-		}
218
-
219
-		if ($provider === null) {
220
-			throw new ProviderException('No provider with id .' . $id . ' found.');
221
-		}
222
-
223
-		return $provider;
224
-	}
225
-
226
-	/**
227
-	 * @inheritdoc
228
-	 */
229
-	public function getProviderForType($shareType) {
230
-		$provider = null;
231
-
232
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
233
-			$shareType === \OCP\Share::SHARE_TYPE_GROUP ||
234
-			$shareType === \OCP\Share::SHARE_TYPE_LINK
235
-		) {
236
-			$provider = $this->defaultShareProvider();
237
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
238
-			$provider = $this->federatedShareProvider();
239
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
240
-			$provider = $this->getShareByMailProvider();
241
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
242
-			$provider = $this->getShareByCircleProvider();
243
-		}
244
-
245
-
246
-		if ($provider === null) {
247
-			throw new ProviderException('No share provider for share type ' . $shareType);
248
-		}
249
-
250
-		return $provider;
251
-	}
252
-
253
-	public function getAllProviders() {
254
-		$shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
255
-		$shareByMail = $this->getShareByMailProvider();
256
-		if ($shareByMail !== null) {
257
-			$shares[] = $shareByMail;
258
-		}
259
-		$shareByCircle = $this->getShareByCircleProvider();
260
-		if ($shareByCircle !== null) {
261
-			$shares[] = $shareByCircle;
262
-		}
263
-
264
-		return $shares;
265
-	}
148
+            $appManager = $this->serverContainer->getAppManager();
149
+            if (!$appManager->isEnabledForUser('sharebymail')) {
150
+                return null;
151
+            }
152
+
153
+            $settingsManager = new SettingsManager($this->serverContainer->getConfig());
154
+
155
+            $this->shareByMailProvider = new ShareByMailProvider(
156
+                $this->serverContainer->getDatabaseConnection(),
157
+                $this->serverContainer->getSecureRandom(),
158
+                $this->serverContainer->getUserManager(),
159
+                $this->serverContainer->getLazyRootFolder(),
160
+                $this->serverContainer->getL10N('sharebymail'),
161
+                $this->serverContainer->getLogger(),
162
+                $this->serverContainer->getMailer(),
163
+                $this->serverContainer->getURLGenerator(),
164
+                $this->serverContainer->getActivityManager(),
165
+                $settingsManager,
166
+                $this->serverContainer->getHasher()
167
+            );
168
+        }
169
+
170
+        return $this->shareByMailProvider;
171
+    }
172
+
173
+
174
+    /**
175
+     * Create the circle share provider
176
+     *
177
+     * @return FederatedShareProvider
178
+     */
179
+    protected function getShareByCircleProvider() {
180
+
181
+        $appManager = $this->serverContainer->getAppManager();
182
+        if (!$appManager->isEnabledForUser('circles')) {
183
+            return null;
184
+        }
185
+
186
+
187
+        if ($this->shareByCircleProvider === null) {
188
+
189
+            $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
190
+                $this->serverContainer->getDatabaseConnection(),
191
+                $this->serverContainer->getSecureRandom(),
192
+                $this->serverContainer->getUserManager(),
193
+                $this->serverContainer->getLazyRootFolder(),
194
+                $this->serverContainer->getL10N('circles'),
195
+                $this->serverContainer->getLogger(),
196
+                $this->serverContainer->getURLGenerator()
197
+            );
198
+        }
199
+
200
+        return $this->shareByCircleProvider;
201
+    }
202
+
203
+
204
+    /**
205
+     * @inheritdoc
206
+     */
207
+    public function getProvider($id) {
208
+        $provider = null;
209
+        if ($id === 'ocinternal') {
210
+            $provider = $this->defaultShareProvider();
211
+        } else if ($id === 'ocFederatedSharing') {
212
+            $provider = $this->federatedShareProvider();
213
+        } else if ($id === 'ocMailShare') {
214
+            $provider = $this->getShareByMailProvider();
215
+        } else if ($id === 'ocCircleShare') {
216
+            $provider = $this->getShareByCircleProvider();
217
+        }
218
+
219
+        if ($provider === null) {
220
+            throw new ProviderException('No provider with id .' . $id . ' found.');
221
+        }
222
+
223
+        return $provider;
224
+    }
225
+
226
+    /**
227
+     * @inheritdoc
228
+     */
229
+    public function getProviderForType($shareType) {
230
+        $provider = null;
231
+
232
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
233
+            $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
234
+            $shareType === \OCP\Share::SHARE_TYPE_LINK
235
+        ) {
236
+            $provider = $this->defaultShareProvider();
237
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
238
+            $provider = $this->federatedShareProvider();
239
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) {
240
+            $provider = $this->getShareByMailProvider();
241
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) {
242
+            $provider = $this->getShareByCircleProvider();
243
+        }
244
+
245
+
246
+        if ($provider === null) {
247
+            throw new ProviderException('No share provider for share type ' . $shareType);
248
+        }
249
+
250
+        return $provider;
251
+    }
252
+
253
+    public function getAllProviders() {
254
+        $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];
255
+        $shareByMail = $this->getShareByMailProvider();
256
+        if ($shareByMail !== null) {
257
+            $shares[] = $shareByMail;
258
+        }
259
+        $shareByCircle = $this->getShareByCircleProvider();
260
+        if ($shareByCircle !== null) {
261
+            $shares[] = $shareByCircle;
262
+        }
263
+
264
+        return $shares;
265
+    }
266 266
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings/SettingsManager.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,35 +27,35 @@
 block discarded – undo
27 27
 
28 28
 class SettingsManager {
29 29
 
30
-	/** @var IConfig */
31
-	private $config;
32
-
33
-	private $sendPasswordByMailDefault = 'yes';
34
-
35
-	private $enforcePasswordProtectionDefault = 'no';
36
-
37
-	public function __construct(IConfig $config) {
38
-		$this->config = $config;
39
-	}
40
-
41
-	/**
42
-	 * should the password for a mail share be send to the recipient
43
-	 *
44
-	 * @return bool
45
-	 */
46
-	public function sendPasswordByMail() {
47
-		$sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
-		return $sendPasswordByMail === 'yes';
49
-	}
50
-
51
-	/**
52
-	 * do we require a share by mail to be password protected
53
-	 *
54
-	 * @return bool
55
-	 */
56
-	public function enforcePasswordProtection() {
57
-		$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
-		return $enforcePassword === 'yes';
59
-	}
30
+    /** @var IConfig */
31
+    private $config;
32
+
33
+    private $sendPasswordByMailDefault = 'yes';
34
+
35
+    private $enforcePasswordProtectionDefault = 'no';
36
+
37
+    public function __construct(IConfig $config) {
38
+        $this->config = $config;
39
+    }
40
+
41
+    /**
42
+     * should the password for a mail share be send to the recipient
43
+     *
44
+     * @return bool
45
+     */
46
+    public function sendPasswordByMail() {
47
+        $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
48
+        return $sendPasswordByMail === 'yes';
49
+    }
50
+
51
+    /**
52
+     * do we require a share by mail to be password protected
53
+     *
54
+     * @return bool
55
+     */
56
+    public function enforcePasswordProtection() {
57
+        $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
58
+        return $enforcePassword === 'yes';
59
+    }
60 60
 
61 61
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings/Admin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -27,42 +27,42 @@
 block discarded – undo
27 27
 
28 28
 class Admin implements ISettings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32 32
 
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36 36
 
37
-	/**
38
-	 * @return TemplateResponse
39
-	 */
40
-	public function getForm() {
37
+    /**
38
+     * @return TemplateResponse
39
+     */
40
+    public function getForm() {
41 41
 
42
-		$parameters = [
43
-			'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
-			'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
-		];
42
+        $parameters = [
43
+            'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
44
+            'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
45
+        ];
46 46
 
47
-		return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
-	}
47
+        return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
48
+    }
49 49
 
50
-	/**
51
-	 * @return string the section ID, e.g. 'sharing'
52
-	 */
53
-	public function getSection() {
54
-		return 'sharing';
55
-	}
50
+    /**
51
+     * @return string the section ID, e.g. 'sharing'
52
+     */
53
+    public function getSection() {
54
+        return 'sharing';
55
+    }
56 56
 
57
-	/**
58
-	 * @return int whether the form should be rather on the top or bottom of
59
-	 * the admin section. The forms are arranged in ascending order of the
60
-	 * priority values. It is required to return a value between 0 and 100.
61
-	 *
62
-	 * E.g.: 70
63
-	 */
64
-	public function getPriority() {
65
-		return 40;
66
-	}
57
+    /**
58
+     * @return int whether the form should be rather on the top or bottom of
59
+     * the admin section. The forms are arranged in ascending order of the
60
+     * priority values. It is required to return a value between 0 and 100.
61
+     *
62
+     * E.g.: 70
63
+     */
64
+    public function getPriority() {
65
+        return 40;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/Settings.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -27,27 +27,27 @@
 block discarded – undo
27 27
 
28 28
 class Settings {
29 29
 
30
-	/** @var SettingsManager */
31
-	private $settingsManager;
32
-
33
-	public function __construct(SettingsManager $settingsManager) {
34
-		$this->settingsManager = $settingsManager;
35
-	}
36
-
37
-	/**
38
-	 * announce that the share-by-mail share provider is enabled
39
-	 *
40
-	 * @param array $settings
41
-	 */
42
-	public function announceShareProvider(array $settings) {
43
-		$array = json_decode($settings['array']['oc_appconfig'], true);
44
-		$array['shareByMailEnabled'] = true;
45
-		$settings['array']['oc_appconfig'] = json_encode($array);
46
-	}
47
-
48
-	public function announceShareByMailSettings(array $settings) {
49
-		$array = json_decode($settings['array']['oc_appconfig'], true);
50
-		$array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
-		$settings['array']['oc_appconfig'] = json_encode($array);
52
-	}
30
+    /** @var SettingsManager */
31
+    private $settingsManager;
32
+
33
+    public function __construct(SettingsManager $settingsManager) {
34
+        $this->settingsManager = $settingsManager;
35
+    }
36
+
37
+    /**
38
+     * announce that the share-by-mail share provider is enabled
39
+     *
40
+     * @param array $settings
41
+     */
42
+    public function announceShareProvider(array $settings) {
43
+        $array = json_decode($settings['array']['oc_appconfig'], true);
44
+        $array['shareByMailEnabled'] = true;
45
+        $settings['array']['oc_appconfig'] = json_encode($array);
46
+    }
47
+
48
+    public function announceShareByMailSettings(array $settings) {
49
+        $array = json_decode($settings['array']['oc_appconfig'], true);
50
+        $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
51
+        $settings['array']['oc_appconfig'] = json_encode($array);
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/sharebymail/templates/settings-admin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 	<em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> />
15 15
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
16
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> />
17 17
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 18
 	</p>
19 19
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,15 @@
 block discarded – undo
11 11
 	<em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) {
15
+    p('checked');
16
+}
17
+?> />
15 18
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
19
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) {
20
+    p('checked');
21
+}
22
+?> />
17 23
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 24
 	</p>
19 25
 
Please login to merge, or discard this patch.
apps/sharebymail/templates/mailpasswordowner.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@
 block discarded – undo
36 36
 					<td width="20px">&nbsp;</td>
37 37
 					<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
38 38
 						<?php
39
-						print_unescaped($l->t('Hey there,<br><br>you just shared »%s« with %s.<br>The share was already send to the recipient. Due to the security policies each share needs to be protected by email and it is not allowed to send the password directly by mail to the recipient. Therefore you need to forward the password manually to the recipient.<br><br>This is the password: %s<br><br>You can chose a different password at any time in the share dialog.<br><br>', [$_['filename'], $_['recipient'], $_['password']]));
40
-						// TRANSLATORS term at the end of a mail
41
-						p($l->t('Cheers!'));
42
-						?>
39
+                        print_unescaped($l->t('Hey there,<br><br>you just shared »%s« with %s.<br>The share was already send to the recipient. Due to the security policies each share needs to be protected by email and it is not allowed to send the password directly by mail to the recipient. Therefore you need to forward the password manually to the recipient.<br><br>This is the password: %s<br><br>You can chose a different password at any time in the share dialog.<br><br>', [$_['filename'], $_['recipient'], $_['password']]));
40
+                        // TRANSLATORS term at the end of a mail
41
+                        p($l->t('Cheers!'));
42
+                        ?>
43 43
 					</td>
44 44
 				</tr>
45 45
 				<tr><td colspan="2">&nbsp;</td></tr>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	<tr><td>
28 28
 			<table cellspacing="0" cellpadding="0" border="0" width="600px">
29 29
 				<tr>
30
-					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>">
30
+					<td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>">
31 31
 						<img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/>
32 32
 					</td>
33 33
 				</tr>
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 					<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
53 53
 						<?php p($theme->getName()); ?> -
54 54
 						<?php p($theme->getSlogan()); ?>
55
-						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a>
55
+						<br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a>
56 56
 					</td>
57 57
 				</tr>
58 58
 				<tr>
Please login to merge, or discard this patch.
apps/sharebymail/templates/altmail.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,5 +32,5 @@
 block discarded – undo
32 32
 ?>
33 33
 
34 34
 <?php print_unescaped("-- \n"); ?>
35
-<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
35
+<?php p($theme->getName().' - '.$theme->getSlogan()); ?>
36 36
 <?php print_unescaped("\n".$theme->getBaseUrl());
Please login to merge, or discard this patch.
apps/sharebymail/templates/altmailpassword.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,5 +32,5 @@
 block discarded – undo
32 32
 ?>
33 33
 
34 34
 <?php print_unescaped("-- \n"); ?>
35
-<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
35
+<?php p($theme->getName().' - '.$theme->getSlogan()); ?>
36 36
 <?php print_unescaped("\n".$theme->getBaseUrl());
Please login to merge, or discard this patch.