diff options
author | Roeland Douma <rullzer@users.noreply.github.com> | 2016-04-12 09:46:25 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-12 09:46:25 +0200 |
commit | 495a964ca2e5384f6e6a97a4c9cab73a02928634 (patch) | |
tree | 6389fd51c66801b80cd58282b92dd261f0789078 /lib/private/Share20 | |
parent | 4ddf9f98f1189192acfeb5ba9046a4bc0b52dbe5 (diff) | |
download | nextcloud-server-495a964ca2e5384f6e6a97a4c9cab73a02928634.tar.gz nextcloud-server-495a964ca2e5384f6e6a97a4c9cab73a02928634.zip |
Migrate post_groupDelete hook to share manager (#23841)
The hook now calls the share manager that will call the responsible
shareProvider to do the proper cleanup.
* Unit tests added
Again nothing should change it is just to cleanup old code
Diffstat (limited to 'lib/private/Share20')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 43 | ||||
-rw-r--r-- | lib/private/Share20/Hooks.php | 4 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 8 |
3 files changed, 55 insertions, 0 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 370655f8315..b1f3b4dab83 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -867,4 +867,47 @@ class DefaultShareProvider implements IShareProvider { $qb->execute(); } + + /** + * Delete all shares received by this group. As well as any custom group + * shares for group members. + * + * @param string $gid + */ + public function groupDeleted($gid) { + /* + * First delete all custom group shares for group members + */ + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('id') + ->from('share') + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); + + $cursor = $qb->execute(); + $ids = []; + while($row = $cursor->fetch()) { + $ids[] = (int)$row['id']; + } + $cursor->closeCursor(); + + if (!empty($ids)) { + $chunks = array_chunk($ids, 100); + foreach ($chunks as $chunk) { + $qb->delete('share') + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); + $qb->execute(); + } + } + + /* + * Now delete all the group shares + */ + $qb = $this->dbConn->getQueryBuilder(); + $qb->delete('share') + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); + $qb->execute(); + } } diff --git a/lib/private/Share20/Hooks.php b/lib/private/Share20/Hooks.php index 93669974b28..b391ffce8d5 100644 --- a/lib/private/Share20/Hooks.php +++ b/lib/private/Share20/Hooks.php @@ -24,4 +24,8 @@ class Hooks { public static function post_deleteUser($arguments) { \OC::$server->getShareManager()->userDeleted($arguments['uid']); } + + public static function post_deleteGroup($arguments) { + \OC::$server->getShareManager()->groupDeleted($arguments['gid']); + } } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index be7257de36d..af846b9283c 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1049,6 +1049,14 @@ class Manager implements IManager { } /** + * @inheritdoc + */ + public function groupDeleted($gid) { + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); + $provider->groupDeleted($gid); + } + + /** * Get access list to a path. This means * all the users and groups that can access a given path. * |