summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-09-08 23:07:43 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-09-08 23:09:57 -0400
commitb163bd514f65999cd8aa66262d10ca92dcdf99d1 (patch)
treefdda277cf4d0b7c8918258714f2e1ab8849faf72
parenta050915167cdcb0f5b99d5c0007ed9f9f25a20de (diff)
downloadnextcloud-server-b163bd514f65999cd8aa66262d10ca92dcdf99d1.tar.gz
nextcloud-server-b163bd514f65999cd8aa66262d10ca92dcdf99d1.zip
Fix fetching shared children items, fixes problem with displaying owner of a shared file inside a shared folder
-rw-r--r--apps/files_sharing/lib/share/folder.php22
-rw-r--r--lib/public/share.php29
2 files changed, 35 insertions, 16 deletions
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
index 665583e83ad..e29e9b7e002 100644
--- a/apps/files_sharing/lib/share/folder.php
+++ b/apps/files_sharing/lib/share/folder.php
@@ -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
diff --git a/lib/public/share.php b/lib/public/share.php
index a3cfe4f6ddb..87144735a68 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -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);