From 3fae4c82d261cfbc88a3df28cdbe6fea95c2936c Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 8 Apr 2016 11:56:38 +0200 Subject: Remove pre/post_addToGroup hooks for shares There is no need to perform the checks for unique targets on add to group as we have to do this all when mounting the shares anyway. --- lib/private/share/hooks.php | 118 -------------------------------------------- 1 file changed, 118 deletions(-) (limited to 'lib/private') diff --git a/lib/private/share/hooks.php b/lib/private/share/hooks.php index dae273eefb8..999efc7ca70 100644 --- a/lib/private/share/hooks.php +++ b/lib/private/share/hooks.php @@ -25,124 +25,6 @@ namespace OC\Share; class Hooks extends \OC\Share\Constants { - - /** - * remember which targets need to be updated in the post addToGroup Hook - * @var array - */ - private static $updateTargets = array(); - - /** - * Function that is called before a user is added to a group. - * check if we need to create a unique target for the user - * @param array $arguments - */ - public static function pre_addToGroup($arguments) { - $currentUser = \OC::$server->getUserSession()->getUser(); - $currentUserID = is_null($currentUser) ? '' : $currentUser->getUID(); - - // setup filesystem for added user if it isn't the current user - if($currentUserID !== $arguments['uid']) { - \OC_Util::tearDownFS(); - \OC_Util::setupFS($arguments['uid']); - } - - /** @var \OC\DB\Connection $db */ - $db = \OC::$server->getDatabaseConnection(); - - $insert = $db->createQueryBuilder(); - - $select = $db->createQueryBuilder(); - // Find the group shares and check if the user needs a unique target - $select->select('*') - ->from('`*PREFIX*share`') - ->where($select->expr()->andX( - $select->expr()->eq('`share_type`', ':shareType'), - $select->expr()->eq('`share_with`', ':shareWith') - )) - ->setParameter('shareType', self::SHARE_TYPE_GROUP) - ->setParameter('shareWith', $arguments['gid']); - - $result = $select->execute(); - - while ($item = $result->fetch()) { - - $itemTarget = Helper::generateTarget( - $item['item_type'], - $item['item_source'], - self::SHARE_TYPE_USER, - $arguments['uid'], - $item['uid_owner'], - null, - $item['parent'] - ); - - if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') { - $fileTarget = Helper::generateTarget( - $item['item_type'], - $item['file_target'], - self::SHARE_TYPE_USER, - $arguments['uid'], - $item['uid_owner'], - null, - $item['parent'] - ); - } else { - $fileTarget = null; - } - - - // Insert an extra row for the group share if the item or file target is unique for this user - if ( - ($fileTarget === null && $itemTarget != $item['item_target']) - || ($fileTarget !== null && $fileTarget !== $item['file_target']) - ) { - self::$updateTargets[$arguments['gid']][] = [ - '`item_type`' => $insert->expr()->literal($item['item_type']), - '`item_source`' => $insert->expr()->literal($item['item_source']), - '`item_target`' => $insert->expr()->literal($itemTarget), - '`file_target`' => $insert->expr()->literal($fileTarget), - '`parent`' => $insert->expr()->literal($item['id']), - '`share_type`' => $insert->expr()->literal(self::$shareTypeGroupUserUnique), - '`share_with`' => $insert->expr()->literal($arguments['uid']), - '`uid_owner`' => $insert->expr()->literal($item['uid_owner']), - '`permissions`' => $insert->expr()->literal($item['permissions']), - '`stime`' => $insert->expr()->literal($item['stime']), - '`file_source`' => $insert->expr()->literal($item['file_source']), - ]; - } - } - - // re-setup old filesystem state - if($currentUserID !== $arguments['uid']) { - \OC_Util::tearDownFS(); - if($currentUserID !== '') { - \OC_Util::setupFS($currentUserID); - } - } - } - - /** - * Function that is called after a user is added to a group. - * add unique target for the user if needed - * @param array $arguments - */ - public static function post_addToGroup($arguments) { - /** @var \OC\DB\Connection $db */ - $db = \OC::$server->getDatabaseConnection(); - - $insert = $db->createQueryBuilder(); - $insert->insert('`*PREFIX*share`'); - - if (isset(self::$updateTargets[$arguments['gid']])) { - foreach (self::$updateTargets[$arguments['gid']] as $newTarget) { - $insert->values($newTarget); - $insert->execute(); - } - unset(self::$updateTargets[$arguments['gid']]); - } - } - /** * Function that is called after a user is removed from a group. Shares are cleaned up. * @param array $arguments -- cgit v1.2.3