Fix bug in constructor for appending numbers to already existing targets

This commit is contained in:
Michael Gapczynski 2011-07-20 16:41:39 -04:00
parent 3e6037659e
commit fcda3a338c
1 changed files with 3 additions and 1 deletions

View File

@ -47,16 +47,18 @@ class OC_SHARE {
$target = "/".$uid."/files/Share/".basename($source); $target = "/".$uid."/files/Share/".basename($source);
$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();
// Check if target already exists for the user, if it does append a number to the name
if (count($result) > 0) { if (count($result) > 0) {
if ($pos = strrpos($target, ".")) { if ($pos = strrpos($target, ".")) {
$name = substr($target, 0, $pos); $name = substr($target, 0, $pos);
$ext = substr($target, $pos); $ext = substr($target, $pos);
} else { } else {
$name = $target; $name = $target;
$ext = "";
} }
$counter = 1; $counter = 1;
while (count($result) > 0) { while (count($result) > 0) {
$newTarget = $name."_".$counter.isset($ext); $newTarget = $name."_".$counter.$ext;
$result = $check->execute(array($newTarget, $uid))->fetchAll(); $result = $check->execute(array($newTarget, $uid))->fetchAll();
$counter++; $counter++;
} }