diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 8707a853..d5d3befd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -30,8 +30,10 @@ use OCA\Activity\Controller\Settings; use OCA\Activity\Data; use OCA\Activity\DataHelper; +use OCA\Activity\FilesHooksStatic; use OCA\Activity\GroupHelper; use OCA\Activity\FilesHooks; +use OCA\Activity\Hooks; use OCA\Activity\MailQueueHandler; use OCA\Activity\Navigation; use OCA\Activity\Parameter\Factory; @@ -287,7 +289,8 @@ public function registerHooksAndEvents() { $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Activity\FilesHooksStatic', 'onLoadFilesAppScripts']); - Util::connectHook('OC_User', 'post_deleteUser', 'OCA\Activity\Hooks', 'deleteUser'); + $activityHook = new Hooks(); + $eventDispatcher->addListener('user.afterdelete', [$activityHook, 'deleteUser']); $this->registerFilesActivity(); } @@ -296,13 +299,16 @@ public function registerHooksAndEvents() { * Register the hooks for filesystem operations */ public function registerFilesActivity() { + $filesHooksStatic = new FilesHooksStatic(); + $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); + // All other events from other apps have to be send via the Consumer Util::connectHook('OC_Filesystem', 'post_create', 'OCA\Activity\FilesHooksStatic', 'fileCreate'); Util::connectHook('OC_Filesystem', 'post_update', 'OCA\Activity\FilesHooksStatic', 'fileUpdate'); Util::connectHook('OC_Filesystem', 'delete', 'OCA\Activity\FilesHooksStatic', 'fileDelete'); Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OCA\Activity\FilesHooksStatic', 'fileRestore'); - Util::connectHook('OCP\Share', 'post_shared', 'OCA\Activity\FilesHooksStatic', 'share'); - Util::connectHook('OCP\Share', 'pre_unshare', 'OCA\Activity\FilesHooksStatic', 'unShare'); + $eventDispatcher->addListener('file.aftercreateshare', [$filesHooksStatic, 'share']); + $eventDispatcher->addListener('file.beforeunshare', [$filesHooksStatic, 'unshare']); } } diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 8f7d875b..90c58319 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -36,6 +36,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\Share; +use Symfony\Component\EventDispatcher\GenericEvent; /** * The class to handle the filesystem hooks @@ -224,32 +225,54 @@ protected function getSourcePathAndOwner($path) { /** * Manage sharing events - * @param array $params The hook params + * @param GenericEvent $params The hook params */ - public function share($params) { - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - if ((int) $params['shareType'] === Share::SHARE_TYPE_USER) { - $this->shareFileOrFolderWithUser($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], true); - } else if ((int) $params['shareType'] === Share::SHARE_TYPE_GROUP) { - $this->shareFileOrFolderWithGroup($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], (int) $params['id'], true); + public function share(GenericEvent $params) { + \OC::$server->getLogger()->warning(__METHOD__ . " LOOPING . First take the count = " . count($params->getArguments())); + foreach ($params->getArguments() as $argument) { + \OC::$server->getLogger()->warning(__METHOD__ . " val = $argument"); + } + if ($params->getArgument('itemType') === 'file' || $params->getArgument('itemType') === 'folder') { + if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_USER) { + $this->shareFileOrFolderWithUser($params->getArgument('shareWith'), + (int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('fileTarget'), true); + } else if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_GROUP) { + $this->shareFileOrFolderWithGroup($params->getArgument('shareWith'), + (int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('fileTarget'), + (int) $params->getArgument('id'), true); } else if ((int) $params['shareType'] === Share::SHARE_TYPE_LINK) { - $this->shareFileOrFolderByLink((int) $params['fileSource'], $params['itemType'], $params['uidOwner'], true); + $this->shareFileOrFolderByLink((int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('uidOwner'), true); } } } /** * Manage sharing events - * @param array $params The hook params + * @param GenericEvent $params The hook params */ - public function unShare($params) { - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { - if ((int) $params['shareType'] === Share::SHARE_TYPE_USER) { - $this->shareFileOrFolderWithUser($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], false); - } else if ((int) $params['shareType'] === Share::SHARE_TYPE_GROUP) { - $this->shareFileOrFolderWithGroup($params['shareWith'], (int) $params['fileSource'], $params['itemType'], $params['fileTarget'], (int) $params['id'], false); + public function unShare(GenericEvent $params) { + if ($params->getArgument('itemType') === 'file' || $params->getArgument('itemType') === 'folder') { + if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_USER) { + $this->shareFileOrFolderWithUser($params->getArgument('shareWith'), + (int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('fileTarget'), false); + } else if ((int) $params->getArgument('shareType') === Share::SHARE_TYPE_GROUP) { + $this->shareFileOrFolderWithGroup($params->getArgument('shareWith'), + (int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('fileTarget'), + (int) $params->getArgument('id'), false); } else if ((int) $params['shareType'] === Share::SHARE_TYPE_LINK) { - $this->shareFileOrFolderByLink((int) $params['fileSource'], $params['itemType'], $params['uidOwner'], false); + $this->shareFileOrFolderByLink((int) $params->getArgument('fileSource'), + $params->getArgument('itemType'), + $params->getArgument('uidOwner'), false); } } } diff --git a/lib/FilesHooksStatic.php b/lib/FilesHooksStatic.php index fcd80363..b8e00471 100755 --- a/lib/FilesHooksStatic.php +++ b/lib/FilesHooksStatic.php @@ -23,6 +23,7 @@ namespace OCA\Activity; use OCP\Util; +use Symfony\Component\EventDispatcher\GenericEvent; /** * The class to handle the filesystem hooks @@ -71,17 +72,17 @@ public static function fileRestore($params) { /** * Manage sharing events - * @param array $params The hook params + * @param GenericEvent $params The hook params */ - public static function share($params) { + public static function share(GenericEvent $params) { self::getHooks()->share($params); } /** * Manage sharing events - * @param array $params The hook params + * @param GenericEvent $params The hook params */ - public static function unShare($params) { + public static function unShare(GenericEvent $params) { self::getHooks()->unShare($params); } diff --git a/lib/Hooks.php b/lib/Hooks.php index f822e57b..d9158dfc 100755 --- a/lib/Hooks.php +++ b/lib/Hooks.php @@ -23,6 +23,7 @@ use OCA\Activity\AppInfo\Application; use OCP\IDBConnection; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Handles the stream and mail queue of a user when he is being deleted @@ -33,10 +34,10 @@ class Hooks { * * @param array $params The hook params */ - static public function deleteUser($params) { + static public function deleteUser(GenericEvent $params) { $connection = \OC::$server->getDatabaseConnection(); - self::deleteUserStream($params['uid']); - self::deleteUserMailQueue($connection, $params['uid']); + self::deleteUserStream($params->getArgument('uid')); + self::deleteUserMailQueue($connection, $params->getArgument('uid')); } /**