$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));
}
}, []);
}
+ 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
*/
*/
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.
*