1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Activities App |
5
|
|
|
* |
6
|
|
|
* @author Frank Karlitschek, Joas Schilling |
7
|
|
|
* @copyright 2013 Frank Karlitschek [email protected] |
8
|
|
|
* |
9
|
|
|
* This library is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
11
|
|
|
* License as published by the Free Software Foundation; either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* This library is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public |
20
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Activity; |
24
|
|
|
|
25
|
|
|
use OC\Files\Filesystem; |
26
|
|
|
use OC\Files\View; |
27
|
|
|
use OCA\Activity\Extension\Files; |
28
|
|
|
use OCA\Activity\Extension\Files_Sharing; |
29
|
|
|
use OCP\Activity\IManager; |
30
|
|
|
use OCP\Files\Mount\IMountPoint; |
31
|
|
|
use OCP\IDBConnection; |
32
|
|
|
use OCP\IGroupManager; |
33
|
|
|
use OCP\Share; |
34
|
|
|
use OCP\Util; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The class to handle the filesystem hooks |
38
|
|
|
*/ |
39
|
|
|
class FilesHooks { |
40
|
|
|
|
41
|
|
|
/** @var \OCP\Activity\IManager */ |
42
|
|
|
protected $manager; |
43
|
|
|
|
44
|
|
|
/** @var \OCA\Activity\Data */ |
45
|
|
|
protected $activityData; |
46
|
|
|
|
47
|
|
|
/** @var \OCA\Activity\UserSettings */ |
48
|
|
|
protected $userSettings; |
49
|
|
|
|
50
|
|
|
/** @var \OCP\IGroupManager */ |
51
|
|
|
protected $groupManager; |
52
|
|
|
|
53
|
|
|
/** @var \OCP\IDBConnection */ |
54
|
|
|
protected $connection; |
55
|
|
|
|
56
|
|
|
/** @var \OC\Files\View */ |
57
|
|
|
protected $view; |
58
|
|
|
|
59
|
|
|
/** @var string|false */ |
60
|
|
|
protected $currentUser; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Constructor |
64
|
|
|
* |
65
|
|
|
* @param IManager $manager |
66
|
|
|
* @param Data $activityData |
67
|
|
|
* @param UserSettings $userSettings |
68
|
|
|
* @param IGroupManager $groupManager |
69
|
|
|
* @param View $view |
70
|
|
|
* @param IDBConnection $connection |
71
|
|
|
* @param string|false $currentUser |
72
|
|
|
*/ |
73
|
46 |
|
public function __construct(IManager $manager, Data $activityData, UserSettings $userSettings, IGroupManager $groupManager, View $view, IDBConnection $connection, $currentUser) { |
74
|
46 |
|
$this->manager = $manager; |
75
|
46 |
|
$this->activityData = $activityData; |
76
|
46 |
|
$this->userSettings = $userSettings; |
77
|
46 |
|
$this->groupManager = $groupManager; |
78
|
46 |
|
$this->view = $view; |
79
|
46 |
|
$this->connection = $connection; |
80
|
46 |
|
$this->currentUser = $currentUser; |
81
|
46 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string|false Current UserID if logged in, false otherwise |
85
|
|
|
*/ |
86
|
2 |
|
protected function getCurrentUser() { |
87
|
2 |
|
return $this->currentUser; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Store the create hook events |
92
|
|
|
* @param string $path Path of the file that has been created |
93
|
|
|
*/ |
94
|
2 |
|
public function fileCreate($path) { |
95
|
2 |
|
if ($this->getCurrentUser() !== false) { |
96
|
1 |
|
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by'); |
97
|
1 |
|
} else { |
98
|
1 |
|
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, '', 'created_public'); |
99
|
|
|
} |
100
|
2 |
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Store the update hook events |
104
|
|
|
* @param string $path Path of the file that has been modified |
105
|
|
|
*/ |
106
|
1 |
|
public function fileUpdate($path) { |
107
|
1 |
|
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CHANGED, 'changed_self', 'changed_by'); |
108
|
1 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Store the delete hook events |
112
|
|
|
* @param string $path Path of the file that has been deleted |
113
|
|
|
*/ |
114
|
1 |
|
public function fileDelete($path) { |
115
|
1 |
|
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_DELETED, 'deleted_self', 'deleted_by'); |
116
|
1 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Store the restore hook events |
120
|
|
|
* @param string $path Path of the file that has been restored |
121
|
|
|
*/ |
122
|
1 |
|
public function fileRestore($path) { |
123
|
1 |
|
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_RESTORED, 'restored_self', 'restored_by'); |
124
|
1 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Creates the entries for file actions on $file_path |
128
|
|
|
* |
129
|
|
|
* @param string $filePath The file that is being changed |
130
|
|
|
* @param int $activityType The activity type |
131
|
|
|
* @param string $subject The subject for the actor |
132
|
|
|
* @param string $subjectBy The subject for other users (with "by $actor") |
133
|
|
|
*/ |
134
|
3 |
|
protected function addNotificationsForFileAction($filePath, $activityType, $subject, $subjectBy) { |
135
|
|
|
// Do not add activities for .part-files |
136
|
3 |
|
if (substr($filePath, -5) === '.part') { |
137
|
1 |
|
return; |
138
|
|
|
} |
139
|
|
|
|
140
|
2 |
|
list($filePath, $uidOwner, $fileId) = $this->getSourcePathAndOwner($filePath); |
141
|
2 |
|
$affectedUsers = $this->getUserPathsFromPath($filePath, $uidOwner); |
142
|
2 |
|
$filteredStreamUsers = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'stream', $activityType); |
143
|
2 |
|
$filteredEmailUsers = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'email', $activityType); |
144
|
|
|
|
145
|
2 |
|
foreach ($affectedUsers as $user => $path) { |
146
|
2 |
|
if (empty($filteredStreamUsers[$user]) && empty($filteredEmailUsers[$user])) { |
147
|
2 |
|
continue; |
148
|
|
|
} |
149
|
|
|
|
150
|
2 |
|
if ($user === $this->currentUser) { |
151
|
1 |
|
$userSubject = $subject; |
152
|
1 |
|
$userParams = array($path); |
153
|
1 |
|
} else { |
154
|
1 |
|
$userSubject = $subjectBy; |
155
|
1 |
|
$userParams = array($path, $this->currentUser); |
156
|
|
|
} |
157
|
|
|
|
158
|
2 |
|
$this->addNotificationsForUser( |
159
|
2 |
|
$user, $userSubject, $userParams, |
160
|
2 |
|
$fileId, $path, true, |
161
|
2 |
|
!empty($filteredStreamUsers[$user]), |
162
|
2 |
|
!empty($filteredEmailUsers[$user]) ? $filteredEmailUsers[$user] : 0, |
163
|
|
|
$activityType |
164
|
2 |
|
); |
165
|
2 |
|
} |
166
|
2 |
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns a "username => path" map for all affected users |
170
|
|
|
* |
171
|
|
|
* @param string $path |
172
|
|
|
* @param string $uidOwner |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
|
protected function getUserPathsFromPath($path, $uidOwner) { |
176
|
|
|
return Share::getUsersSharingFile($path, $uidOwner, true, true); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Return the source |
181
|
|
|
* |
182
|
|
|
* @param string $path |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
protected function getSourcePathAndOwner($path) { |
186
|
|
|
$uidOwner = Filesystem::getOwner($path); |
187
|
|
|
$fileId = 0; |
188
|
|
|
|
189
|
|
|
if ($uidOwner !== $this->currentUser) { |
190
|
|
|
Filesystem::initMountPoints($uidOwner); |
191
|
|
|
} |
192
|
|
|
$info = Filesystem::getFileInfo($path); |
193
|
|
|
if ($info !== false) { |
194
|
|
|
$ownerView = new View('/' . $uidOwner . '/files'); |
195
|
|
|
$fileId = (int) $info['fileid']; |
196
|
|
|
$path = $ownerView->getPath($fileId); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return array($path, $uidOwner, $fileId); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Manage sharing events |
204
|
|
|
* @param array $params The hook params |
205
|
|
|
*/ |
206
|
3 |
|
public function share($params) { |
207
|
3 |
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
208
|
3 |
|
if ($params['shareWith']) { |
209
|
2 |
|
if ((int) $params['shareType'] === Share::SHARE_TYPE_USER) { |
210
|
1 |
|
$this->shareFileOrFolderWithUser($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget']); |
211
|
2 |
|
} else if ((int) $params['shareType'] === Share::SHARE_TYPE_GROUP) { |
212
|
1 |
|
$this->shareFileOrFolderWithGroup($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], (int) $params['id']); |
213
|
1 |
|
} |
214
|
2 |
|
} else { |
215
|
1 |
|
$this->shareFileOrFolder((int) $params['fileSource'], $params['itemType']); |
216
|
|
|
} |
217
|
3 |
|
} |
218
|
3 |
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Sharing a file or folder with a user |
222
|
|
|
* |
223
|
|
|
* @param string $shareWith |
224
|
|
|
* @param int $fileSource File ID that is being shared |
225
|
|
|
* @param string $itemType File type that is being shared (file or folder) |
226
|
|
|
* @param string $fileTarget File path |
227
|
|
|
*/ |
228
|
2 |
|
protected function shareFileOrFolderWithUser($shareWith, $fileSource, $itemType, $fileTarget) { |
229
|
|
|
// User performing the share |
230
|
2 |
|
$this->shareNotificationForSharer('shared_user_self', $shareWith, $fileSource, $itemType); |
231
|
2 |
|
$this->shareNotificationForOriginalOwners($this->currentUser, 'reshared_user_by', $shareWith, $fileSource, $itemType); |
|
|
|
|
232
|
|
|
|
233
|
|
|
// New shared user |
234
|
2 |
|
$this->addNotificationsForUser( |
235
|
2 |
|
$shareWith, 'shared_with_by', array($fileTarget, $this->currentUser), |
236
|
2 |
|
(int) $fileSource, $fileTarget, ($itemType === 'file'), |
237
|
2 |
|
$this->userSettings->getUserSetting($shareWith, 'stream', Files_Sharing::TYPE_SHARED), |
238
|
2 |
|
$this->userSettings->getUserSetting($shareWith, 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($shareWith, 'setting', 'batchtime') : 0 |
239
|
2 |
|
); |
240
|
2 |
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Sharing a file or folder with a group |
244
|
|
|
* |
245
|
|
|
* @param string $shareWith |
246
|
|
|
* @param int $fileSource File ID that is being shared |
247
|
|
|
* @param string $itemType File type that is being shared (file or folder) |
248
|
|
|
* @param string $fileTarget File path |
249
|
|
|
* @param int $shareId The Share ID of this share |
250
|
|
|
*/ |
251
|
5 |
|
protected function shareFileOrFolderWithGroup($shareWith, $fileSource, $itemType, $fileTarget, $shareId) { |
252
|
|
|
// Members of the new group |
253
|
5 |
|
$affectedUsers = array(); |
254
|
5 |
|
$group = $this->groupManager->get($shareWith); |
255
|
5 |
|
if (!($group instanceof \OCP\IGroup)) { |
|
|
|
|
256
|
1 |
|
return; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
// User performing the share |
260
|
4 |
|
$this->shareNotificationForSharer('shared_group_self', $shareWith, $fileSource, $itemType); |
261
|
4 |
|
$this->shareNotificationForOriginalOwners($this->currentUser, 'reshared_group_by', $shareWith, $fileSource, $itemType); |
|
|
|
|
262
|
|
|
|
263
|
|
|
|
264
|
4 |
|
$usersInGroup = $group->searchUsers(''); |
265
|
4 |
|
foreach ($usersInGroup as $user) { |
266
|
3 |
|
$affectedUsers[$user->getUID()] = $fileTarget; |
267
|
4 |
|
} |
268
|
|
|
|
269
|
|
|
// Remove the triggering user, we already managed his notifications |
270
|
4 |
|
unset($affectedUsers[$this->currentUser]); |
271
|
|
|
|
272
|
4 |
|
if (empty($affectedUsers)) { |
273
|
2 |
|
return; |
274
|
|
|
} |
275
|
|
|
|
276
|
2 |
|
$filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'stream', Files_Sharing::TYPE_SHARED); |
277
|
2 |
|
$filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'email', Files_Sharing::TYPE_SHARED); |
278
|
|
|
|
279
|
2 |
|
$affectedUsers = $this->fixPathsForShareExceptions($affectedUsers, $shareId); |
280
|
2 |
|
foreach ($affectedUsers as $user => $path) { |
281
|
2 |
|
if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) { |
282
|
1 |
|
continue; |
283
|
|
|
} |
284
|
|
|
|
285
|
1 |
|
$this->addNotificationsForUser( |
286
|
1 |
|
$user, 'shared_with_by', array($path, $this->currentUser), |
287
|
1 |
|
$fileSource, $path, ($itemType === 'file'), |
288
|
1 |
|
!empty($filteredStreamUsersInGroup[$user]), |
289
|
1 |
|
!empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0 |
290
|
1 |
|
); |
291
|
2 |
|
} |
292
|
2 |
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Check when there was a naming conflict and the target is different |
296
|
|
|
* for some of the users |
297
|
|
|
* |
298
|
|
|
* @param array $affectedUsers |
299
|
|
|
* @param int $shareId |
300
|
|
|
* @return mixed |
301
|
|
|
*/ |
302
|
|
|
protected function fixPathsForShareExceptions(array $affectedUsers, $shareId) { |
303
|
|
|
$queryBuilder = $this->connection->getQueryBuilder(); |
304
|
|
|
$queryBuilder->select(['share_with', 'file_target']) |
305
|
|
|
->from('share') |
306
|
|
|
->where($queryBuilder->expr()->eq('parent', $queryBuilder->createParameter('parent'))) |
307
|
|
|
->setParameter('parent', (int) $shareId); |
308
|
|
|
$query = $queryBuilder->execute(); |
309
|
|
|
|
310
|
|
|
while ($row = $query->fetch()) { |
311
|
|
|
$affectedUsers[$row['share_with']] = $row['file_target']; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
return $affectedUsers; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Sharing a file or folder via link/public |
319
|
|
|
* |
320
|
|
|
* @param int $fileSource File ID that is being shared |
321
|
|
|
* @param string $itemType File type that is being shared (file or folder) |
322
|
|
|
*/ |
323
|
2 |
|
protected function shareFileOrFolder($fileSource, $itemType) { |
324
|
2 |
|
$this->view->chroot('/' . $this->currentUser . '/files'); |
325
|
2 |
|
$path = $this->view->getPath($fileSource); |
326
|
|
|
|
327
|
2 |
|
if ($path === null) { |
328
|
1 |
|
return; |
329
|
|
|
} |
330
|
|
|
|
331
|
1 |
|
$this->shareNotificationForOriginalOwners($this->currentUser, 'reshared_link_by', '', $fileSource, $itemType); |
|
|
|
|
332
|
|
|
|
333
|
1 |
|
$this->addNotificationsForUser( |
334
|
1 |
|
$this->currentUser, 'shared_link_self', array($path), |
|
|
|
|
335
|
1 |
|
(int) $fileSource, $path, ($itemType === 'file'), |
336
|
1 |
|
$this->userSettings->getUserSetting($this->currentUser, 'stream', Files_Sharing::TYPE_SHARED), |
|
|
|
|
337
|
1 |
|
$this->userSettings->getUserSetting($this->currentUser, 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($this->currentUser, 'setting', 'batchtime') : 0 |
|
|
|
|
338
|
1 |
|
); |
339
|
1 |
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Add notifications for the user that shares a file/folder |
343
|
|
|
* |
344
|
|
|
* @param string $subject |
345
|
|
|
* @param string $shareWith |
346
|
|
|
* @param int $fileSource |
347
|
|
|
* @param string $itemType |
348
|
|
|
*/ |
349
|
2 |
|
protected function shareNotificationForSharer($subject, $shareWith, $fileSource, $itemType) { |
350
|
2 |
|
$this->view->chroot('/' . $this->currentUser . '/files'); |
351
|
2 |
|
$path = $this->view->getPath($fileSource); |
352
|
|
|
|
353
|
2 |
|
if ($path === null) { |
354
|
1 |
|
return; |
355
|
|
|
} |
356
|
|
|
|
357
|
1 |
|
$this->addNotificationsForUser( |
358
|
1 |
|
$this->currentUser, $subject, array($path, $shareWith), |
|
|
|
|
359
|
1 |
|
$fileSource, $path, ($itemType === 'file'), |
360
|
1 |
|
$this->userSettings->getUserSetting($this->currentUser, 'stream', Files_Sharing::TYPE_SHARED), |
|
|
|
|
361
|
1 |
|
$this->userSettings->getUserSetting($this->currentUser, 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($this->currentUser, 'setting', 'batchtime') : 0 |
|
|
|
|
362
|
1 |
|
); |
363
|
1 |
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Add notifications for the user that shares a file/folder |
367
|
|
|
* |
368
|
|
|
* @param string $owner |
369
|
|
|
* @param string $subject |
370
|
|
|
* @param string $shareWith |
371
|
|
|
* @param int $fileSource |
372
|
|
|
* @param string $itemType |
373
|
|
|
*/ |
374
|
2 |
|
protected function reshareNotificationForSharer($owner, $subject, $shareWith, $fileSource, $itemType) { |
375
|
2 |
|
$this->view->chroot('/' . $owner . '/files'); |
376
|
2 |
|
$path = $this->view->getPath($fileSource); |
377
|
|
|
|
378
|
2 |
|
if ($path === null) { |
379
|
1 |
|
return; |
380
|
|
|
} |
381
|
|
|
|
382
|
1 |
|
$this->addNotificationsForUser( |
383
|
1 |
|
$owner, $subject, array($path, $this->currentUser, $shareWith), |
384
|
1 |
|
$fileSource, $path, ($itemType === 'file'), |
385
|
1 |
|
$this->userSettings->getUserSetting($owner, 'stream', Files_Sharing::TYPE_SHARED), |
386
|
1 |
|
$this->userSettings->getUserSetting($owner, 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($owner, 'setting', 'batchtime') : 0 |
387
|
1 |
|
); |
388
|
1 |
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Add notifications for the owners whose files have been reshared |
392
|
|
|
* |
393
|
|
|
* @param string $currentOwner |
394
|
|
|
* @param string $subject |
395
|
|
|
* @param string $shareWith |
396
|
|
|
* @param int $fileSource |
397
|
|
|
* @param string $itemType |
398
|
|
|
*/ |
399
|
10 |
|
protected function shareNotificationForOriginalOwners($currentOwner, $subject, $shareWith, $fileSource, $itemType) { |
400
|
|
|
// Get the full path of the current user |
401
|
10 |
|
$this->view->chroot('/' . $currentOwner . '/files'); |
402
|
10 |
|
$path = $this->view->getPath($fileSource); |
403
|
10 |
|
if ($path === null) { |
404
|
1 |
|
return; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Get the original owner and his path |
409
|
|
|
*/ |
410
|
9 |
|
$owner = $this->view->getOwner($path); |
411
|
9 |
|
if ($owner !== $currentOwner) { |
412
|
7 |
|
$this->reshareNotificationForSharer($owner, $subject, $shareWith, $fileSource, $itemType); |
413
|
7 |
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Get the sharee who shared the item with the currentUser |
417
|
|
|
*/ |
418
|
9 |
|
$this->view->chroot('/' . $currentOwner . '/files'); |
419
|
9 |
|
$mount = $this->view->getMount($path); |
420
|
9 |
|
if (!($mount instanceof IMountPoint)) { |
|
|
|
|
421
|
1 |
|
return; |
422
|
|
|
} |
423
|
|
|
|
424
|
8 |
|
$storage = $mount->getStorage(); |
425
|
8 |
|
if (!$storage->instanceOfStorage('OC\Files\Storage\Shared')) { |
426
|
1 |
|
return; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** @var \OC\Files\Storage\Shared $storage */ |
430
|
7 |
|
$shareOwner = $storage->getSharedFrom(); |
431
|
7 |
|
if ($shareOwner === '' || $shareOwner === null || $shareOwner === $owner || $shareOwner === $currentOwner) { |
432
|
5 |
|
return; |
433
|
|
|
} |
434
|
|
|
|
435
|
2 |
|
$this->reshareNotificationForSharer($shareOwner, $subject, $shareWith, $fileSource, $itemType); |
436
|
2 |
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Adds the activity and email for a user when the settings require it |
440
|
|
|
* |
441
|
|
|
* @param string $user |
442
|
|
|
* @param string $subject |
443
|
|
|
* @param array $subjectParams |
444
|
|
|
* @param int $fileId |
445
|
|
|
* @param string $path |
446
|
|
|
* @param bool $isFile If the item is a file, we link to the parent directory |
447
|
|
|
* @param bool $streamSetting |
448
|
|
|
* @param int $emailSetting |
449
|
|
|
* @param string $type |
450
|
|
|
*/ |
451
|
9 |
|
protected function addNotificationsForUser($user, $subject, $subjectParams, $fileId, $path, $isFile, $streamSetting, $emailSetting, $type = Files_Sharing::TYPE_SHARED) { |
452
|
9 |
|
if (!$streamSetting && !$emailSetting) { |
453
|
1 |
|
return; |
454
|
|
|
} |
455
|
|
|
|
456
|
8 |
|
$selfAction = $user === $this->currentUser; |
457
|
8 |
|
$app = $type === Files_Sharing::TYPE_SHARED ? 'files_sharing' : 'files'; |
458
|
8 |
|
$link = Util::linkToAbsolute('files', 'index.php', array( |
459
|
8 |
|
'dir' => ($isFile) ? dirname($path) : $path, |
460
|
8 |
|
)); |
461
|
|
|
|
462
|
8 |
|
$objectType = ($fileId) ? 'files' : ''; |
463
|
|
|
|
464
|
8 |
|
$event = $this->manager->generateEvent(); |
465
|
8 |
|
$event->setApp($app) |
466
|
8 |
|
->setType($type) |
467
|
8 |
|
->setAffectedUser($user) |
468
|
8 |
|
->setAuthor($this->currentUser) |
469
|
8 |
|
->setTimestamp(time()) |
470
|
8 |
|
->setSubject($subject, $subjectParams) |
471
|
8 |
|
->setObject($objectType, $fileId, $path) |
472
|
8 |
|
->setLink($link); |
473
|
|
|
|
474
|
|
|
// Add activity to stream |
475
|
8 |
|
if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) { |
476
|
3 |
|
$this->activityData->send($event); |
477
|
3 |
|
} |
478
|
|
|
|
479
|
|
|
// Add activity to mail queue |
480
|
8 |
|
if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'selfemail'))) { |
481
|
3 |
|
$latestSend = time() + $emailSetting; |
482
|
3 |
|
$this->activityData->storeMail($event, $latestSend); |
483
|
3 |
|
} |
484
|
8 |
|
} |
485
|
|
|
} |
486
|
|
|
|