Fix fetching shared children items, fixes problem with displaying owner of a shared file inside a shared folder
This commit is contained in:
parent
a050915167
commit
b163bd514f
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue