We can't rely on the assumption that if the matching target is from the same owner that the share type will be different.
Files in different folders can have the same name. Therefore also a unique name has to be generated if the matching target it from the same user. Also for folders and files with the same name a unique target name has to be generated If matching target is from the same owner, use the same target. The share type will be different so this isn't the sa
This commit is contained in:
parent
550813ce41
commit
c6c0fcc7c8
|
@ -1002,8 +1002,22 @@ class Share {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if target already exists
|
// Check if target already exists
|
||||||
$checkTarget = self::getItems($itemType, $target, $shareType, $shareWith);
|
$targetConflict = false;
|
||||||
if (!empty($checkTarget)) {
|
|
||||||
|
if( $itemType == "file" or $itemType == "folder") {
|
||||||
|
$itemList1 = self::getItems("file", $target, $shareType, $shareWith);
|
||||||
|
$itemList2 = self::getItems("folder", $target, $shareType, $shareWith);
|
||||||
|
if ( !empty($itemList1) or !empty($itemList2)) {
|
||||||
|
$targetConflict = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$itemList = self::getItems($itemType, $target, $shareType, $shareWith);
|
||||||
|
if ( !empty($itemList) ) {
|
||||||
|
$targetConflict = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($targetConflict) {
|
||||||
foreach ($checkTarget as $item) {
|
foreach ($checkTarget as $item) {
|
||||||
// Skip item if it is the group parent row
|
// Skip item if it is the group parent row
|
||||||
if (isset($groupParent) && $item['id'] == $groupParent) {
|
if (isset($groupParent) && $item['id'] == $groupParent) {
|
||||||
|
@ -1013,21 +1027,27 @@ class Share {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
|
|
||||||
if ($item['uid_owner'] == $uidOwner) {
|
|
||||||
return $target;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!isset($exclude)) {
|
if (!isset($exclude)) {
|
||||||
$exclude = array();
|
$exclude = array();
|
||||||
}
|
}
|
||||||
// Find similar targets to improve backend's chances to generate a unqiue target
|
// Find similar targets to improve backend's chances to generate a unqiue target
|
||||||
if ($userAndGroups) {
|
if ($userAndGroups) {
|
||||||
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\') AND `'.$column.'` LIKE ?');
|
if ($column == 'file_target') {
|
||||||
$result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, '%'.$target.'%'));
|
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
|
||||||
|
$result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
|
||||||
} else {
|
} else {
|
||||||
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ? AND `'.$column.'` LIKE ?');
|
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
|
||||||
$result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith, '%'.$target.'%'));
|
$result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($column == 'file_target') {
|
||||||
|
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?');
|
||||||
|
$result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
|
||||||
|
} else {
|
||||||
|
$checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
|
||||||
|
$result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while ($row = $result->fetchRow()) {
|
while ($row = $result->fetchRow()) {
|
||||||
$exclude[] = $row[$column];
|
$exclude[] = $row[$column];
|
||||||
|
|
Loading…
Reference in New Issue