]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix shared collection item searching
authorMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 15:50:12 +0000 (11:50 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 15:50:12 +0000 (11:50 -0400)
core/ajax/share.php
lib/public/share.php

index 3ace97d4d023b98f90a13e6918b2170542bf07d2..5b6763c08e7047c009d989ca0e4b682a46475eb3 100644 (file)
@@ -72,7 +72,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
                                        $reshare = false;
                                }
                                if ($_GET['checkShares'] == 'true') {
-                                       $shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource']);
+                                       $shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true);
                                } else {
                                        $shares = false;
                                }
index 5ed04c3e160b5f5c4a55675fd91f640d6e98ecd1..3e42e91d045afddade95d382efa2a8d4c1eb26e9 100644 (file)
@@ -629,7 +629,6 @@ class Share {
                }
                $root = strlen($root);
                $query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
-               
                $result = $query->execute($queryArgs);
                $items = array();
                $targets = array();
@@ -692,37 +691,47 @@ class Share {
                                // Check if this is a collection of the requested item type
                                if ($includeCollections && in_array($row['item_type'], $collectionTypes)) {
                                        if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) {
-                                               $row['collection'] = array('item_type' => $itemType, $column => $row[$column]);
-                                               // Fetch all of the children sources
-                                               $children = $collectionBackend->getChildren($row[$column]);
-                                               foreach ($children as $child) {
-                                                       $childItem = $row;
-                                                       if ($row['item_type'] != 'file' && $row['item_type'] != 'folder') {
-                                                               $childItem['item_source'] = $child['source'];
-                                                               $childItem['item_target'] = $child['target'];
-                                                       }
-                                                       if ($backend instanceof Share_Backend_File_Dependent) {
-                                                               if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
-                                                                       $childItem['file_source'] = $child['source'];
-                                                               } else {
-                                                                       $childItem['file_source'] = \OC_FileCache::getId($child['file_path']);
+                                               // Collections can be inside collections, check if the item is a collection
+                                               if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) {
+                                                       $collectionItems[] = $row;
+                                               } else {
+                                                       $row['collection'] = array('item_type' => $row['item_type'], $column => $row[$column]);
+                                                       // Fetch all of the children sources
+                                                       $children = $collectionBackend->getChildren($row[$column]);
+                                                       foreach ($children as $child) {
+                                                               $childItem = $row;
+                                                               $childItem['item_type'] = $itemType;
+                                                               if ($row['item_type'] != 'file' && $row['item_type'] != 'folder') {
+                                                                       $childItem['item_source'] = $child['source'];
+                                                                       $childItem['item_target'] = $child['target'];
                                                                }
-                                                               $childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']);
-                                                       }
-                                                       if (isset($item)) {
-                                                               if ($childItem[$column] == $item) {
-                                                                       // Return only the item instead of a 2-dimensional array
-                                                                       if ($limit == 1 && $format == self::FORMAT_NONE) {
-                                                                               return $childItem;
+                                                               if ($backend instanceof Share_Backend_File_Dependent) {
+                                                                       if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
+                                                                               $childItem['file_source'] = $child['source'];
                                                                        } else {
-                                                                               // Unset the items array and break out of both loops
-                                                                               $items = array();
-                                                                               $items[] = $childItem;
-                                                                               break 2;
+                                                                               $childItem['file_source'] = \OC_FileCache::getId($child['file_path']);
                                                                        }
+                                                                       $childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']);
+                                                               }
+                                                               if (isset($item)) {
+                                                                       if ($childItem[$column] == $item) {
+                                                                               // Return only the item instead of a 2-dimensional array
+                                                                               if ($limit == 1) {
+                                                                                       if ($format == self::FORMAT_NONE) {
+                                                                                               return $childItem;
+                                                                                       } else {
+                                                                                               // Unset the items array and break out of both loops
+                                                                                               $items = array();
+                                                                                               $items[] = $childItem;
+                                                                                               break 2;
+                                                                                       }
+                                                                               } else {
+                                                                                       $collectionItems[] = $childItem;
+                                                                               }
+                                                                       }
+                                                               } else {
+                                                                       $collectionItems[] = $childItem;
                                                                }
-                                                       } else {
-                                                               $collectionItems[] = $childItem;
                                                        }
                                                }
                                        }
@@ -1182,4 +1191,4 @@ interface Share_Backend_Collection extends Share_Backend {
        */
        public function getChildren($itemSource);
 
-}
+}
\ No newline at end of file