Append number to name if target file already exists

This commit is contained in:
Michael Gapczynski 2011-07-20 14:16:20 -04:00
parent 029b21bf54
commit c9082d5b0d
2 changed files with 17 additions and 13 deletions

View File

@ -6,7 +6,6 @@ require_once('../lib_share.php');
$source = $_GET['source'];
$uid_shared_with = array($_GET['uid_shared_with']);
error_log("deleteitem called".$source.$uid_shared_with);
OC_SHARE::unshare($source, $uid_shared_with);
?>

View File

@ -45,18 +45,23 @@ class OC_SHARE {
$query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
foreach ($uid_shared_with as $uid) {
$target = "/".$uid."/files/Share/".basename($source);
// TODO Fix check if target already exists
// $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
// $result = $check->execute(array($target, $uid))->fetchAll();
// $counter = 1;
// while (count($result > 0)) {
// if ($pos = strrpos($target, ".")) {
// $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos);
// } else {
// $target .= $counter;
// }
// $result = $check->execute(array($target, $uid))->fetchAll();
// }
$check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
$result = $check->execute(array($target, $uid))->fetchAll();
if (count($result) > 0) {
if ($pos = strrpos($target, ".")) {
$name = substr($target, 0, $pos);
$ext = substr($target, $pos);
} else {
$name = $target;
}
$counter = 1;
while (count($result) > 0) {
$newTarget = $name."_".$counter.isset($ext);
$result = $check->execute(array($newTarget, $uid))->fetchAll();
$counter++;
}
$target = $newTarget;
}
$query->execute(array($uid_owner, $uid, $source, $target, $permissions));
}
}