]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix fetching shared children items, fixes problem with displaying owner of a shared...
authorMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 03:07:43 +0000 (23:07 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 03:09:57 +0000 (23:09 -0400)
apps/files_sharing/lib/share/folder.php
lib/public/share.php

index 665583e83ad603e3cc75d5e07b32dedaf68120c3..e29e9b7e002fba685424a6b7d1a2f8a7f572314c 100644 (file)
@@ -19,7 +19,7 @@
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-class OC_Share_Backend_Folder extends OC_Share_Backend_File {
+class OC_Share_Backend_Folder extends OC_Share_Backend_File implements OCP\Share_Backend_Collection {
 
        public function formatItems($items, $format, $parameters = null) {
                if ($format == self::FORMAT_SHARED_STORAGE) {
@@ -50,12 +50,22 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File {
        }
 
        public function getChildren($itemSource) {
-               $files = OC_FileCache::getFolderContent($itemSource);
-               $sources = array();
-               foreach ($files as $file) {
-                       $sources[] = $file['path'];
+               $children = array();
+               $parents = array($itemSource);
+               while (!empty($parents)) {
+                       $parents = "'".implode("','", $parents)."'";
+                       $query = OC_DB::prepare('SELECT `id`, `name`, `mimetype` FROM `*PREFIX*fscache` WHERE `parent` IN ('.$parents.')');
+                       $result = $query->execute();
+                       $parents = array();
+                       while ($file = $result->fetchRow()) {
+                               $children[] = array('source' => $file['id'], 'file_path' => $file['name']);
+                               // If a child folder is found look inside it 
+                               if ($file['mimetype'] == 'httpd/unix-directory') {
+                                       $parents[] = $file['id'];
+                               }
+                       }
                }
-               return $sources;
+               return $children;
        }
 
 }
\ No newline at end of file
index a3cfe4f6ddb56153b2ba3bdc35c0352472dd5307..87144735a6836465e9c6c496e6e21e98d821b027 100644 (file)
@@ -458,8 +458,8 @@ class Share {
                                $collectionTypes[] = $type;
                        }
                }
-               if (count($collectionTypes) > 1) {
-                       unset($collectionTypes[0]);
+               // Return array if collections were found or the item type is a collection itself - collections can be inside collections
+               if (count($collectionTypes) > 1 || self::getBackend($itemType) instanceof Share_Backend_Collection) {
                        return $collectionTypes;
                }
                return false;
@@ -504,10 +504,9 @@ class Share {
                        $root = '';
                        if ($includeCollections && !isset($item) && ($collectionTypes = self::getCollectionItemTypes($itemType))) {
                                // If includeCollections is true, find collections of this item type, e.g. a music album contains songs
-                               $itemTypes = array_merge(array($itemType), $collectionTypes);
-                               $placeholders = join(',', array_fill(0, count($itemTypes), '?'));
-                               $where = ' WHERE `item_type` IN ('.$placeholders.')';
-                               $queryArgs = $itemTypes;
+                               $placeholders = join(',', array_fill(0, count($collectionTypes), '?'));
+                               $where .= ' OR item_type IN ('.$placeholders.'))';
+                               $queryArgs = $collectionTypes;
                        } else {
                                $where = ' WHERE `item_type` = ?';
                                $queryArgs = array($itemType);
@@ -690,15 +689,25 @@ class Share {
                                        }
                                }
                                // Check if this is a collection of the requested item type
-                               if ($includeCollections && $row['item_type'] != $itemType) {
+                               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;
-                                                       $childItem['item_source'] = $child;
-       //                                              $childItem['item_target'] = $child['target']; TODO
+                                                       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']);
+                                                               }
+                                                               $childItem['file_target'] = $child['file_path'];
+                                                       }
                                                        if (isset($item)) {
                                                                if ($childItem[$column] == $item) {
                                                                        // Return only the item instead of a 2-dimensional array
@@ -1167,7 +1176,7 @@ interface Share_Backend_Collection extends Share_Backend {
        /**
        * @brief Get the sources of the children of the item
        * @param string Item source
-       * @return array Returns an array of sources
+       * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable
        */
        public function getChildren($itemSource);