]> source.dussan.org Git - nextcloud-server.git/commitdiff
Recursively fetch subshares
authorLouis Chemineau <louis@chmn.me>
Wed, 27 Apr 2022 11:17:22 +0000 (13:17 +0200)
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>
Tue, 26 Jul 2022 12:17:46 +0000 (12:17 +0000)
Signed-off-by: Louis Chemineau <louis@chmn.me>
apps/files_sharing/lib/Updater.php
lib/private/Share20/Manager.php
lib/public/Share/IManager.php

index a1159cc3f581606c4d475044b15f33fbc4ce15d3..071d4d3cca9bc38169378f7984ea6c2a5249a8c7 100644 (file)
@@ -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));
                        }
index 905a006372fc2ef42a5a3c2bb611c02f00d1e6a0..fd1a27af8cfb24cca0a87379e04ae885e7e64ffc 100644 (file)
@@ -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
         */
index f207ca87a2c982af86b6d2a71b1f540f6129d124..b1c980733fb7abf9e3ae93fb763848ddb4f5791c 100644 (file)
@@ -140,6 +140,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.
         *