@@ -34,101 +34,101 @@ |
||
| 34 | 34 | use OCP\Share\IShareHelper; |
| 35 | 35 | |
| 36 | 36 | class Listener { |
| 37 | - /** @var IManager */ |
|
| 38 | - protected $activityManager; |
|
| 39 | - /** @var IUserSession */ |
|
| 40 | - protected $session; |
|
| 41 | - /** @var \OCP\App\IAppManager */ |
|
| 42 | - protected $appManager; |
|
| 43 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
| 44 | - protected $mountCollection; |
|
| 45 | - /** @var \OCP\Files\IRootFolder */ |
|
| 46 | - protected $rootFolder; |
|
| 47 | - /** @var IShareHelper */ |
|
| 48 | - protected $shareHelper; |
|
| 37 | + /** @var IManager */ |
|
| 38 | + protected $activityManager; |
|
| 39 | + /** @var IUserSession */ |
|
| 40 | + protected $session; |
|
| 41 | + /** @var \OCP\App\IAppManager */ |
|
| 42 | + protected $appManager; |
|
| 43 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
| 44 | + protected $mountCollection; |
|
| 45 | + /** @var \OCP\Files\IRootFolder */ |
|
| 46 | + protected $rootFolder; |
|
| 47 | + /** @var IShareHelper */ |
|
| 48 | + protected $shareHelper; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Listener constructor. |
|
| 52 | - * |
|
| 53 | - * @param IManager $activityManager |
|
| 54 | - * @param IUserSession $session |
|
| 55 | - * @param IAppManager $appManager |
|
| 56 | - * @param IMountProviderCollection $mountCollection |
|
| 57 | - * @param IRootFolder $rootFolder |
|
| 58 | - * @param IShareHelper $shareHelper |
|
| 59 | - */ |
|
| 60 | - public function __construct(IManager $activityManager, |
|
| 61 | - IUserSession $session, |
|
| 62 | - IAppManager $appManager, |
|
| 63 | - IMountProviderCollection $mountCollection, |
|
| 64 | - IRootFolder $rootFolder, |
|
| 65 | - IShareHelper $shareHelper) { |
|
| 66 | - $this->activityManager = $activityManager; |
|
| 67 | - $this->session = $session; |
|
| 68 | - $this->appManager = $appManager; |
|
| 69 | - $this->mountCollection = $mountCollection; |
|
| 70 | - $this->rootFolder = $rootFolder; |
|
| 71 | - $this->shareHelper = $shareHelper; |
|
| 72 | - } |
|
| 50 | + /** |
|
| 51 | + * Listener constructor. |
|
| 52 | + * |
|
| 53 | + * @param IManager $activityManager |
|
| 54 | + * @param IUserSession $session |
|
| 55 | + * @param IAppManager $appManager |
|
| 56 | + * @param IMountProviderCollection $mountCollection |
|
| 57 | + * @param IRootFolder $rootFolder |
|
| 58 | + * @param IShareHelper $shareHelper |
|
| 59 | + */ |
|
| 60 | + public function __construct(IManager $activityManager, |
|
| 61 | + IUserSession $session, |
|
| 62 | + IAppManager $appManager, |
|
| 63 | + IMountProviderCollection $mountCollection, |
|
| 64 | + IRootFolder $rootFolder, |
|
| 65 | + IShareHelper $shareHelper) { |
|
| 66 | + $this->activityManager = $activityManager; |
|
| 67 | + $this->session = $session; |
|
| 68 | + $this->appManager = $appManager; |
|
| 69 | + $this->mountCollection = $mountCollection; |
|
| 70 | + $this->rootFolder = $rootFolder; |
|
| 71 | + $this->shareHelper = $shareHelper; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @param CommentsEvent $event |
|
| 76 | - */ |
|
| 77 | - public function commentEvent(CommentsEvent $event) { |
|
| 78 | - if ($event->getComment()->getObjectType() !== 'files' |
|
| 79 | - || $event->getEvent() !== CommentsEvent::EVENT_ADD |
|
| 80 | - || !$this->appManager->isInstalled('activity')) { |
|
| 81 | - // Comment not for file, not adding a comment or no activity-app enabled (save the energy) |
|
| 82 | - return; |
|
| 83 | - } |
|
| 74 | + /** |
|
| 75 | + * @param CommentsEvent $event |
|
| 76 | + */ |
|
| 77 | + public function commentEvent(CommentsEvent $event) { |
|
| 78 | + if ($event->getComment()->getObjectType() !== 'files' |
|
| 79 | + || $event->getEvent() !== CommentsEvent::EVENT_ADD |
|
| 80 | + || !$this->appManager->isInstalled('activity')) { |
|
| 81 | + // Comment not for file, not adding a comment or no activity-app enabled (save the energy) |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Get all mount point owners |
|
| 86 | - $cache = $this->mountCollection->getMountCache(); |
|
| 87 | - $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
| 88 | - if (empty($mounts)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 85 | + // Get all mount point owners |
|
| 86 | + $cache = $this->mountCollection->getMountCache(); |
|
| 87 | + $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
| 88 | + if (empty($mounts)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $users = []; |
|
| 93 | - foreach ($mounts as $mount) { |
|
| 94 | - $owner = $mount->getUser()->getUID(); |
|
| 95 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
| 96 | - $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
| 97 | - if (!empty($nodes)) { |
|
| 98 | - /** @var Node $node */ |
|
| 99 | - $node = array_shift($nodes); |
|
| 100 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
| 101 | - $users += $al['users']; |
|
| 102 | - } |
|
| 103 | - } |
|
| 92 | + $users = []; |
|
| 93 | + foreach ($mounts as $mount) { |
|
| 94 | + $owner = $mount->getUser()->getUID(); |
|
| 95 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
| 96 | + $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
| 97 | + if (!empty($nodes)) { |
|
| 98 | + /** @var Node $node */ |
|
| 99 | + $node = array_shift($nodes); |
|
| 100 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
| 101 | + $users += $al['users']; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $actor = $this->session->getUser(); |
|
| 106 | - if ($actor instanceof IUser) { |
|
| 107 | - $actor = $actor->getUID(); |
|
| 108 | - } else { |
|
| 109 | - $actor = ''; |
|
| 110 | - } |
|
| 105 | + $actor = $this->session->getUser(); |
|
| 106 | + if ($actor instanceof IUser) { |
|
| 107 | + $actor = $actor->getUID(); |
|
| 108 | + } else { |
|
| 109 | + $actor = ''; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $activity = $this->activityManager->generateEvent(); |
|
| 113 | - $activity->setApp('comments') |
|
| 114 | - ->setType('comments') |
|
| 115 | - ->setAuthor($actor) |
|
| 116 | - ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId()) |
|
| 117 | - ->setMessage('add_comment_message', [ |
|
| 118 | - 'commentId' => $event->getComment()->getId(), |
|
| 119 | - ]); |
|
| 112 | + $activity = $this->activityManager->generateEvent(); |
|
| 113 | + $activity->setApp('comments') |
|
| 114 | + ->setType('comments') |
|
| 115 | + ->setAuthor($actor) |
|
| 116 | + ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId()) |
|
| 117 | + ->setMessage('add_comment_message', [ |
|
| 118 | + 'commentId' => $event->getComment()->getId(), |
|
| 119 | + ]); |
|
| 120 | 120 | |
| 121 | - foreach ($users as $user => $path) { |
|
| 122 | - // numerical user ids end up as integers from array keys, but string |
|
| 123 | - // is required |
|
| 124 | - $activity->setAffectedUser((string)$user); |
|
| 121 | + foreach ($users as $user => $path) { |
|
| 122 | + // numerical user ids end up as integers from array keys, but string |
|
| 123 | + // is required |
|
| 124 | + $activity->setAffectedUser((string)$user); |
|
| 125 | 125 | |
| 126 | - $activity->setSubject('add_comment_subject', [ |
|
| 127 | - 'actor' => $actor, |
|
| 128 | - 'fileId' => (int) $event->getComment()->getObjectId(), |
|
| 129 | - 'filePath' => trim($path, '/'), |
|
| 130 | - ]); |
|
| 131 | - $this->activityManager->publish($activity); |
|
| 132 | - } |
|
| 133 | - } |
|
| 126 | + $activity->setSubject('add_comment_subject', [ |
|
| 127 | + 'actor' => $actor, |
|
| 128 | + 'fileId' => (int) $event->getComment()->getObjectId(), |
|
| 129 | + 'filePath' => trim($path, '/'), |
|
| 130 | + ]); |
|
| 131 | + $this->activityManager->publish($activity); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | // Get all mount point owners |
| 86 | 86 | $cache = $this->mountCollection->getMountCache(); |
| 87 | - $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId()); |
|
| 87 | + $mounts = $cache->getMountsForFileId((int) $event->getComment()->getObjectId()); |
|
| 88 | 88 | if (empty($mounts)) { |
| 89 | 89 | return; |
| 90 | 90 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | foreach ($mounts as $mount) { |
| 94 | 94 | $owner = $mount->getUser()->getUID(); |
| 95 | 95 | $ownerFolder = $this->rootFolder->getUserFolder($owner); |
| 96 | - $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId()); |
|
| 96 | + $nodes = $ownerFolder->getById((int) $event->getComment()->getObjectId()); |
|
| 97 | 97 | if (!empty($nodes)) { |
| 98 | 98 | /** @var Node $node */ |
| 99 | 99 | $node = array_shift($nodes); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | foreach ($users as $user => $path) { |
| 122 | 122 | // numerical user ids end up as integers from array keys, but string |
| 123 | 123 | // is required |
| 124 | - $activity->setAffectedUser((string)$user); |
|
| 124 | + $activity->setAffectedUser((string) $user); |
|
| 125 | 125 | |
| 126 | 126 | $activity->setSubject('add_comment_subject', [ |
| 127 | 127 | 'actor' => $actor, |
@@ -42,224 +42,224 @@ |
||
| 42 | 42 | use OCP\SystemTag\TagNotFoundException; |
| 43 | 43 | |
| 44 | 44 | class Listener { |
| 45 | - /** @var IGroupManager */ |
|
| 46 | - protected $groupManager; |
|
| 47 | - /** @var IManager */ |
|
| 48 | - protected $activityManager; |
|
| 49 | - /** @var IUserSession */ |
|
| 50 | - protected $session; |
|
| 51 | - /** @var IConfig */ |
|
| 52 | - protected $config; |
|
| 53 | - /** @var \OCP\SystemTag\ISystemTagManager */ |
|
| 54 | - protected $tagManager; |
|
| 55 | - /** @var \OCP\App\IAppManager */ |
|
| 56 | - protected $appManager; |
|
| 57 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
| 58 | - protected $mountCollection; |
|
| 59 | - /** @var \OCP\Files\IRootFolder */ |
|
| 60 | - protected $rootFolder; |
|
| 61 | - /** @var IShareHelper */ |
|
| 62 | - protected $shareHelper; |
|
| 45 | + /** @var IGroupManager */ |
|
| 46 | + protected $groupManager; |
|
| 47 | + /** @var IManager */ |
|
| 48 | + protected $activityManager; |
|
| 49 | + /** @var IUserSession */ |
|
| 50 | + protected $session; |
|
| 51 | + /** @var IConfig */ |
|
| 52 | + protected $config; |
|
| 53 | + /** @var \OCP\SystemTag\ISystemTagManager */ |
|
| 54 | + protected $tagManager; |
|
| 55 | + /** @var \OCP\App\IAppManager */ |
|
| 56 | + protected $appManager; |
|
| 57 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
| 58 | + protected $mountCollection; |
|
| 59 | + /** @var \OCP\Files\IRootFolder */ |
|
| 60 | + protected $rootFolder; |
|
| 61 | + /** @var IShareHelper */ |
|
| 62 | + protected $shareHelper; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Listener constructor. |
|
| 66 | - * |
|
| 67 | - * @param IGroupManager $groupManager |
|
| 68 | - * @param IManager $activityManager |
|
| 69 | - * @param IUserSession $session |
|
| 70 | - * @param IConfig $config |
|
| 71 | - * @param ISystemTagManager $tagManager |
|
| 72 | - * @param IAppManager $appManager |
|
| 73 | - * @param IMountProviderCollection $mountCollection |
|
| 74 | - * @param IRootFolder $rootFolder |
|
| 75 | - * @param IShareHelper $shareHelper |
|
| 76 | - */ |
|
| 77 | - public function __construct(IGroupManager $groupManager, |
|
| 78 | - IManager $activityManager, |
|
| 79 | - IUserSession $session, |
|
| 80 | - IConfig $config, |
|
| 81 | - ISystemTagManager $tagManager, |
|
| 82 | - IAppManager $appManager, |
|
| 83 | - IMountProviderCollection $mountCollection, |
|
| 84 | - IRootFolder $rootFolder, |
|
| 85 | - IShareHelper $shareHelper) { |
|
| 86 | - $this->groupManager = $groupManager; |
|
| 87 | - $this->activityManager = $activityManager; |
|
| 88 | - $this->session = $session; |
|
| 89 | - $this->config = $config; |
|
| 90 | - $this->tagManager = $tagManager; |
|
| 91 | - $this->appManager = $appManager; |
|
| 92 | - $this->mountCollection = $mountCollection; |
|
| 93 | - $this->rootFolder = $rootFolder; |
|
| 94 | - $this->shareHelper = $shareHelper; |
|
| 95 | - } |
|
| 64 | + /** |
|
| 65 | + * Listener constructor. |
|
| 66 | + * |
|
| 67 | + * @param IGroupManager $groupManager |
|
| 68 | + * @param IManager $activityManager |
|
| 69 | + * @param IUserSession $session |
|
| 70 | + * @param IConfig $config |
|
| 71 | + * @param ISystemTagManager $tagManager |
|
| 72 | + * @param IAppManager $appManager |
|
| 73 | + * @param IMountProviderCollection $mountCollection |
|
| 74 | + * @param IRootFolder $rootFolder |
|
| 75 | + * @param IShareHelper $shareHelper |
|
| 76 | + */ |
|
| 77 | + public function __construct(IGroupManager $groupManager, |
|
| 78 | + IManager $activityManager, |
|
| 79 | + IUserSession $session, |
|
| 80 | + IConfig $config, |
|
| 81 | + ISystemTagManager $tagManager, |
|
| 82 | + IAppManager $appManager, |
|
| 83 | + IMountProviderCollection $mountCollection, |
|
| 84 | + IRootFolder $rootFolder, |
|
| 85 | + IShareHelper $shareHelper) { |
|
| 86 | + $this->groupManager = $groupManager; |
|
| 87 | + $this->activityManager = $activityManager; |
|
| 88 | + $this->session = $session; |
|
| 89 | + $this->config = $config; |
|
| 90 | + $this->tagManager = $tagManager; |
|
| 91 | + $this->appManager = $appManager; |
|
| 92 | + $this->mountCollection = $mountCollection; |
|
| 93 | + $this->rootFolder = $rootFolder; |
|
| 94 | + $this->shareHelper = $shareHelper; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @param ManagerEvent $event |
|
| 99 | - */ |
|
| 100 | - public function event(ManagerEvent $event) { |
|
| 101 | - $actor = $this->session->getUser(); |
|
| 102 | - if ($actor instanceof IUser) { |
|
| 103 | - $actor = $actor->getUID(); |
|
| 104 | - } else { |
|
| 105 | - $actor = ''; |
|
| 106 | - } |
|
| 107 | - $tag = $event->getTag(); |
|
| 97 | + /** |
|
| 98 | + * @param ManagerEvent $event |
|
| 99 | + */ |
|
| 100 | + public function event(ManagerEvent $event) { |
|
| 101 | + $actor = $this->session->getUser(); |
|
| 102 | + if ($actor instanceof IUser) { |
|
| 103 | + $actor = $actor->getUID(); |
|
| 104 | + } else { |
|
| 105 | + $actor = ''; |
|
| 106 | + } |
|
| 107 | + $tag = $event->getTag(); |
|
| 108 | 108 | |
| 109 | - $activity = $this->activityManager->generateEvent(); |
|
| 110 | - $activity->setApp('systemtags') |
|
| 111 | - ->setType('systemtags') |
|
| 112 | - ->setAuthor($actor) |
|
| 113 | - ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
| 114 | - if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
| 115 | - $activity->setSubject(Provider::CREATE_TAG, [ |
|
| 116 | - $actor, |
|
| 117 | - $this->prepareTagAsParameter($event->getTag()), |
|
| 118 | - ]); |
|
| 119 | - } else if ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
| 120 | - $activity->setSubject(Provider::UPDATE_TAG, [ |
|
| 121 | - $actor, |
|
| 122 | - $this->prepareTagAsParameter($event->getTag()), |
|
| 123 | - $this->prepareTagAsParameter($event->getTagBefore()), |
|
| 124 | - ]); |
|
| 125 | - } else if ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
| 126 | - $activity->setSubject(Provider::DELETE_TAG, [ |
|
| 127 | - $actor, |
|
| 128 | - $this->prepareTagAsParameter($event->getTag()), |
|
| 129 | - ]); |
|
| 130 | - } else { |
|
| 131 | - return; |
|
| 132 | - } |
|
| 109 | + $activity = $this->activityManager->generateEvent(); |
|
| 110 | + $activity->setApp('systemtags') |
|
| 111 | + ->setType('systemtags') |
|
| 112 | + ->setAuthor($actor) |
|
| 113 | + ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
| 114 | + if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
| 115 | + $activity->setSubject(Provider::CREATE_TAG, [ |
|
| 116 | + $actor, |
|
| 117 | + $this->prepareTagAsParameter($event->getTag()), |
|
| 118 | + ]); |
|
| 119 | + } else if ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
| 120 | + $activity->setSubject(Provider::UPDATE_TAG, [ |
|
| 121 | + $actor, |
|
| 122 | + $this->prepareTagAsParameter($event->getTag()), |
|
| 123 | + $this->prepareTagAsParameter($event->getTagBefore()), |
|
| 124 | + ]); |
|
| 125 | + } else if ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
| 126 | + $activity->setSubject(Provider::DELETE_TAG, [ |
|
| 127 | + $actor, |
|
| 128 | + $this->prepareTagAsParameter($event->getTag()), |
|
| 129 | + ]); |
|
| 130 | + } else { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - $group = $this->groupManager->get('admin'); |
|
| 135 | - if ($group instanceof IGroup) { |
|
| 136 | - foreach ($group->getUsers() as $user) { |
|
| 137 | - $activity->setAffectedUser($user->getUID()); |
|
| 138 | - $this->activityManager->publish($activity); |
|
| 139 | - } |
|
| 140 | - } |
|
| 134 | + $group = $this->groupManager->get('admin'); |
|
| 135 | + if ($group instanceof IGroup) { |
|
| 136 | + foreach ($group->getUsers() as $user) { |
|
| 137 | + $activity->setAffectedUser($user->getUID()); |
|
| 138 | + $this->activityManager->publish($activity); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | |
| 143 | - if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
| 144 | - $this->updateLastUsedTags($actor, $event->getTag()); |
|
| 145 | - } |
|
| 146 | - } |
|
| 143 | + if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
| 144 | + $this->updateLastUsedTags($actor, $event->getTag()); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param MapperEvent $event |
|
| 150 | - */ |
|
| 151 | - public function mapperEvent(MapperEvent $event) { |
|
| 152 | - $tagIds = $event->getTags(); |
|
| 153 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
| 154 | - || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
| 155 | - || !$this->appManager->isInstalled('activity')) { |
|
| 156 | - // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
| 157 | - return; |
|
| 158 | - } |
|
| 148 | + /** |
|
| 149 | + * @param MapperEvent $event |
|
| 150 | + */ |
|
| 151 | + public function mapperEvent(MapperEvent $event) { |
|
| 152 | + $tagIds = $event->getTags(); |
|
| 153 | + if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
| 154 | + || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
| 155 | + || !$this->appManager->isInstalled('activity')) { |
|
| 156 | + // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
| 157 | + return; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - try { |
|
| 161 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 162 | - } catch (TagNotFoundException $e) { |
|
| 163 | - // User assigned/unassigned a non-existing tag, ignore... |
|
| 164 | - return; |
|
| 165 | - } |
|
| 160 | + try { |
|
| 161 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 162 | + } catch (TagNotFoundException $e) { |
|
| 163 | + // User assigned/unassigned a non-existing tag, ignore... |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - if (empty($tags)) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 167 | + if (empty($tags)) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // Get all mount point owners |
|
| 172 | - $cache = $this->mountCollection->getMountCache(); |
|
| 173 | - $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
| 174 | - if (empty($mounts)) { |
|
| 175 | - return; |
|
| 176 | - } |
|
| 171 | + // Get all mount point owners |
|
| 172 | + $cache = $this->mountCollection->getMountCache(); |
|
| 173 | + $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
| 174 | + if (empty($mounts)) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - $users = []; |
|
| 179 | - foreach ($mounts as $mount) { |
|
| 180 | - $owner = $mount->getUser()->getUID(); |
|
| 181 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
| 182 | - $nodes = $ownerFolder->getById($event->getObjectId()); |
|
| 183 | - if (!empty($nodes)) { |
|
| 184 | - /** @var Node $node */ |
|
| 185 | - $node = array_shift($nodes); |
|
| 186 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
| 187 | - $users += $al['users']; |
|
| 188 | - } |
|
| 189 | - } |
|
| 178 | + $users = []; |
|
| 179 | + foreach ($mounts as $mount) { |
|
| 180 | + $owner = $mount->getUser()->getUID(); |
|
| 181 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
| 182 | + $nodes = $ownerFolder->getById($event->getObjectId()); |
|
| 183 | + if (!empty($nodes)) { |
|
| 184 | + /** @var Node $node */ |
|
| 185 | + $node = array_shift($nodes); |
|
| 186 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
| 187 | + $users += $al['users']; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - $actor = $this->session->getUser(); |
|
| 192 | - if ($actor instanceof IUser) { |
|
| 193 | - $actor = $actor->getUID(); |
|
| 194 | - } else { |
|
| 195 | - $actor = ''; |
|
| 196 | - } |
|
| 191 | + $actor = $this->session->getUser(); |
|
| 192 | + if ($actor instanceof IUser) { |
|
| 193 | + $actor = $actor->getUID(); |
|
| 194 | + } else { |
|
| 195 | + $actor = ''; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - $activity = $this->activityManager->generateEvent(); |
|
| 199 | - $activity->setApp('systemtags') |
|
| 200 | - ->setType('systemtags') |
|
| 201 | - ->setAuthor($actor) |
|
| 202 | - ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
| 198 | + $activity = $this->activityManager->generateEvent(); |
|
| 199 | + $activity->setApp('systemtags') |
|
| 200 | + ->setType('systemtags') |
|
| 201 | + ->setAuthor($actor) |
|
| 202 | + ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
| 203 | 203 | |
| 204 | - foreach ($users as $user => $path) { |
|
| 205 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
| 206 | - $activity->setAffectedUser($user); |
|
| 204 | + foreach ($users as $user => $path) { |
|
| 205 | + $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
| 206 | + $activity->setAffectedUser($user); |
|
| 207 | 207 | |
| 208 | - foreach ($tags as $tag) { |
|
| 209 | - // don't publish activity for non-admins if tag is invisible |
|
| 210 | - if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
| 211 | - continue; |
|
| 212 | - } |
|
| 213 | - if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
| 214 | - $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
| 215 | - $actor, |
|
| 216 | - $path, |
|
| 217 | - $this->prepareTagAsParameter($tag), |
|
| 218 | - ]); |
|
| 219 | - } else if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
| 220 | - $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
| 221 | - $actor, |
|
| 222 | - $path, |
|
| 223 | - $this->prepareTagAsParameter($tag), |
|
| 224 | - ]); |
|
| 225 | - } |
|
| 208 | + foreach ($tags as $tag) { |
|
| 209 | + // don't publish activity for non-admins if tag is invisible |
|
| 210 | + if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
| 211 | + continue; |
|
| 212 | + } |
|
| 213 | + if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
| 214 | + $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
| 215 | + $actor, |
|
| 216 | + $path, |
|
| 217 | + $this->prepareTagAsParameter($tag), |
|
| 218 | + ]); |
|
| 219 | + } else if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
| 220 | + $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
| 221 | + $actor, |
|
| 222 | + $path, |
|
| 223 | + $this->prepareTagAsParameter($tag), |
|
| 224 | + ]); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - $this->activityManager->publish($activity); |
|
| 228 | - } |
|
| 229 | - } |
|
| 227 | + $this->activityManager->publish($activity); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
| 232 | - foreach ($tags as $tag) { |
|
| 233 | - $this->updateLastUsedTags($actor, $tag); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 231 | + if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
| 232 | + foreach ($tags as $tag) { |
|
| 233 | + $this->updateLastUsedTags($actor, $tag); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * @param string $actor |
|
| 240 | - * @param ISystemTag $tag |
|
| 241 | - */ |
|
| 242 | - protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
| 243 | - $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
| 244 | - $lastUsedTags = json_decode($lastUsedTags, true); |
|
| 238 | + /** |
|
| 239 | + * @param string $actor |
|
| 240 | + * @param ISystemTag $tag |
|
| 241 | + */ |
|
| 242 | + protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
| 243 | + $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
| 244 | + $lastUsedTags = json_decode($lastUsedTags, true); |
|
| 245 | 245 | |
| 246 | - array_unshift($lastUsedTags, $tag->getId()); |
|
| 247 | - array_unique($lastUsedTags); |
|
| 248 | - $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
| 246 | + array_unshift($lastUsedTags, $tag->getId()); |
|
| 247 | + array_unique($lastUsedTags); |
|
| 248 | + $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
| 249 | 249 | |
| 250 | - $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
| 251 | - } |
|
| 250 | + $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * @param ISystemTag $tag |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - protected function prepareTagAsParameter(ISystemTag $tag) { |
|
| 258 | - return json_encode([ |
|
| 259 | - 'id' => $tag->getId(), |
|
| 260 | - 'name' => $tag->getName(), |
|
| 261 | - 'assignable' => $tag->isUserAssignable(), |
|
| 262 | - 'visible' => $tag->isUserVisible(), |
|
| 263 | - ]); |
|
| 264 | - } |
|
| 253 | + /** |
|
| 254 | + * @param ISystemTag $tag |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + protected function prepareTagAsParameter(ISystemTag $tag) { |
|
| 258 | + return json_encode([ |
|
| 259 | + 'id' => $tag->getId(), |
|
| 260 | + 'name' => $tag->getName(), |
|
| 261 | + 'assignable' => $tag->isUserAssignable(), |
|
| 262 | + 'visible' => $tag->isUserVisible(), |
|
| 263 | + ]); |
|
| 264 | + } |
|
| 265 | 265 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $activity->setApp('systemtags') |
| 111 | 111 | ->setType('systemtags') |
| 112 | 112 | ->setAuthor($actor) |
| 113 | - ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
| 113 | + ->setObject('systemtag', (int) $tag->getId(), $tag->getName()); |
|
| 114 | 114 | if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
| 115 | 115 | $activity->setSubject(Provider::CREATE_TAG, [ |
| 116 | 116 | $actor, |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public function mapperEvent(MapperEvent $event) { |
| 152 | 152 | $tagIds = $event->getTags(); |
| 153 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
| 153 | + if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
| 154 | 154 | || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
| 155 | 155 | || !$this->appManager->isInstalled('activity')) { |
| 156 | 156 | // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
| 203 | 203 | |
| 204 | 204 | foreach ($users as $user => $path) { |
| 205 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
| 205 | + $user = (string) $user; // numerical ids could be ints which are not accepted everywhere |
|
| 206 | 206 | $activity->setAffectedUser($user); |
| 207 | 207 | |
| 208 | 208 | foreach ($tags as $tag) { |