diff options
-rw-r--r-- | apps/files_sharing/lib/Updater.php | 4 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 18 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 8 |
3 files changed, 27 insertions, 3 deletions
diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index a1159cc3f58..071d4d3cca9 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -69,9 +69,7 @@ class Updater { $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); if ($src instanceof Folder) { - // also check children - $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false); - // flatten the result + $subShares = $shareManager->getSharesInFolderRecursive($userFolder->getOwner()->getUID(), $src, false); foreach ($subShares as $subShare) { $shares = array_merge($shares, array_values($subShare)); } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 905a006372f..fd1a27af8cf 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1319,6 +1319,24 @@ class Manager implements IManager { }, []); } + public function getSharesInFolderRecursive(string $userId, Folder $node, $reshares = false) { + $shares = $this->getSharesInFolder($userId, $node, $reshares); + + foreach ($node->getDirectoryListing() as $subnode) { + if (!$subnode instanceof Folder) { + continue; + } + + $subShares = $this->getSharesInFolderRecursive($userId, $subnode, $reshares); + + foreach ($subShares as $fileId => $subSharesForFile) { + $shares[$fileId] = array_merge($shares[$fileId] ?? [], $subSharesForFile); + } + } + + return $shares; + } + /** * @inheritdoc */ diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index f207ca87a2c..b1c980733fb 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -141,6 +141,14 @@ interface IManager { public function getSharesInFolder($userId, Folder $node, $reshares = false); /** + * Recursively get all shares shared by (initiated) by the provided user in a folder. + * + * @return IShare[][] [$fileId => IShare[], ...] + * @since 11.0.0 + */ + public function getSharesInFolderRecursive(string $userId, Folder $node, bool $reshares = false); + + /** * Get shares shared by (initiated) by the provided user. * * @param string $userId |