Completed
Pull Request — master (#4212)
by Individual IT
13:52
created
apps/sharebymail/lib/Settings.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@
 block discarded – undo
25 25
 
26 26
 class Settings {
27 27
 
28
-	/**
29
-	 * announce that the share-by-mail share provider is enabled
30
-	 *
31
-	 * @param array $settings
32
-	 */
33
-	public function announceShareProvider(array $settings) {
34
-		$array = json_decode($settings['array']['oc_appconfig'], true);
35
-		$array['shareByMailEnabled'] = true;
36
-		$settings['array']['oc_appconfig'] = json_encode($array);
37
-	}
28
+    /**
29
+     * announce that the share-by-mail share provider is enabled
30
+     *
31
+     * @param array $settings
32
+     */
33
+    public function announceShareProvider(array $settings) {
34
+        $array = json_decode($settings['array']['oc_appconfig'], true);
35
+        $array['shareByMailEnabled'] = true;
36
+        $settings['array']['oc_appconfig'] = json_encode($array);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/sharebymail/lib/ShareByMailProvider.php 1 patch
Indentation   +716 added lines, -716 removed lines patch added patch discarded remove patch
@@ -48,728 +48,728 @@
 block discarded – undo
48 48
  */
49 49
 class ShareByMailProvider implements IShareProvider {
50 50
 
51
-	/** @var  IDBConnection */
52
-	private $dbConnection;
53
-
54
-	/** @var ILogger */
55
-	private $logger;
56
-
57
-	/** @var ISecureRandom */
58
-	private $secureRandom;
59
-
60
-	/** @var IUserManager */
61
-	private $userManager;
62
-
63
-	/** @var IRootFolder */
64
-	private $rootFolder;
65
-
66
-	/** @var IL10N */
67
-	private $l;
68
-
69
-	/** @var IMailer */
70
-	private $mailer;
71
-
72
-	/** @var IURLGenerator */
73
-	private $urlGenerator;
74
-
75
-	/** @var IManager  */
76
-	private $activityManager;
77
-
78
-	/**
79
-	 * Return the identifier of this provider.
80
-	 *
81
-	 * @return string Containing only [a-zA-Z0-9]
82
-	 */
83
-	public function identifier() {
84
-		return 'ocShareByMail';
85
-	}
86
-
87
-	/**
88
-	 * DefaultShareProvider constructor.
89
-	 *
90
-	 * @param IDBConnection $connection
91
-	 * @param ISecureRandom $secureRandom
92
-	 * @param IUserManager $userManager
93
-	 * @param IRootFolder $rootFolder
94
-	 * @param IL10N $l
95
-	 * @param ILogger $logger
96
-	 * @param IMailer $mailer
97
-	 * @param IURLGenerator $urlGenerator
98
-	 * @param IManager $activityManager
99
-	 */
100
-	public function __construct(
101
-		IDBConnection $connection,
102
-		ISecureRandom $secureRandom,
103
-		IUserManager $userManager,
104
-		IRootFolder $rootFolder,
105
-		IL10N $l,
106
-		ILogger $logger,
107
-		IMailer $mailer,
108
-		IURLGenerator $urlGenerator,
109
-		IManager $activityManager
110
-	) {
111
-		$this->dbConnection = $connection;
112
-		$this->secureRandom = $secureRandom;
113
-		$this->userManager = $userManager;
114
-		$this->rootFolder = $rootFolder;
115
-		$this->l = $l;
116
-		$this->logger = $logger;
117
-		$this->mailer = $mailer;
118
-		$this->urlGenerator = $urlGenerator;
119
-		$this->activityManager = $activityManager;
120
-	}
121
-
122
-	/**
123
-	 * Share a path
124
-	 *
125
-	 * @param IShare $share
126
-	 * @return IShare The share object
127
-	 * @throws ShareNotFound
128
-	 * @throws \Exception
129
-	 */
130
-	public function create(IShare $share) {
131
-
132
-		$shareWith = $share->getSharedWith();
133
-		/*
51
+    /** @var  IDBConnection */
52
+    private $dbConnection;
53
+
54
+    /** @var ILogger */
55
+    private $logger;
56
+
57
+    /** @var ISecureRandom */
58
+    private $secureRandom;
59
+
60
+    /** @var IUserManager */
61
+    private $userManager;
62
+
63
+    /** @var IRootFolder */
64
+    private $rootFolder;
65
+
66
+    /** @var IL10N */
67
+    private $l;
68
+
69
+    /** @var IMailer */
70
+    private $mailer;
71
+
72
+    /** @var IURLGenerator */
73
+    private $urlGenerator;
74
+
75
+    /** @var IManager  */
76
+    private $activityManager;
77
+
78
+    /**
79
+     * Return the identifier of this provider.
80
+     *
81
+     * @return string Containing only [a-zA-Z0-9]
82
+     */
83
+    public function identifier() {
84
+        return 'ocShareByMail';
85
+    }
86
+
87
+    /**
88
+     * DefaultShareProvider constructor.
89
+     *
90
+     * @param IDBConnection $connection
91
+     * @param ISecureRandom $secureRandom
92
+     * @param IUserManager $userManager
93
+     * @param IRootFolder $rootFolder
94
+     * @param IL10N $l
95
+     * @param ILogger $logger
96
+     * @param IMailer $mailer
97
+     * @param IURLGenerator $urlGenerator
98
+     * @param IManager $activityManager
99
+     */
100
+    public function __construct(
101
+        IDBConnection $connection,
102
+        ISecureRandom $secureRandom,
103
+        IUserManager $userManager,
104
+        IRootFolder $rootFolder,
105
+        IL10N $l,
106
+        ILogger $logger,
107
+        IMailer $mailer,
108
+        IURLGenerator $urlGenerator,
109
+        IManager $activityManager
110
+    ) {
111
+        $this->dbConnection = $connection;
112
+        $this->secureRandom = $secureRandom;
113
+        $this->userManager = $userManager;
114
+        $this->rootFolder = $rootFolder;
115
+        $this->l = $l;
116
+        $this->logger = $logger;
117
+        $this->mailer = $mailer;
118
+        $this->urlGenerator = $urlGenerator;
119
+        $this->activityManager = $activityManager;
120
+    }
121
+
122
+    /**
123
+     * Share a path
124
+     *
125
+     * @param IShare $share
126
+     * @return IShare The share object
127
+     * @throws ShareNotFound
128
+     * @throws \Exception
129
+     */
130
+    public function create(IShare $share) {
131
+
132
+        $shareWith = $share->getSharedWith();
133
+        /*
134 134
 		 * Check if file is not already shared with the remote user
135 135
 		 */
136
-		$alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
137
-		if (!empty($alreadyShared)) {
138
-			$message = 'Sharing %s failed, this item is already shared with %s';
139
-			$message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
140
-			$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
141
-			throw new \Exception($message_t);
142
-		}
143
-
144
-		$shareId = $this->createMailShare($share);
145
-		$this->createActivity($share);
146
-		$data = $this->getRawShare($shareId);
147
-		return $this->createShareObject($data);
148
-
149
-	}
150
-
151
-	/**
152
-	 * create activity if a file/folder was shared by mail
153
-	 *
154
-	 * @param IShare $share
155
-	 */
156
-	protected function createActivity(IShare $share) {
157
-
158
-		$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
159
-
160
-		$this->publishActivity(
161
-			Activity::SUBJECT_SHARED_EMAIL_SELF,
162
-			[$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
163
-			$share->getSharedBy(),
164
-			$share->getNode()->getId(),
165
-			$userFolder->getRelativePath($share->getNode()->getPath())
166
-		);
167
-
168
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
169
-			$ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
170
-			$fileId = $share->getNode()->getId();
171
-			$nodes = $ownerFolder->getById($fileId);
172
-			$ownerPath = $nodes[0]->getPath();
173
-			$this->publishActivity(
174
-				Activity::SUBJECT_SHARED_EMAIL_BY,
175
-				[$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
176
-				$share->getShareOwner(),
177
-				$fileId,
178
-				$ownerFolder->getRelativePath($ownerPath)
179
-			);
180
-		}
181
-
182
-	}
183
-
184
-	/**
185
-	 * publish activity if a file/folder was shared by mail
186
-	 *
187
-	 * @param $subject
188
-	 * @param $parameters
189
-	 * @param $affectedUser
190
-	 * @param $fileId
191
-	 * @param $filePath
192
-	 */
193
-	protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
194
-		$event = $this->activityManager->generateEvent();
195
-		$event->setApp('sharebymail')
196
-			->setType('shared')
197
-			->setSubject($subject, $parameters)
198
-			->setAffectedUser($affectedUser)
199
-			->setObject('files', $fileId, $filePath);
200
-		$this->activityManager->publish($event);
201
-
202
-	}
203
-
204
-	/**
205
-	 * @param IShare $share
206
-	 * @return int
207
-	 * @throws \Exception
208
-	 */
209
-	protected function createMailShare(IShare $share) {
210
-		$share->setToken($this->generateToken());
211
-		$shareId = $this->addShareToDB(
212
-			$share->getNodeId(),
213
-			$share->getNodeType(),
214
-			$share->getSharedWith(),
215
-			$share->getSharedBy(),
216
-			$share->getShareOwner(),
217
-			$share->getPermissions(),
218
-			$share->getToken()
219
-		);
220
-
221
-		try {
222
-			$link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
223
-				['token' => $share->getToken()]);
224
-			$this->sendMailNotification($share->getNode()->getName(),
225
-				$link,
226
-				$share->getShareOwner(),
227
-				$share->getSharedBy(), $share->getSharedWith());
228
-		} catch (HintException $hintException) {
229
-			$this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
230
-			$this->removeShareFromTable($shareId);
231
-			throw $hintException;
232
-		} catch (\Exception $e) {
233
-			$this->logger->error('Failed to send share by mail: ' . $e->getMessage());
234
-			$this->removeShareFromTable($shareId);
235
-			throw new HintException('Failed to send share by mail',
236
-				$this->l->t('Failed to send share by E-mail'));
237
-		}
238
-
239
-		return $shareId;
240
-
241
-	}
242
-
243
-	protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
244
-		$ownerUser = $this->userManager->get($owner);
245
-		$initiatorUser = $this->userManager->get($initiator);
246
-		$ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
247
-		$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
248
-		if ($owner === $initiator) {
249
-			$subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
250
-		} else {
251
-			$subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
252
-		}
253
-
254
-		$message = $this->mailer->createMessage();
255
-		$htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
256
-		$textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
257
-		$message->setTo([$shareWith]);
258
-		$message->setSubject($subject);
259
-		$message->setBody($textBody, 'text/plain');
260
-		$message->setHtmlBody($htmlBody);
261
-		$this->mailer->send($message);
262
-
263
-	}
264
-
265
-	/**
266
-	 * create mail body
267
-	 *
268
-	 * @param $filename
269
-	 * @param $link
270
-	 * @param $owner
271
-	 * @param $initiator
272
-	 * @return string plain text mail
273
-	 * @throws HintException
274
-	 */
275
-	protected function createMailBody($template, $filename, $link, $owner, $initiator) {
276
-
277
-		$mailBodyTemplate = new Template('sharebymail', $template, '');
278
-		$mailBodyTemplate->assign ('filename', $filename);
279
-		$mailBodyTemplate->assign ('link', $link);
280
-		$mailBodyTemplate->assign ('owner', $owner);
281
-		$mailBodyTemplate->assign ('initiator', $initiator);
282
-		$mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
283
-		$mailBody = $mailBodyTemplate->fetchPage();
284
-
285
-		if (is_string($mailBody)) {
286
-			return $mailBody;
287
-		}
288
-
289
-		throw new HintException('Failed to create the E-mail',
290
-			$this->l->t('Failed to create the E-mail'));
291
-	}
292
-
293
-	/**
294
-	 * generate share token
295
-	 *
296
-	 * @return string
297
-	 */
298
-	protected function generateToken() {
299
-		$token = $this->secureRandom->generate(
300
-			15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
301
-		return $token;
302
-	}
303
-
304
-	/**
305
-	 * Get all children of this share
306
-	 *
307
-	 * @param IShare $parent
308
-	 * @return IShare[]
309
-	 */
310
-	public function getChildren(IShare $parent) {
311
-		$children = [];
312
-
313
-		$qb = $this->dbConnection->getQueryBuilder();
314
-		$qb->select('*')
315
-			->from('share')
316
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
317
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
318
-			->orderBy('id');
319
-
320
-		$cursor = $qb->execute();
321
-		while($data = $cursor->fetch()) {
322
-			$children[] = $this->createShareObject($data);
323
-		}
324
-		$cursor->closeCursor();
325
-
326
-		return $children;
327
-	}
328
-
329
-	/**
330
-	 * add share to the database and return the ID
331
-	 *
332
-	 * @param int $itemSource
333
-	 * @param string $itemType
334
-	 * @param string $shareWith
335
-	 * @param string $sharedBy
336
-	 * @param string $uidOwner
337
-	 * @param int $permissions
338
-	 * @param string $token
339
-	 * @return int
340
-	 */
341
-	protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) {
342
-		$qb = $this->dbConnection->getQueryBuilder();
343
-		$qb->insert('share')
344
-			->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
345
-			->setValue('item_type', $qb->createNamedParameter($itemType))
346
-			->setValue('item_source', $qb->createNamedParameter($itemSource))
347
-			->setValue('file_source', $qb->createNamedParameter($itemSource))
348
-			->setValue('share_with', $qb->createNamedParameter($shareWith))
349
-			->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
350
-			->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
351
-			->setValue('permissions', $qb->createNamedParameter($permissions))
352
-			->setValue('token', $qb->createNamedParameter($token))
353
-			->setValue('stime', $qb->createNamedParameter(time()));
354
-
355
-		/*
136
+        $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0);
137
+        if (!empty($alreadyShared)) {
138
+            $message = 'Sharing %s failed, this item is already shared with %s';
139
+            $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith));
140
+            $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
141
+            throw new \Exception($message_t);
142
+        }
143
+
144
+        $shareId = $this->createMailShare($share);
145
+        $this->createActivity($share);
146
+        $data = $this->getRawShare($shareId);
147
+        return $this->createShareObject($data);
148
+
149
+    }
150
+
151
+    /**
152
+     * create activity if a file/folder was shared by mail
153
+     *
154
+     * @param IShare $share
155
+     */
156
+    protected function createActivity(IShare $share) {
157
+
158
+        $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
159
+
160
+        $this->publishActivity(
161
+            Activity::SUBJECT_SHARED_EMAIL_SELF,
162
+            [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
163
+            $share->getSharedBy(),
164
+            $share->getNode()->getId(),
165
+            $userFolder->getRelativePath($share->getNode()->getPath())
166
+        );
167
+
168
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
169
+            $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
170
+            $fileId = $share->getNode()->getId();
171
+            $nodes = $ownerFolder->getById($fileId);
172
+            $ownerPath = $nodes[0]->getPath();
173
+            $this->publishActivity(
174
+                Activity::SUBJECT_SHARED_EMAIL_BY,
175
+                [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
176
+                $share->getShareOwner(),
177
+                $fileId,
178
+                $ownerFolder->getRelativePath($ownerPath)
179
+            );
180
+        }
181
+
182
+    }
183
+
184
+    /**
185
+     * publish activity if a file/folder was shared by mail
186
+     *
187
+     * @param $subject
188
+     * @param $parameters
189
+     * @param $affectedUser
190
+     * @param $fileId
191
+     * @param $filePath
192
+     */
193
+    protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) {
194
+        $event = $this->activityManager->generateEvent();
195
+        $event->setApp('sharebymail')
196
+            ->setType('shared')
197
+            ->setSubject($subject, $parameters)
198
+            ->setAffectedUser($affectedUser)
199
+            ->setObject('files', $fileId, $filePath);
200
+        $this->activityManager->publish($event);
201
+
202
+    }
203
+
204
+    /**
205
+     * @param IShare $share
206
+     * @return int
207
+     * @throws \Exception
208
+     */
209
+    protected function createMailShare(IShare $share) {
210
+        $share->setToken($this->generateToken());
211
+        $shareId = $this->addShareToDB(
212
+            $share->getNodeId(),
213
+            $share->getNodeType(),
214
+            $share->getSharedWith(),
215
+            $share->getSharedBy(),
216
+            $share->getShareOwner(),
217
+            $share->getPermissions(),
218
+            $share->getToken()
219
+        );
220
+
221
+        try {
222
+            $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
223
+                ['token' => $share->getToken()]);
224
+            $this->sendMailNotification($share->getNode()->getName(),
225
+                $link,
226
+                $share->getShareOwner(),
227
+                $share->getSharedBy(), $share->getSharedWith());
228
+        } catch (HintException $hintException) {
229
+            $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage());
230
+            $this->removeShareFromTable($shareId);
231
+            throw $hintException;
232
+        } catch (\Exception $e) {
233
+            $this->logger->error('Failed to send share by mail: ' . $e->getMessage());
234
+            $this->removeShareFromTable($shareId);
235
+            throw new HintException('Failed to send share by mail',
236
+                $this->l->t('Failed to send share by E-mail'));
237
+        }
238
+
239
+        return $shareId;
240
+
241
+    }
242
+
243
+    protected function sendMailNotification($filename, $link, $owner, $initiator, $shareWith) {
244
+        $ownerUser = $this->userManager->get($owner);
245
+        $initiatorUser = $this->userManager->get($initiator);
246
+        $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner;
247
+        $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
248
+        if ($owner === $initiator) {
249
+            $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename));
250
+        } else {
251
+            $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName));
252
+        }
253
+
254
+        $message = $this->mailer->createMessage();
255
+        $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
256
+        $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName);
257
+        $message->setTo([$shareWith]);
258
+        $message->setSubject($subject);
259
+        $message->setBody($textBody, 'text/plain');
260
+        $message->setHtmlBody($htmlBody);
261
+        $this->mailer->send($message);
262
+
263
+    }
264
+
265
+    /**
266
+     * create mail body
267
+     *
268
+     * @param $filename
269
+     * @param $link
270
+     * @param $owner
271
+     * @param $initiator
272
+     * @return string plain text mail
273
+     * @throws HintException
274
+     */
275
+    protected function createMailBody($template, $filename, $link, $owner, $initiator) {
276
+
277
+        $mailBodyTemplate = new Template('sharebymail', $template, '');
278
+        $mailBodyTemplate->assign ('filename', $filename);
279
+        $mailBodyTemplate->assign ('link', $link);
280
+        $mailBodyTemplate->assign ('owner', $owner);
281
+        $mailBodyTemplate->assign ('initiator', $initiator);
282
+        $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner);
283
+        $mailBody = $mailBodyTemplate->fetchPage();
284
+
285
+        if (is_string($mailBody)) {
286
+            return $mailBody;
287
+        }
288
+
289
+        throw new HintException('Failed to create the E-mail',
290
+            $this->l->t('Failed to create the E-mail'));
291
+    }
292
+
293
+    /**
294
+     * generate share token
295
+     *
296
+     * @return string
297
+     */
298
+    protected function generateToken() {
299
+        $token = $this->secureRandom->generate(
300
+            15, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
301
+        return $token;
302
+    }
303
+
304
+    /**
305
+     * Get all children of this share
306
+     *
307
+     * @param IShare $parent
308
+     * @return IShare[]
309
+     */
310
+    public function getChildren(IShare $parent) {
311
+        $children = [];
312
+
313
+        $qb = $this->dbConnection->getQueryBuilder();
314
+        $qb->select('*')
315
+            ->from('share')
316
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
317
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
318
+            ->orderBy('id');
319
+
320
+        $cursor = $qb->execute();
321
+        while($data = $cursor->fetch()) {
322
+            $children[] = $this->createShareObject($data);
323
+        }
324
+        $cursor->closeCursor();
325
+
326
+        return $children;
327
+    }
328
+
329
+    /**
330
+     * add share to the database and return the ID
331
+     *
332
+     * @param int $itemSource
333
+     * @param string $itemType
334
+     * @param string $shareWith
335
+     * @param string $sharedBy
336
+     * @param string $uidOwner
337
+     * @param int $permissions
338
+     * @param string $token
339
+     * @return int
340
+     */
341
+    protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) {
342
+        $qb = $this->dbConnection->getQueryBuilder();
343
+        $qb->insert('share')
344
+            ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
345
+            ->setValue('item_type', $qb->createNamedParameter($itemType))
346
+            ->setValue('item_source', $qb->createNamedParameter($itemSource))
347
+            ->setValue('file_source', $qb->createNamedParameter($itemSource))
348
+            ->setValue('share_with', $qb->createNamedParameter($shareWith))
349
+            ->setValue('uid_owner', $qb->createNamedParameter($uidOwner))
350
+            ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy))
351
+            ->setValue('permissions', $qb->createNamedParameter($permissions))
352
+            ->setValue('token', $qb->createNamedParameter($token))
353
+            ->setValue('stime', $qb->createNamedParameter(time()));
354
+
355
+        /*
356 356
 		 * Added to fix https://github.com/owncloud/core/issues/22215
357 357
 		 * Can be removed once we get rid of ajax/share.php
358 358
 		 */
359
-		$qb->setValue('file_target', $qb->createNamedParameter(''));
360
-
361
-		$qb->execute();
362
-		$id = $qb->getLastInsertId();
363
-
364
-		return (int)$id;
365
-	}
366
-
367
-	/**
368
-	 * Update a share
369
-	 *
370
-	 * @param IShare $share
371
-	 * @return IShare The share object
372
-	 */
373
-	public function update(IShare $share) {
374
-		/*
359
+        $qb->setValue('file_target', $qb->createNamedParameter(''));
360
+
361
+        $qb->execute();
362
+        $id = $qb->getLastInsertId();
363
+
364
+        return (int)$id;
365
+    }
366
+
367
+    /**
368
+     * Update a share
369
+     *
370
+     * @param IShare $share
371
+     * @return IShare The share object
372
+     */
373
+    public function update(IShare $share) {
374
+        /*
375 375
 		 * We allow updating the permissions of mail shares
376 376
 		 */
377
-		$qb = $this->dbConnection->getQueryBuilder();
378
-			$qb->update('share')
379
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
380
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
381
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
382
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
383
-				->execute();
384
-
385
-		return $share;
386
-	}
387
-
388
-	/**
389
-	 * @inheritdoc
390
-	 */
391
-	public function move(IShare $share, $recipient) {
392
-		/**
393
-		 * nothing to do here, mail shares are only outgoing shares
394
-		 */
395
-		return $share;
396
-	}
397
-
398
-	/**
399
-	 * Delete a share (owner unShares the file)
400
-	 *
401
-	 * @param IShare $share
402
-	 */
403
-	public function delete(IShare $share) {
404
-		$this->removeShareFromTable($share->getId());
405
-	}
406
-
407
-	/**
408
-	 * @inheritdoc
409
-	 */
410
-	public function deleteFromSelf(IShare $share, $recipient) {
411
-		// nothing to do here, mail shares are only outgoing shares
412
-		return;
413
-	}
414
-
415
-	/**
416
-	 * @inheritdoc
417
-	 */
418
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
419
-		$qb = $this->dbConnection->getQueryBuilder();
420
-		$qb->select('*')
421
-			->from('share');
422
-
423
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
424
-
425
-		/**
426
-		 * Reshares for this user are shares where they are the owner.
427
-		 */
428
-		if ($reshares === false) {
429
-			//Special case for old shares created via the web UI
430
-			$or1 = $qb->expr()->andX(
431
-				$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
432
-				$qb->expr()->isNull('uid_initiator')
433
-			);
434
-
435
-			$qb->andWhere(
436
-				$qb->expr()->orX(
437
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
438
-					$or1
439
-				)
440
-			);
441
-		} else {
442
-			$qb->andWhere(
443
-				$qb->expr()->orX(
444
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
445
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
446
-				)
447
-			);
448
-		}
449
-
450
-		if ($node !== null) {
451
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
452
-		}
453
-
454
-		if ($limit !== -1) {
455
-			$qb->setMaxResults($limit);
456
-		}
457
-
458
-		$qb->setFirstResult($offset);
459
-		$qb->orderBy('id');
460
-
461
-		$cursor = $qb->execute();
462
-		$shares = [];
463
-		while($data = $cursor->fetch()) {
464
-			$shares[] = $this->createShareObject($data);
465
-		}
466
-		$cursor->closeCursor();
467
-
468
-		return $shares;
469
-	}
470
-
471
-	/**
472
-	 * @inheritdoc
473
-	 */
474
-	public function getShareById($id, $recipientId = null) {
475
-		$qb = $this->dbConnection->getQueryBuilder();
476
-
477
-		$qb->select('*')
478
-			->from('share')
479
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
480
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
481
-
482
-		$cursor = $qb->execute();
483
-		$data = $cursor->fetch();
484
-		$cursor->closeCursor();
485
-
486
-		if ($data === false) {
487
-			throw new ShareNotFound();
488
-		}
489
-
490
-		try {
491
-			$share = $this->createShareObject($data);
492
-		} catch (InvalidShare $e) {
493
-			throw new ShareNotFound();
494
-		}
495
-
496
-		return $share;
497
-	}
498
-
499
-	/**
500
-	 * Get shares for a given path
501
-	 *
502
-	 * @param \OCP\Files\Node $path
503
-	 * @return IShare[]
504
-	 */
505
-	public function getSharesByPath(Node $path) {
506
-		$qb = $this->dbConnection->getQueryBuilder();
507
-
508
-		$cursor = $qb->select('*')
509
-			->from('share')
510
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
511
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
512
-			->execute();
513
-
514
-		$shares = [];
515
-		while($data = $cursor->fetch()) {
516
-			$shares[] = $this->createShareObject($data);
517
-		}
518
-		$cursor->closeCursor();
519
-
520
-		return $shares;
521
-	}
522
-
523
-	/**
524
-	 * @inheritdoc
525
-	 */
526
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
527
-		/** @var IShare[] $shares */
528
-		$shares = [];
529
-
530
-		//Get shares directly with this user
531
-		$qb = $this->dbConnection->getQueryBuilder();
532
-		$qb->select('*')
533
-			->from('share');
534
-
535
-		// Order by id
536
-		$qb->orderBy('id');
537
-
538
-		// Set limit and offset
539
-		if ($limit !== -1) {
540
-			$qb->setMaxResults($limit);
541
-		}
542
-		$qb->setFirstResult($offset);
543
-
544
-		$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
545
-		$qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
546
-
547
-		// Filter by node if provided
548
-		if ($node !== null) {
549
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
550
-		}
551
-
552
-		$cursor = $qb->execute();
553
-
554
-		while($data = $cursor->fetch()) {
555
-			$shares[] = $this->createShareObject($data);
556
-		}
557
-		$cursor->closeCursor();
558
-
559
-
560
-		return $shares;
561
-	}
562
-
563
-	/**
564
-	 * Get a share by token
565
-	 *
566
-	 * @param string $token
567
-	 * @return IShare
568
-	 * @throws ShareNotFound
569
-	 */
570
-	public function getShareByToken($token) {
571
-		$qb = $this->dbConnection->getQueryBuilder();
572
-
573
-		$cursor = $qb->select('*')
574
-			->from('share')
575
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
576
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
577
-			->execute();
578
-
579
-		$data = $cursor->fetch();
580
-
581
-		if ($data === false) {
582
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
583
-		}
584
-
585
-		try {
586
-			$share = $this->createShareObject($data);
587
-		} catch (InvalidShare $e) {
588
-			throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
589
-		}
590
-
591
-		return $share;
592
-	}
593
-
594
-	/**
595
-	 * remove share from table
596
-	 *
597
-	 * @param string $shareId
598
-	 */
599
-	protected function removeShareFromTable($shareId) {
600
-		$qb = $this->dbConnection->getQueryBuilder();
601
-		$qb->delete('share')
602
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
603
-		$qb->execute();
604
-	}
605
-
606
-	/**
607
-	 * Create a share object from an database row
608
-	 *
609
-	 * @param array $data
610
-	 * @return IShare
611
-	 * @throws InvalidShare
612
-	 * @throws ShareNotFound
613
-	 */
614
-	protected function createShareObject($data) {
615
-
616
-		$share = new Share($this->rootFolder, $this->userManager);
617
-		$share->setId((int)$data['id'])
618
-			->setShareType((int)$data['share_type'])
619
-			->setPermissions((int)$data['permissions'])
620
-			->setTarget($data['file_target'])
621
-			->setMailSend((bool)$data['mail_send'])
622
-			->setToken($data['token']);
623
-
624
-		$shareTime = new \DateTime();
625
-		$shareTime->setTimestamp((int)$data['stime']);
626
-		$share->setShareTime($shareTime);
627
-		$share->setSharedWith($data['share_with']);
628
-
629
-		if ($data['uid_initiator'] !== null) {
630
-			$share->setShareOwner($data['uid_owner']);
631
-			$share->setSharedBy($data['uid_initiator']);
632
-		} else {
633
-			//OLD SHARE
634
-			$share->setSharedBy($data['uid_owner']);
635
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
636
-
637
-			$owner = $path->getOwner();
638
-			$share->setShareOwner($owner->getUID());
639
-		}
640
-
641
-		$share->setNodeId((int)$data['file_source']);
642
-		$share->setNodeType($data['item_type']);
643
-
644
-		$share->setProviderId($this->identifier());
645
-
646
-		return $share;
647
-	}
648
-
649
-	/**
650
-	 * Get the node with file $id for $user
651
-	 *
652
-	 * @param string $userId
653
-	 * @param int $id
654
-	 * @return \OCP\Files\File|\OCP\Files\Folder
655
-	 * @throws InvalidShare
656
-	 */
657
-	private function getNode($userId, $id) {
658
-		try {
659
-			$userFolder = $this->rootFolder->getUserFolder($userId);
660
-		} catch (NotFoundException $e) {
661
-			throw new InvalidShare();
662
-		}
663
-
664
-		$nodes = $userFolder->getById($id);
665
-
666
-		if (empty($nodes)) {
667
-			throw new InvalidShare();
668
-		}
669
-
670
-		return $nodes[0];
671
-	}
672
-
673
-	/**
674
-	 * A user is deleted from the system
675
-	 * So clean up the relevant shares.
676
-	 *
677
-	 * @param string $uid
678
-	 * @param int $shareType
679
-	 */
680
-	public function userDeleted($uid, $shareType) {
681
-		$qb = $this->dbConnection->getQueryBuilder();
682
-
683
-		$qb->delete('share')
684
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
685
-			->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
686
-			->execute();
687
-	}
688
-
689
-	/**
690
-	 * This provider does not support group shares
691
-	 *
692
-	 * @param string $gid
693
-	 */
694
-	public function groupDeleted($gid) {
695
-		return;
696
-	}
697
-
698
-	/**
699
-	 * This provider does not support group shares
700
-	 *
701
-	 * @param string $uid
702
-	 * @param string $gid
703
-	 */
704
-	public function userDeletedFromGroup($uid, $gid) {
705
-		return;
706
-	}
707
-
708
-	/**
709
-	 * get database row of a give share
710
-	 *
711
-	 * @param $id
712
-	 * @return array
713
-	 * @throws ShareNotFound
714
-	 */
715
-	protected function getRawShare($id) {
716
-
717
-		// Now fetch the inserted share and create a complete share object
718
-		$qb = $this->dbConnection->getQueryBuilder();
719
-		$qb->select('*')
720
-			->from('share')
721
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
722
-
723
-		$cursor = $qb->execute();
724
-		$data = $cursor->fetch();
725
-		$cursor->closeCursor();
726
-
727
-		if ($data === false) {
728
-			throw new ShareNotFound;
729
-		}
730
-
731
-		return $data;
732
-	}
733
-
734
-	public function getSharesInFolder($userId, Folder $node, $reshares) {
735
-		$qb = $this->dbConnection->getQueryBuilder();
736
-		$qb->select('*')
737
-			->from('share', 's')
738
-			->andWhere($qb->expr()->orX(
739
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
740
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
741
-			))
742
-			->andWhere(
743
-				$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
744
-			);
745
-
746
-		/**
747
-		 * Reshares for this user are shares where they are the owner.
748
-		 */
749
-		if ($reshares === false) {
750
-			$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
751
-		} else {
752
-			$qb->andWhere(
753
-				$qb->expr()->orX(
754
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
755
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
756
-				)
757
-			);
758
-		}
759
-
760
-		$qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid');
761
-		$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
762
-
763
-		$qb->orderBy('id');
764
-
765
-		$cursor = $qb->execute();
766
-		$shares = [];
767
-		while ($data = $cursor->fetch()) {
768
-			$shares[$data['fileid']][] = $this->createShareObject($data);
769
-		}
770
-		$cursor->closeCursor();
771
-
772
-		return $shares;
773
-	}
377
+        $qb = $this->dbConnection->getQueryBuilder();
378
+            $qb->update('share')
379
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
380
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
381
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
382
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
383
+                ->execute();
384
+
385
+        return $share;
386
+    }
387
+
388
+    /**
389
+     * @inheritdoc
390
+     */
391
+    public function move(IShare $share, $recipient) {
392
+        /**
393
+         * nothing to do here, mail shares are only outgoing shares
394
+         */
395
+        return $share;
396
+    }
397
+
398
+    /**
399
+     * Delete a share (owner unShares the file)
400
+     *
401
+     * @param IShare $share
402
+     */
403
+    public function delete(IShare $share) {
404
+        $this->removeShareFromTable($share->getId());
405
+    }
406
+
407
+    /**
408
+     * @inheritdoc
409
+     */
410
+    public function deleteFromSelf(IShare $share, $recipient) {
411
+        // nothing to do here, mail shares are only outgoing shares
412
+        return;
413
+    }
414
+
415
+    /**
416
+     * @inheritdoc
417
+     */
418
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
419
+        $qb = $this->dbConnection->getQueryBuilder();
420
+        $qb->select('*')
421
+            ->from('share');
422
+
423
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
424
+
425
+        /**
426
+         * Reshares for this user are shares where they are the owner.
427
+         */
428
+        if ($reshares === false) {
429
+            //Special case for old shares created via the web UI
430
+            $or1 = $qb->expr()->andX(
431
+                $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
432
+                $qb->expr()->isNull('uid_initiator')
433
+            );
434
+
435
+            $qb->andWhere(
436
+                $qb->expr()->orX(
437
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
438
+                    $or1
439
+                )
440
+            );
441
+        } else {
442
+            $qb->andWhere(
443
+                $qb->expr()->orX(
444
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
445
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
446
+                )
447
+            );
448
+        }
449
+
450
+        if ($node !== null) {
451
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
452
+        }
453
+
454
+        if ($limit !== -1) {
455
+            $qb->setMaxResults($limit);
456
+        }
457
+
458
+        $qb->setFirstResult($offset);
459
+        $qb->orderBy('id');
460
+
461
+        $cursor = $qb->execute();
462
+        $shares = [];
463
+        while($data = $cursor->fetch()) {
464
+            $shares[] = $this->createShareObject($data);
465
+        }
466
+        $cursor->closeCursor();
467
+
468
+        return $shares;
469
+    }
470
+
471
+    /**
472
+     * @inheritdoc
473
+     */
474
+    public function getShareById($id, $recipientId = null) {
475
+        $qb = $this->dbConnection->getQueryBuilder();
476
+
477
+        $qb->select('*')
478
+            ->from('share')
479
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
480
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
481
+
482
+        $cursor = $qb->execute();
483
+        $data = $cursor->fetch();
484
+        $cursor->closeCursor();
485
+
486
+        if ($data === false) {
487
+            throw new ShareNotFound();
488
+        }
489
+
490
+        try {
491
+            $share = $this->createShareObject($data);
492
+        } catch (InvalidShare $e) {
493
+            throw new ShareNotFound();
494
+        }
495
+
496
+        return $share;
497
+    }
498
+
499
+    /**
500
+     * Get shares for a given path
501
+     *
502
+     * @param \OCP\Files\Node $path
503
+     * @return IShare[]
504
+     */
505
+    public function getSharesByPath(Node $path) {
506
+        $qb = $this->dbConnection->getQueryBuilder();
507
+
508
+        $cursor = $qb->select('*')
509
+            ->from('share')
510
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
511
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
512
+            ->execute();
513
+
514
+        $shares = [];
515
+        while($data = $cursor->fetch()) {
516
+            $shares[] = $this->createShareObject($data);
517
+        }
518
+        $cursor->closeCursor();
519
+
520
+        return $shares;
521
+    }
522
+
523
+    /**
524
+     * @inheritdoc
525
+     */
526
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
527
+        /** @var IShare[] $shares */
528
+        $shares = [];
529
+
530
+        //Get shares directly with this user
531
+        $qb = $this->dbConnection->getQueryBuilder();
532
+        $qb->select('*')
533
+            ->from('share');
534
+
535
+        // Order by id
536
+        $qb->orderBy('id');
537
+
538
+        // Set limit and offset
539
+        if ($limit !== -1) {
540
+            $qb->setMaxResults($limit);
541
+        }
542
+        $qb->setFirstResult($offset);
543
+
544
+        $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)));
545
+        $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)));
546
+
547
+        // Filter by node if provided
548
+        if ($node !== null) {
549
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
550
+        }
551
+
552
+        $cursor = $qb->execute();
553
+
554
+        while($data = $cursor->fetch()) {
555
+            $shares[] = $this->createShareObject($data);
556
+        }
557
+        $cursor->closeCursor();
558
+
559
+
560
+        return $shares;
561
+    }
562
+
563
+    /**
564
+     * Get a share by token
565
+     *
566
+     * @param string $token
567
+     * @return IShare
568
+     * @throws ShareNotFound
569
+     */
570
+    public function getShareByToken($token) {
571
+        $qb = $this->dbConnection->getQueryBuilder();
572
+
573
+        $cursor = $qb->select('*')
574
+            ->from('share')
575
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
576
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
577
+            ->execute();
578
+
579
+        $data = $cursor->fetch();
580
+
581
+        if ($data === false) {
582
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
583
+        }
584
+
585
+        try {
586
+            $share = $this->createShareObject($data);
587
+        } catch (InvalidShare $e) {
588
+            throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
589
+        }
590
+
591
+        return $share;
592
+    }
593
+
594
+    /**
595
+     * remove share from table
596
+     *
597
+     * @param string $shareId
598
+     */
599
+    protected function removeShareFromTable($shareId) {
600
+        $qb = $this->dbConnection->getQueryBuilder();
601
+        $qb->delete('share')
602
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
603
+        $qb->execute();
604
+    }
605
+
606
+    /**
607
+     * Create a share object from an database row
608
+     *
609
+     * @param array $data
610
+     * @return IShare
611
+     * @throws InvalidShare
612
+     * @throws ShareNotFound
613
+     */
614
+    protected function createShareObject($data) {
615
+
616
+        $share = new Share($this->rootFolder, $this->userManager);
617
+        $share->setId((int)$data['id'])
618
+            ->setShareType((int)$data['share_type'])
619
+            ->setPermissions((int)$data['permissions'])
620
+            ->setTarget($data['file_target'])
621
+            ->setMailSend((bool)$data['mail_send'])
622
+            ->setToken($data['token']);
623
+
624
+        $shareTime = new \DateTime();
625
+        $shareTime->setTimestamp((int)$data['stime']);
626
+        $share->setShareTime($shareTime);
627
+        $share->setSharedWith($data['share_with']);
628
+
629
+        if ($data['uid_initiator'] !== null) {
630
+            $share->setShareOwner($data['uid_owner']);
631
+            $share->setSharedBy($data['uid_initiator']);
632
+        } else {
633
+            //OLD SHARE
634
+            $share->setSharedBy($data['uid_owner']);
635
+            $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
636
+
637
+            $owner = $path->getOwner();
638
+            $share->setShareOwner($owner->getUID());
639
+        }
640
+
641
+        $share->setNodeId((int)$data['file_source']);
642
+        $share->setNodeType($data['item_type']);
643
+
644
+        $share->setProviderId($this->identifier());
645
+
646
+        return $share;
647
+    }
648
+
649
+    /**
650
+     * Get the node with file $id for $user
651
+     *
652
+     * @param string $userId
653
+     * @param int $id
654
+     * @return \OCP\Files\File|\OCP\Files\Folder
655
+     * @throws InvalidShare
656
+     */
657
+    private function getNode($userId, $id) {
658
+        try {
659
+            $userFolder = $this->rootFolder->getUserFolder($userId);
660
+        } catch (NotFoundException $e) {
661
+            throw new InvalidShare();
662
+        }
663
+
664
+        $nodes = $userFolder->getById($id);
665
+
666
+        if (empty($nodes)) {
667
+            throw new InvalidShare();
668
+        }
669
+
670
+        return $nodes[0];
671
+    }
672
+
673
+    /**
674
+     * A user is deleted from the system
675
+     * So clean up the relevant shares.
676
+     *
677
+     * @param string $uid
678
+     * @param int $shareType
679
+     */
680
+    public function userDeleted($uid, $shareType) {
681
+        $qb = $this->dbConnection->getQueryBuilder();
682
+
683
+        $qb->delete('share')
684
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
685
+            ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)))
686
+            ->execute();
687
+    }
688
+
689
+    /**
690
+     * This provider does not support group shares
691
+     *
692
+     * @param string $gid
693
+     */
694
+    public function groupDeleted($gid) {
695
+        return;
696
+    }
697
+
698
+    /**
699
+     * This provider does not support group shares
700
+     *
701
+     * @param string $uid
702
+     * @param string $gid
703
+     */
704
+    public function userDeletedFromGroup($uid, $gid) {
705
+        return;
706
+    }
707
+
708
+    /**
709
+     * get database row of a give share
710
+     *
711
+     * @param $id
712
+     * @return array
713
+     * @throws ShareNotFound
714
+     */
715
+    protected function getRawShare($id) {
716
+
717
+        // Now fetch the inserted share and create a complete share object
718
+        $qb = $this->dbConnection->getQueryBuilder();
719
+        $qb->select('*')
720
+            ->from('share')
721
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
722
+
723
+        $cursor = $qb->execute();
724
+        $data = $cursor->fetch();
725
+        $cursor->closeCursor();
726
+
727
+        if ($data === false) {
728
+            throw new ShareNotFound;
729
+        }
730
+
731
+        return $data;
732
+    }
733
+
734
+    public function getSharesInFolder($userId, Folder $node, $reshares) {
735
+        $qb = $this->dbConnection->getQueryBuilder();
736
+        $qb->select('*')
737
+            ->from('share', 's')
738
+            ->andWhere($qb->expr()->orX(
739
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
740
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
741
+            ))
742
+            ->andWhere(
743
+                $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
744
+            );
745
+
746
+        /**
747
+         * Reshares for this user are shares where they are the owner.
748
+         */
749
+        if ($reshares === false) {
750
+            $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
751
+        } else {
752
+            $qb->andWhere(
753
+                $qb->expr()->orX(
754
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
755
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
756
+                )
757
+            );
758
+        }
759
+
760
+        $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid');
761
+        $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
762
+
763
+        $qb->orderBy('id');
764
+
765
+        $cursor = $qb->execute();
766
+        $shares = [];
767
+        while ($data = $cursor->fetch()) {
768
+            $shares[$data['fileid']][] = $this->createShareObject($data);
769
+        }
770
+        $cursor->closeCursor();
771
+
772
+        return $shares;
773
+    }
774 774
 
775 775
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Controller/RequestTime.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@
 block discarded – undo
26 26
 
27 27
 class RequestTime extends Controller {
28 28
 
29
-	/**
30
-	 * @NoAdminRequired
31
-	 *
32
-	 * @param string $search
33
-	 * @return JSONResponse
34
-	 */
35
-	public function getTimezones($search = '') {
36
-		$timezones = \DateTimeZone::listIdentifiers();
29
+    /**
30
+     * @NoAdminRequired
31
+     *
32
+     * @param string $search
33
+     * @return JSONResponse
34
+     */
35
+    public function getTimezones($search = '') {
36
+        $timezones = \DateTimeZone::listIdentifiers();
37 37
 
38
-		if ($search !== '') {
39
-			$timezones = array_filter($timezones, function ($timezone) use ($search) {
40
-				return strpos(strtolower($timezone), strtolower($search)) !== false;
41
-			});
42
-		}
38
+        if ($search !== '') {
39
+            $timezones = array_filter($timezones, function ($timezone) use ($search) {
40
+                return strpos(strtolower($timezone), strtolower($search)) !== false;
41
+            });
42
+        }
43 43
 
44
-		$timezones = array_slice($timezones, 0, 10);
44
+        $timezones = array_slice($timezones, 0, 10);
45 45
 
46
-		$response = [];
47
-		foreach ($timezones as $timezone) {
48
-			$response[$timezone] = $timezone;
49
-		}
50
-		return new JSONResponse($response);
51
-	}
46
+        $response = [];
47
+        foreach ($timezones as $timezone) {
48
+            $response[$timezone] = $timezone;
49
+        }
50
+        return new JSONResponse($response);
51
+    }
52 52
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Controller/FlowOperations.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -29,100 +29,100 @@
 block discarded – undo
29 29
 
30 30
 class FlowOperations extends Controller {
31 31
 
32
-	/** @var Manager */
33
-	protected $manager;
32
+    /** @var Manager */
33
+    protected $manager;
34 34
 
35
-	/**
36
-	 * @param IRequest $request
37
-	 * @param Manager $manager
38
-	 */
39
-	public function __construct(IRequest $request, Manager $manager) {
40
-		parent::__construct('workflowengine', $request);
41
-		$this->manager = $manager;
42
-	}
35
+    /**
36
+     * @param IRequest $request
37
+     * @param Manager $manager
38
+     */
39
+    public function __construct(IRequest $request, Manager $manager) {
40
+        parent::__construct('workflowengine', $request);
41
+        $this->manager = $manager;
42
+    }
43 43
 
44
-	/**
45
-	 * @NoCSRFRequired
46
-	 *
47
-	 * @param string $class
48
-	 * @return JSONResponse
49
-	 */
50
-	public function getOperations($class) {
51
-		$operations = $this->manager->getOperations($class);
44
+    /**
45
+     * @NoCSRFRequired
46
+     *
47
+     * @param string $class
48
+     * @return JSONResponse
49
+     */
50
+    public function getOperations($class) {
51
+        $operations = $this->manager->getOperations($class);
52 52
 
53
-		foreach ($operations as &$operation) {
54
-			$operation = $this->prepareOperation($operation);
55
-		}
53
+        foreach ($operations as &$operation) {
54
+            $operation = $this->prepareOperation($operation);
55
+        }
56 56
 
57
-		return new JSONResponse($operations);
58
-	}
57
+        return new JSONResponse($operations);
58
+    }
59 59
 
60
-	/**
61
-	 * @PasswordConfirmationRequired
62
-	 *
63
-	 * @param string $class
64
-	 * @param string $name
65
-	 * @param array[] $checks
66
-	 * @param string $operation
67
-	 * @return JSONResponse The added element
68
-	 */
69
-	public function addOperation($class, $name, $checks, $operation) {
70
-		try {
71
-			$operation = $this->manager->addOperation($class, $name, $checks, $operation);
72
-			$operation = $this->prepareOperation($operation);
73
-			return new JSONResponse($operation);
74
-		} catch (\UnexpectedValueException $e) {
75
-			return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST);
76
-		}
77
-	}
60
+    /**
61
+     * @PasswordConfirmationRequired
62
+     *
63
+     * @param string $class
64
+     * @param string $name
65
+     * @param array[] $checks
66
+     * @param string $operation
67
+     * @return JSONResponse The added element
68
+     */
69
+    public function addOperation($class, $name, $checks, $operation) {
70
+        try {
71
+            $operation = $this->manager->addOperation($class, $name, $checks, $operation);
72
+            $operation = $this->prepareOperation($operation);
73
+            return new JSONResponse($operation);
74
+        } catch (\UnexpectedValueException $e) {
75
+            return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST);
76
+        }
77
+    }
78 78
 
79
-	/**
80
-	 * @PasswordConfirmationRequired
81
-	 *
82
-	 * @param int $id
83
-	 * @param string $name
84
-	 * @param array[] $checks
85
-	 * @param string $operation
86
-	 * @return JSONResponse The updated element
87
-	 */
88
-	public function updateOperation($id, $name, $checks, $operation) {
89
-		try {
90
-			$operation = $this->manager->updateOperation($id, $name, $checks, $operation);
91
-			$operation = $this->prepareOperation($operation);
92
-			return new JSONResponse($operation);
93
-		} catch (\UnexpectedValueException $e) {
94
-			return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST);
95
-		}
96
-	}
79
+    /**
80
+     * @PasswordConfirmationRequired
81
+     *
82
+     * @param int $id
83
+     * @param string $name
84
+     * @param array[] $checks
85
+     * @param string $operation
86
+     * @return JSONResponse The updated element
87
+     */
88
+    public function updateOperation($id, $name, $checks, $operation) {
89
+        try {
90
+            $operation = $this->manager->updateOperation($id, $name, $checks, $operation);
91
+            $operation = $this->prepareOperation($operation);
92
+            return new JSONResponse($operation);
93
+        } catch (\UnexpectedValueException $e) {
94
+            return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST);
95
+        }
96
+    }
97 97
 
98
-	/**
99
-	 * @PasswordConfirmationRequired
100
-	 *
101
-	 * @param int $id
102
-	 * @return JSONResponse
103
-	 */
104
-	public function deleteOperation($id) {
105
-		$deleted = $this->manager->deleteOperation((int) $id);
106
-		return new JSONResponse($deleted);
107
-	}
98
+    /**
99
+     * @PasswordConfirmationRequired
100
+     *
101
+     * @param int $id
102
+     * @return JSONResponse
103
+     */
104
+    public function deleteOperation($id) {
105
+        $deleted = $this->manager->deleteOperation((int) $id);
106
+        return new JSONResponse($deleted);
107
+    }
108 108
 
109
-	/**
110
-	 * @param array $operation
111
-	 * @return array
112
-	 */
113
-	protected function prepareOperation(array $operation) {
114
-		$checkIds = json_decode($operation['checks']);
115
-		$checks = $this->manager->getChecks($checkIds);
109
+    /**
110
+     * @param array $operation
111
+     * @return array
112
+     */
113
+    protected function prepareOperation(array $operation) {
114
+        $checkIds = json_decode($operation['checks']);
115
+        $checks = $this->manager->getChecks($checkIds);
116 116
 
117
-		$operation['checks'] = [];
118
-		foreach ($checks as $check) {
119
-			// Remove internal values
120
-			unset($check['id']);
121
-			unset($check['hash']);
117
+        $operation['checks'] = [];
118
+        foreach ($checks as $check) {
119
+            // Remove internal values
120
+            unset($check['id']);
121
+            unset($check['hash']);
122 122
 
123
-			$operation['checks'][] = $check;
124
-		}
123
+            $operation['checks'][] = $check;
124
+        }
125 125
 
126
-		return $operation;
127
-	}
126
+        return $operation;
127
+    }
128 128
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Settings/Section.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -28,45 +28,45 @@
 block discarded – undo
28 28
 use OCP\Settings\IIconSection;
29 29
 
30 30
 class Section implements IIconSection {
31
-	/** @var IL10N */
32
-	private $l;
33
-	/** @var IURLGenerator */
34
-	private $url;
31
+    /** @var IL10N */
32
+    private $l;
33
+    /** @var IURLGenerator */
34
+    private $url;
35 35
 
36
-	/**
37
-	 * @param IURLGenerator $url
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IURLGenerator $url, IL10N $l) {
41
-		$this->url = $url;
42
-		$this->l = $l;
43
-	}
36
+    /**
37
+     * @param IURLGenerator $url
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IURLGenerator $url, IL10N $l) {
41
+        $this->url = $url;
42
+        $this->l = $l;
43
+    }
44 44
 
45
-	/**
46
-	 * {@inheritdoc}
47
-	 */
48
-	public function getID() {
49
-		return 'workflow';
50
-	}
45
+    /**
46
+     * {@inheritdoc}
47
+     */
48
+    public function getID() {
49
+        return 'workflow';
50
+    }
51 51
 
52
-	/**
53
-	 * {@inheritdoc}
54
-	 */
55
-	public function getName() {
56
-		return $this->l->t('Workflow');
57
-	}
52
+    /**
53
+     * {@inheritdoc}
54
+     */
55
+    public function getName() {
56
+        return $this->l->t('Workflow');
57
+    }
58 58
 
59
-	/**
60
-	 * {@inheritdoc}
61
-	 */
62
-	public function getPriority() {
63
-		return 55;
64
-	}
59
+    /**
60
+     * {@inheritdoc}
61
+     */
62
+    public function getPriority() {
63
+        return 55;
64
+    }
65 65
 
66
-	/**
67
-	 * {@inheritdoc}
68
-	 */
69
-	public function getIcon() {
70
-		return $this->url->imagePath('core', 'actions/tag.svg');
71
-	}
66
+    /**
67
+     * {@inheritdoc}
68
+     */
69
+    public function getIcon() {
70
+        return $this->url->imagePath('core', 'actions/tag.svg');
71
+    }
72 72
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/AbstractStringCheck.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -28,94 +28,94 @@
 block discarded – undo
28 28
 
29 29
 abstract class AbstractStringCheck implements ICheck {
30 30
 
31
-	/** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */
32
-	protected $matches;
31
+    /** @var array[] Nested array: [Pattern => [ActualValue => Regex Result]] */
32
+    protected $matches;
33 33
 
34
-	/** @var IL10N */
35
-	protected $l;
34
+    /** @var IL10N */
35
+    protected $l;
36 36
 
37
-	/**
38
-	 * @param IL10N $l
39
-	 */
40
-	public function __construct(IL10N $l) {
41
-		$this->l = $l;
42
-	}
37
+    /**
38
+     * @param IL10N $l
39
+     */
40
+    public function __construct(IL10N $l) {
41
+        $this->l = $l;
42
+    }
43 43
 
44
-	/**
45
-	 * @param IStorage $storage
46
-	 * @param string $path
47
-	 */
48
-	public function setFileInfo(IStorage $storage, $path) {
49
-		// Nothing changes here with a different path
50
-	}
44
+    /**
45
+     * @param IStorage $storage
46
+     * @param string $path
47
+     */
48
+    public function setFileInfo(IStorage $storage, $path) {
49
+        // Nothing changes here with a different path
50
+    }
51 51
 
52
-	/**
53
-	 * @return string
54
-	 */
55
-	abstract protected function getActualValue();
52
+    /**
53
+     * @return string
54
+     */
55
+    abstract protected function getActualValue();
56 56
 
57
-	/**
58
-	 * @param string $operator
59
-	 * @param string $value
60
-	 * @return bool
61
-	 */
62
-	public function executeCheck($operator, $value)  {
63
-		$actualValue = $this->getActualValue();
64
-		return $this->executeStringCheck($operator, $value, $actualValue);
65
-	}
57
+    /**
58
+     * @param string $operator
59
+     * @param string $value
60
+     * @return bool
61
+     */
62
+    public function executeCheck($operator, $value)  {
63
+        $actualValue = $this->getActualValue();
64
+        return $this->executeStringCheck($operator, $value, $actualValue);
65
+    }
66 66
 
67
-	/**
68
-	 * @param string $operator
69
-	 * @param string $checkValue
70
-	 * @param string $actualValue
71
-	 * @return bool
72
-	 */
73
-	protected function executeStringCheck($operator, $checkValue, $actualValue) {
74
-		if ($operator === 'is') {
75
-			return $checkValue === $actualValue;
76
-		} else if ($operator === '!is') {
77
-			return $checkValue !== $actualValue;
78
-		} else {
79
-			$match = $this->match($checkValue, $actualValue);
80
-			if ($operator === 'matches') {
81
-				return $match === 1;
82
-			} else {
83
-				return $match === 0;
84
-			}
85
-		}
86
-	}
67
+    /**
68
+     * @param string $operator
69
+     * @param string $checkValue
70
+     * @param string $actualValue
71
+     * @return bool
72
+     */
73
+    protected function executeStringCheck($operator, $checkValue, $actualValue) {
74
+        if ($operator === 'is') {
75
+            return $checkValue === $actualValue;
76
+        } else if ($operator === '!is') {
77
+            return $checkValue !== $actualValue;
78
+        } else {
79
+            $match = $this->match($checkValue, $actualValue);
80
+            if ($operator === 'matches') {
81
+                return $match === 1;
82
+            } else {
83
+                return $match === 0;
84
+            }
85
+        }
86
+    }
87 87
 
88
-	/**
89
-	 * @param string $operator
90
-	 * @param string $value
91
-	 * @throws \UnexpectedValueException
92
-	 */
93
-	public function validateCheck($operator, $value) {
94
-		if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) {
95
-			throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
96
-		}
88
+    /**
89
+     * @param string $operator
90
+     * @param string $value
91
+     * @throws \UnexpectedValueException
92
+     */
93
+    public function validateCheck($operator, $value) {
94
+        if (!in_array($operator, ['is', '!is', 'matches', '!matches'])) {
95
+            throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
96
+        }
97 97
 
98
-		if (in_array($operator, ['matches', '!matches']) &&
99
-			  @preg_match($value, null) === false) {
100
-			throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2);
101
-		}
102
-	}
98
+        if (in_array($operator, ['matches', '!matches']) &&
99
+              @preg_match($value, null) === false) {
100
+            throw new \UnexpectedValueException($this->l->t('The given regular expression is invalid'), 2);
101
+        }
102
+    }
103 103
 
104
-	/**
105
-	 * @param string $pattern
106
-	 * @param string $subject
107
-	 * @return int|bool
108
-	 */
109
-	protected function match($pattern, $subject) {
110
-		$patternHash = md5($pattern);
111
-		$subjectHash = md5($subject);
112
-		if (isset($this->matches[$patternHash][$subjectHash])) {
113
-			return $this->matches[$patternHash][$subjectHash];
114
-		}
115
-		if (!isset($this->matches[$patternHash])) {
116
-			$this->matches[$patternHash] = [];
117
-		}
118
-		$this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject);
119
-		return $this->matches[$patternHash][$subjectHash];
120
-	}
104
+    /**
105
+     * @param string $pattern
106
+     * @param string $subject
107
+     * @return int|bool
108
+     */
109
+    protected function match($pattern, $subject) {
110
+        $patternHash = md5($pattern);
111
+        $subjectHash = md5($subject);
112
+        if (isset($this->matches[$patternHash][$subjectHash])) {
113
+            return $this->matches[$patternHash][$subjectHash];
114
+        }
115
+        if (!isset($this->matches[$patternHash])) {
116
+            $this->matches[$patternHash] = [];
117
+        }
118
+        $this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject);
119
+        return $this->matches[$patternHash][$subjectHash];
120
+    }
121 121
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/FileSize.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -30,90 +30,90 @@
 block discarded – undo
30 30
 
31 31
 class FileSize implements ICheck {
32 32
 
33
-	/** @var int */
34
-	protected $size;
35
-
36
-	/** @var IL10N */
37
-	protected $l;
38
-
39
-	/** @var IRequest */
40
-	protected $request;
41
-
42
-	/**
43
-	 * @param IL10N $l
44
-	 * @param IRequest $request
45
-	 */
46
-	public function __construct(IL10N $l, IRequest $request) {
47
-		$this->l = $l;
48
-		$this->request = $request;
49
-	}
50
-
51
-	/**
52
-	 * @param IStorage $storage
53
-	 * @param string $path
54
-	 */
55
-	public function setFileInfo(IStorage $storage, $path) {
56
-	}
57
-
58
-	/**
59
-	 * @param string $operator
60
-	 * @param string $value
61
-	 * @return bool
62
-	 */
63
-	public function executeCheck($operator, $value) {
64
-		$size = $this->getFileSizeFromHeader();
65
-
66
-		$value = Util::computerFileSize($value);
67
-		if ($size !== false) {
68
-			switch ($operator) {
69
-				case 'less':
70
-					return $size < $value;
71
-				case '!less':
72
-					return $size >= $value;
73
-				case 'greater':
74
-					return $size > $value;
75
-				case '!greater':
76
-					return $size <= $value;
77
-			}
78
-		}
79
-		return false;
80
-	}
81
-
82
-	/**
83
-	 * @param string $operator
84
-	 * @param string $value
85
-	 * @throws \UnexpectedValueException
86
-	 */
87
-	public function validateCheck($operator, $value) {
88
-		if (!in_array($operator, ['less', '!less', 'greater', '!greater'])) {
89
-			throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
90
-		}
91
-
92
-		if (!preg_match('/^[0-9]+[ ]?[kmgt]?b$/i', $value)) {
93
-			throw new \UnexpectedValueException($this->l->t('The given file size is invalid'), 2);
94
-		}
95
-	}
96
-
97
-	/**
98
-	 * @return string
99
-	 */
100
-	protected function getFileSizeFromHeader() {
101
-		if ($this->size !== null) {
102
-			return $this->size;
103
-		}
104
-
105
-		$size = $this->request->getHeader('OC-Total-Length');
106
-		if ($size === null) {
107
-			if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
108
-				$size = $this->request->getHeader('Content-Length');
109
-			}
110
-		}
111
-
112
-		if ($size === null) {
113
-			$size = false;
114
-		}
115
-
116
-		$this->size = $size;
117
-		return $this->size;
118
-	}
33
+    /** @var int */
34
+    protected $size;
35
+
36
+    /** @var IL10N */
37
+    protected $l;
38
+
39
+    /** @var IRequest */
40
+    protected $request;
41
+
42
+    /**
43
+     * @param IL10N $l
44
+     * @param IRequest $request
45
+     */
46
+    public function __construct(IL10N $l, IRequest $request) {
47
+        $this->l = $l;
48
+        $this->request = $request;
49
+    }
50
+
51
+    /**
52
+     * @param IStorage $storage
53
+     * @param string $path
54
+     */
55
+    public function setFileInfo(IStorage $storage, $path) {
56
+    }
57
+
58
+    /**
59
+     * @param string $operator
60
+     * @param string $value
61
+     * @return bool
62
+     */
63
+    public function executeCheck($operator, $value) {
64
+        $size = $this->getFileSizeFromHeader();
65
+
66
+        $value = Util::computerFileSize($value);
67
+        if ($size !== false) {
68
+            switch ($operator) {
69
+                case 'less':
70
+                    return $size < $value;
71
+                case '!less':
72
+                    return $size >= $value;
73
+                case 'greater':
74
+                    return $size > $value;
75
+                case '!greater':
76
+                    return $size <= $value;
77
+            }
78
+        }
79
+        return false;
80
+    }
81
+
82
+    /**
83
+     * @param string $operator
84
+     * @param string $value
85
+     * @throws \UnexpectedValueException
86
+     */
87
+    public function validateCheck($operator, $value) {
88
+        if (!in_array($operator, ['less', '!less', 'greater', '!greater'])) {
89
+            throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
90
+        }
91
+
92
+        if (!preg_match('/^[0-9]+[ ]?[kmgt]?b$/i', $value)) {
93
+            throw new \UnexpectedValueException($this->l->t('The given file size is invalid'), 2);
94
+        }
95
+    }
96
+
97
+    /**
98
+     * @return string
99
+     */
100
+    protected function getFileSizeFromHeader() {
101
+        if ($this->size !== null) {
102
+            return $this->size;
103
+        }
104
+
105
+        $size = $this->request->getHeader('OC-Total-Length');
106
+        if ($size === null) {
107
+            if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
108
+                $size = $this->request->getHeader('Content-Length');
109
+            }
110
+        }
111
+
112
+        if ($size === null) {
113
+            $size = false;
114
+        }
115
+
116
+        $this->size = $size;
117
+        return $this->size;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/RequestTime.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -29,101 +29,101 @@
 block discarded – undo
29 29
 
30 30
 class RequestTime implements ICheck {
31 31
 
32
-	const REGEX_TIME = '([0-1][0-9]|2[0-3]):([0-5][0-9])';
33
-	const REGEX_TIMEZONE = '([a-zA-Z]+(?:\\/[a-zA-Z\-\_]+)+)';
34
-
35
-	/** @var bool[] */
36
-	protected $cachedResults;
37
-
38
-	/** @var IL10N */
39
-	protected $l;
40
-
41
-	/** @var ITimeFactory */
42
-	protected $timeFactory;
43
-
44
-	/**
45
-	 * @param ITimeFactory $timeFactory
46
-	 */
47
-	public function __construct(IL10N $l, ITimeFactory $timeFactory) {
48
-		$this->l = $l;
49
-		$this->timeFactory = $timeFactory;
50
-	}
51
-
52
-	/**
53
-	 * @param IStorage $storage
54
-	 * @param string $path
55
-	 */
56
-	public function setFileInfo(IStorage $storage, $path) {
57
-		// A different path doesn't change time, so nothing to do here.
58
-	}
59
-
60
-	/**
61
-	 * @param string $operator
62
-	 * @param string $value
63
-	 * @return bool
64
-	 */
65
-	public function executeCheck($operator, $value) {
66
-		$valueHash = md5($value);
67
-
68
-		if (isset($this->cachedResults[$valueHash])) {
69
-			return $this->cachedResults[$valueHash];
70
-		}
71
-
72
-		$timestamp = $this->timeFactory->getTime();
73
-
74
-		$values = json_decode($value, true);
75
-		$timestamp1 = $this->getTimestamp($timestamp, $values[0]);
76
-		$timestamp2 = $this->getTimestamp($timestamp, $values[1]);
77
-
78
-		if ($timestamp1 < $timestamp2) {
79
-			$in = $timestamp1 <= $timestamp && $timestamp <= $timestamp2;
80
-		} else {
81
-			$in = $timestamp1 <= $timestamp || $timestamp <= $timestamp2;
82
-		}
83
-
84
-		return ($operator === 'in') ? $in : !$in;
85
-	}
86
-
87
-	/**
88
-	 * @param int $currentTimestamp
89
-	 * @param string $value Format: "H:i e"
90
-	 * @return int
91
-	 */
92
-	protected function getTimestamp($currentTimestamp, $value) {
93
-		list($time1, $timezone1) = explode(' ', $value);
94
-		list($hour1, $minute1) = explode(':', $time1);
95
-		$date1 = new \DateTime('now', new \DateTimeZone($timezone1));
96
-		$date1->setTimestamp($currentTimestamp);
97
-		$date1->setTime($hour1, $minute1);
98
-
99
-		return $date1->getTimestamp();
100
-	}
101
-
102
-	/**
103
-	 * @param string $operator
104
-	 * @param string $value
105
-	 * @throws \UnexpectedValueException
106
-	 */
107
-	public function validateCheck($operator, $value) {
108
-		if (!in_array($operator, ['in', '!in'])) {
109
-			throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
110
-		}
111
-
112
-		$regexValue = '\"' . self::REGEX_TIME . ' ' . self::REGEX_TIMEZONE . '\"';
113
-		$result = preg_match('/^\[' . $regexValue . ',' . $regexValue . '\]$/', $value, $matches);
114
-		if (!$result) {
115
-			throw new \UnexpectedValueException($this->l->t('The given time span is invalid'), 2);
116
-		}
117
-
118
-		$values = json_decode($value, true);
119
-		$time1 = \DateTime::createFromFormat('H:i e', $values[0]);
120
-		if ($time1 === false) {
121
-			throw new \UnexpectedValueException($this->l->t('The given start time is invalid'), 3);
122
-		}
123
-
124
-		$time2 = \DateTime::createFromFormat('H:i e', $values[1]);
125
-		if ($time2 === false) {
126
-			throw new \UnexpectedValueException($this->l->t('The given end time is invalid'), 4);
127
-		}
128
-	}
32
+    const REGEX_TIME = '([0-1][0-9]|2[0-3]):([0-5][0-9])';
33
+    const REGEX_TIMEZONE = '([a-zA-Z]+(?:\\/[a-zA-Z\-\_]+)+)';
34
+
35
+    /** @var bool[] */
36
+    protected $cachedResults;
37
+
38
+    /** @var IL10N */
39
+    protected $l;
40
+
41
+    /** @var ITimeFactory */
42
+    protected $timeFactory;
43
+
44
+    /**
45
+     * @param ITimeFactory $timeFactory
46
+     */
47
+    public function __construct(IL10N $l, ITimeFactory $timeFactory) {
48
+        $this->l = $l;
49
+        $this->timeFactory = $timeFactory;
50
+    }
51
+
52
+    /**
53
+     * @param IStorage $storage
54
+     * @param string $path
55
+     */
56
+    public function setFileInfo(IStorage $storage, $path) {
57
+        // A different path doesn't change time, so nothing to do here.
58
+    }
59
+
60
+    /**
61
+     * @param string $operator
62
+     * @param string $value
63
+     * @return bool
64
+     */
65
+    public function executeCheck($operator, $value) {
66
+        $valueHash = md5($value);
67
+
68
+        if (isset($this->cachedResults[$valueHash])) {
69
+            return $this->cachedResults[$valueHash];
70
+        }
71
+
72
+        $timestamp = $this->timeFactory->getTime();
73
+
74
+        $values = json_decode($value, true);
75
+        $timestamp1 = $this->getTimestamp($timestamp, $values[0]);
76
+        $timestamp2 = $this->getTimestamp($timestamp, $values[1]);
77
+
78
+        if ($timestamp1 < $timestamp2) {
79
+            $in = $timestamp1 <= $timestamp && $timestamp <= $timestamp2;
80
+        } else {
81
+            $in = $timestamp1 <= $timestamp || $timestamp <= $timestamp2;
82
+        }
83
+
84
+        return ($operator === 'in') ? $in : !$in;
85
+    }
86
+
87
+    /**
88
+     * @param int $currentTimestamp
89
+     * @param string $value Format: "H:i e"
90
+     * @return int
91
+     */
92
+    protected function getTimestamp($currentTimestamp, $value) {
93
+        list($time1, $timezone1) = explode(' ', $value);
94
+        list($hour1, $minute1) = explode(':', $time1);
95
+        $date1 = new \DateTime('now', new \DateTimeZone($timezone1));
96
+        $date1->setTimestamp($currentTimestamp);
97
+        $date1->setTime($hour1, $minute1);
98
+
99
+        return $date1->getTimestamp();
100
+    }
101
+
102
+    /**
103
+     * @param string $operator
104
+     * @param string $value
105
+     * @throws \UnexpectedValueException
106
+     */
107
+    public function validateCheck($operator, $value) {
108
+        if (!in_array($operator, ['in', '!in'])) {
109
+            throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
110
+        }
111
+
112
+        $regexValue = '\"' . self::REGEX_TIME . ' ' . self::REGEX_TIMEZONE . '\"';
113
+        $result = preg_match('/^\[' . $regexValue . ',' . $regexValue . '\]$/', $value, $matches);
114
+        if (!$result) {
115
+            throw new \UnexpectedValueException($this->l->t('The given time span is invalid'), 2);
116
+        }
117
+
118
+        $values = json_decode($value, true);
119
+        $time1 = \DateTime::createFromFormat('H:i e', $values[0]);
120
+        if ($time1 === false) {
121
+            throw new \UnexpectedValueException($this->l->t('The given start time is invalid'), 3);
122
+        }
123
+
124
+        $time2 = \DateTime::createFromFormat('H:i e', $values[1]);
125
+        if ($time2 === false) {
126
+            throw new \UnexpectedValueException($this->l->t('The given end time is invalid'), 4);
127
+        }
128
+    }
129 129
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/UserGroupMembership.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -31,84 +31,84 @@
 block discarded – undo
31 31
 
32 32
 class UserGroupMembership implements ICheck {
33 33
 
34
-	/** @var string */
35
-	protected $cachedUser;
36
-
37
-	/** @var string[] */
38
-	protected $cachedGroupMemberships;
39
-
40
-	/** @var IUserSession */
41
-	protected $userSession;
42
-
43
-	/** @var IGroupManager */
44
-	protected $groupManager;
45
-
46
-	/** @var IL10N */
47
-	protected $l;
48
-
49
-	/**
50
-	 * @param IUserSession $userSession
51
-	 * @param IGroupManager $groupManager
52
-	 * @param IL10N $l
53
-	 */
54
-	public function __construct(IUserSession $userSession, IGroupManager $groupManager, IL10N $l) {
55
-		$this->userSession = $userSession;
56
-		$this->groupManager = $groupManager;
57
-		$this->l = $l;
58
-	}
59
-
60
-	/**
61
-	 * @param IStorage $storage
62
-	 * @param string $path
63
-	 */
64
-	public function setFileInfo(IStorage $storage, $path) {
65
-		// A different path doesn't change group memberships, so nothing to do here.
66
-	}
67
-
68
-	/**
69
-	 * @param string $operator
70
-	 * @param string $value
71
-	 * @return bool
72
-	 */
73
-	public function executeCheck($operator, $value) {
74
-		$user = $this->userSession->getUser();
75
-
76
-		if ($user instanceof IUser) {
77
-			$groupIds = $this->getUserGroups($user);
78
-			return ($operator === 'is') === in_array($value, $groupIds);
79
-		} else {
80
-			return $operator !== 'is';
81
-		}
82
-	}
83
-
84
-
85
-	/**
86
-	 * @param string $operator
87
-	 * @param string $value
88
-	 * @throws \UnexpectedValueException
89
-	 */
90
-	public function validateCheck($operator, $value) {
91
-		if (!in_array($operator, ['is', '!is'])) {
92
-			throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
93
-		}
94
-
95
-		if (!$this->groupManager->groupExists($value)) {
96
-			throw new \UnexpectedValueException($this->l->t('The given group does not exist'), 2);
97
-		}
98
-	}
99
-
100
-	/**
101
-	 * @param IUser $user
102
-	 * @return string[]
103
-	 */
104
-	protected function getUserGroups(IUser $user) {
105
-		$uid = $user->getUID();
106
-
107
-		if ($this->cachedUser !== $uid) {
108
-			$this->cachedUser = $uid;
109
-			$this->cachedGroupMemberships = $this->groupManager->getUserGroupIds($user);
110
-		}
111
-
112
-		return $this->cachedGroupMemberships;
113
-	}
34
+    /** @var string */
35
+    protected $cachedUser;
36
+
37
+    /** @var string[] */
38
+    protected $cachedGroupMemberships;
39
+
40
+    /** @var IUserSession */
41
+    protected $userSession;
42
+
43
+    /** @var IGroupManager */
44
+    protected $groupManager;
45
+
46
+    /** @var IL10N */
47
+    protected $l;
48
+
49
+    /**
50
+     * @param IUserSession $userSession
51
+     * @param IGroupManager $groupManager
52
+     * @param IL10N $l
53
+     */
54
+    public function __construct(IUserSession $userSession, IGroupManager $groupManager, IL10N $l) {
55
+        $this->userSession = $userSession;
56
+        $this->groupManager = $groupManager;
57
+        $this->l = $l;
58
+    }
59
+
60
+    /**
61
+     * @param IStorage $storage
62
+     * @param string $path
63
+     */
64
+    public function setFileInfo(IStorage $storage, $path) {
65
+        // A different path doesn't change group memberships, so nothing to do here.
66
+    }
67
+
68
+    /**
69
+     * @param string $operator
70
+     * @param string $value
71
+     * @return bool
72
+     */
73
+    public function executeCheck($operator, $value) {
74
+        $user = $this->userSession->getUser();
75
+
76
+        if ($user instanceof IUser) {
77
+            $groupIds = $this->getUserGroups($user);
78
+            return ($operator === 'is') === in_array($value, $groupIds);
79
+        } else {
80
+            return $operator !== 'is';
81
+        }
82
+    }
83
+
84
+
85
+    /**
86
+     * @param string $operator
87
+     * @param string $value
88
+     * @throws \UnexpectedValueException
89
+     */
90
+    public function validateCheck($operator, $value) {
91
+        if (!in_array($operator, ['is', '!is'])) {
92
+            throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
93
+        }
94
+
95
+        if (!$this->groupManager->groupExists($value)) {
96
+            throw new \UnexpectedValueException($this->l->t('The given group does not exist'), 2);
97
+        }
98
+    }
99
+
100
+    /**
101
+     * @param IUser $user
102
+     * @return string[]
103
+     */
104
+    protected function getUserGroups(IUser $user) {
105
+        $uid = $user->getUID();
106
+
107
+        if ($this->cachedUser !== $uid) {
108
+            $this->cachedUser = $uid;
109
+            $this->cachedGroupMemberships = $this->groupManager->getUserGroupIds($user);
110
+        }
111
+
112
+        return $this->cachedGroupMemberships;
113
+    }
114 114
 }
Please login to merge, or discard this patch.