From c03de5bb461da6ac46e8d4eedce6263348c68e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Fri, 14 Jul 2017 01:11:04 +0300 Subject: [PATCH] Connect the hook post_unshareFromSelf to react to unshare by recipient - This solves #567 together with the core PR https://github.com/owncloud/core/pull/28401 --- hooks/sharehooks.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/hooks/sharehooks.php b/hooks/sharehooks.php index e720b60e2..d2be0cc8c 100644 --- a/hooks/sharehooks.php +++ b/hooks/sharehooks.php @@ -23,21 +23,38 @@ class ShareHooks { static public function itemUnshared($params) { $app = new Music(); - $container = $app->getContainer(); - $scanner = $container->query('Scanner'); - $sharedFileId = $params['itemSource']; + $scanner = $app->getContainer()->query('Scanner'); + $sharedNodeId = $params['itemSource']; $shareWithUser = $params['shareWith']; if ($params['itemType'] === 'folder') { - $ownerHome = $container->query('UserFolder'); - $nodes = $ownerHome->getById($sharedFileId); + $ownerHome = $scanner->resolveUserFolder($params['uidOwner']); + $nodes = $ownerHome->getById($sharedNodeId); if (count($nodes) > 0) { $sharedFolder = $nodes[0]; $scanner->deleteFolder($sharedFolder, $shareWithUser); } } else if ($params['itemType'] === 'file') { - $scanner->delete((int)$sharedFileId, $shareWithUser); + $scanner->delete((int)$sharedNodeId, $shareWithUser); + } + } + + /** + * Invoke auto update of music database after item gets unshared by the share recipient + * @param array $params contains the params of the removed share + */ + static public function itemUnsharedFromSelf($params) { + // In Share 1.0 used before OC 9.0, the parameter data of this signal + // did not contain all the needed fields, and updating our database based + // on such signal would be basically impossible. Handle the signal only + // if the needed fields are present. + // See: https://github.com/owncloud/core/issues/28337 + if (array_key_exists('itemSource', $params) + && array_key_exists('shareWith', $params) + && array_key_exists('itemType', $params) + && array_key_exists('uidOwner', $params)) { + self::itemUnshared($params); } } @@ -66,7 +83,8 @@ static public function itemShared($params) { public function register() { // FIXME: this is temporarily static because core emitters are not future // proof, therefore legacy code in here - \OCP\Util::connectHook('OCP\Share', 'post_unshare', __CLASS__, 'itemUnshared'); - \OCP\Util::connectHook('OCP\Share', 'post_shared', __CLASS__, 'itemShared'); + \OCP\Util::connectHook('OCP\Share', 'post_unshare', __CLASS__, 'itemUnshared'); + \OCP\Util::connectHook('OCP\Share', 'post_unshareFromSelf', __CLASS__, 'itemUnsharedFromSelf'); + \OCP\Util::connectHook('OCP\Share', 'post_shared', __CLASS__, 'itemShared'); } }