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']; $source = $_GET['source'];
$uid_shared_with = array($_GET['uid_shared_with']); $uid_shared_with = array($_GET['uid_shared_with']);
error_log("deleteitem called".$source.$uid_shared_with);
OC_SHARE::unshare($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(?,?,?,?,?)"); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
foreach ($uid_shared_with as $uid) { foreach ($uid_shared_with as $uid) {
$target = "/".$uid."/files/Share/".basename($source); $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 = ?");
// $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); $result = $check->execute(array($target, $uid))->fetchAll();
// $result = $check->execute(array($target, $uid))->fetchAll(); if (count($result) > 0) {
// $counter = 1; if ($pos = strrpos($target, ".")) {
// while (count($result > 0)) { $name = substr($target, 0, $pos);
// if ($pos = strrpos($target, ".")) { $ext = substr($target, $pos);
// $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); } else {
// } else { $name = $target;
// $target .= $counter; }
// } $counter = 1;
// $result = $check->execute(array($target, $uid))->fetchAll(); 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)); $query->execute(array($uid_owner, $uid, $source, $target, $permissions));
} }
} }