Fix shared collection item searching

This commit is contained in:
Michael Gapczynski 2012-09-09 11:50:12 -04:00
parent 3e7951e1e6
commit 13d513c17c
2 changed files with 39 additions and 30 deletions

View 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;
}

View 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,11 +691,16 @@ 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]);
// 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'];
@ -712,7 +716,8 @@ class Share {
if (isset($item)) {
if ($childItem[$column] == $item) {
// Return only the item instead of a 2-dimensional array
if ($limit == 1 && $format == self::FORMAT_NONE) {
if ($limit == 1) {
if ($format == self::FORMAT_NONE) {
return $childItem;
} else {
// Unset the items array and break out of both loops
@ -720,12 +725,16 @@ class Share {
$items[] = $childItem;
break 2;
}
} else {
$collectionItems[] = $childItem;
}
}
} else {
$collectionItems[] = $childItem;
}
}
}
}
// Remove collection item
unset($items[$row['id']]);
}