Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring
This commit is contained in:
commit
77fe7240f0
|
@ -150,7 +150,6 @@
|
||||||
*/
|
*/
|
||||||
function fileinfo($path)
|
function fileinfo($path)
|
||||||
{
|
{
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
|
|
||||||
// map URI path to filesystem path
|
// map URI path to filesystem path
|
||||||
$fspath =$path;
|
$fspath =$path;
|
||||||
|
@ -185,8 +184,8 @@
|
||||||
$info["props"][] = $this->mkprop("getcontentlength", OC_FILESYSTEM::filesize($fspath));
|
$info["props"][] = $this->mkprop("getcontentlength", OC_FILESYSTEM::filesize($fspath));
|
||||||
}
|
}
|
||||||
// get additional properties from database
|
// get additional properties from database
|
||||||
$query = "SELECT ns, name, value FROM {$CONFIG_DBTABLEPREFIX}properties WHERE path = '$path'";
|
$query = OC_DB::prepare("SELECT ns, name, value FROM *PREFIX*properties WHERE path = ?");
|
||||||
$res = OC_DB::select($query);
|
$res = $query->execute(array($path))->fetchAll();
|
||||||
foreach($res as $row){
|
foreach($res as $row){
|
||||||
$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
|
$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
|
||||||
}
|
}
|
||||||
|
@ -391,7 +390,6 @@
|
||||||
*/
|
*/
|
||||||
function DELETE($options)
|
function DELETE($options)
|
||||||
{
|
{
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
$path =$options["path"];
|
$path =$options["path"];
|
||||||
if (!OC_FILESYSTEM::file_exists($path)) {
|
if (!OC_FILESYSTEM::file_exists($path)) {
|
||||||
return "404 Not found";
|
return "404 Not found";
|
||||||
|
@ -405,14 +403,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OC_FILESYSTEM::is_dir($path)) {
|
if (OC_FILESYSTEM::is_dir($path)) {
|
||||||
$query = "DELETE FROM {$CONFIG_DBTABLEPREFIX}properties WHERE path LIKE '".$this->_slashify($options["path"])."%'";
|
$query = OC_DB::prepare("DELETE FROM *PREFIX*properties WHERE path LIKE '?%'");
|
||||||
OC_DB::query($query);
|
$query->execute(array($this->_slashify($options["path"])));
|
||||||
OC_FILESYSTEM::delTree($path);
|
OC_FILESYSTEM::delTree($path);
|
||||||
} else {
|
} else {
|
||||||
OC_FILESYSTEM::unlink($path);
|
OC_FILESYSTEM::unlink($path);
|
||||||
}
|
}
|
||||||
$query = "DELETE FROM {$CONFIG_DBTABLEPREFIX}properties WHERE path = '$options[path]'";
|
$query = OC_DB::prepare("DELETE FROM *PREFIX*properties WHERE path = ?");
|
||||||
OC_DB::query($query);
|
$query->execute(array($options[path]));
|
||||||
|
|
||||||
return "204 No Content";
|
return "204 No Content";
|
||||||
}
|
}
|
||||||
|
@ -438,7 +436,6 @@
|
||||||
function COPY($options, $del=false)
|
function COPY($options, $del=false)
|
||||||
{
|
{
|
||||||
// TODO Property updates still broken (Litmus should detect this?)
|
// TODO Property updates still broken (Litmus should detect this?)
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
|
|
||||||
if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
|
if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
|
||||||
return "415 Unsupported media type";
|
return "415 Unsupported media type";
|
||||||
|
@ -512,18 +509,18 @@
|
||||||
}
|
}
|
||||||
$destpath = $this->_unslashify($options["dest"]);
|
$destpath = $this->_unslashify($options["dest"]);
|
||||||
if (is_dir($source)) {
|
if (is_dir($source)) {
|
||||||
$dpath=OC_DB::escape($destpath);
|
$dpath=$destpath;
|
||||||
$path=OC_DB::escape($options["path"]);
|
$path=$options["path"];
|
||||||
$query = "UPDATE {$CONFIG_DBTABLEPREFIX}properties
|
$query = OC_DB::prepare("UPDATE *PREFIX*properties
|
||||||
SET path = REPLACE(path, '$path', '$dpath')
|
SET path = REPLACE(path, ?, ?)
|
||||||
WHERE path LIKE '$path%'";
|
WHERE path LIKE '?%'");
|
||||||
OC_DB::query($query);
|
$query->execute(array($path,$dpath,$path));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "UPDATE {$CONFIG_DBTABLEPREFIX}properties
|
$query = OC_DB::prepare("UPDATE *PREFIX*properties
|
||||||
SET path = '$dpath'
|
SET path = ?
|
||||||
WHERE path = '$path'";
|
WHERE path = ?");
|
||||||
OC_DB::query($query);
|
$query->execute(array($dpath,$path));
|
||||||
} else {
|
} else {
|
||||||
if (OC_FILESYSTEM::is_dir($source)) {
|
if (OC_FILESYSTEM::is_dir($source)) {
|
||||||
$files = OC_FILESYSTEM::getTree($source);
|
$files = OC_FILESYSTEM::getTree($source);
|
||||||
|
@ -572,7 +569,6 @@
|
||||||
function PROPPATCH(&$options)
|
function PROPPATCH(&$options)
|
||||||
{
|
{
|
||||||
global $prefs, $tab;
|
global $prefs, $tab;
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
|
|
||||||
$msg = "";
|
$msg = "";
|
||||||
$path = $options["path"];
|
$path = $options["path"];
|
||||||
|
@ -583,16 +579,17 @@
|
||||||
if ($prop["ns"] == "DAV:") {
|
if ($prop["ns"] == "DAV:") {
|
||||||
$options["props"][$key]['status'] = "403 Forbidden";
|
$options["props"][$key]['status'] = "403 Forbidden";
|
||||||
} else {
|
} else {
|
||||||
$path=OC_DB::escape($options['path']);
|
$path=$options['path'];
|
||||||
$name=OC_DB::escape($prop['name']);
|
$name=$prop['name'];
|
||||||
$ns=OC_DB::escape($prop['ns']);
|
$ns=$prop['ns'];
|
||||||
$val=OC_DB::escape($prop['val']);
|
$val=$prop['val'];
|
||||||
if (isset($prop["val"])) {
|
if (isset($prop["val"])) {
|
||||||
$query = "REPLACE INTO {$CONFIG_DBTABLEPREFIX}properties (path,name,ns,value) VALUES('$path','$name','$ns','$val')";
|
$query = OC_DB::prepare("REPLACE INTO *PREFIX*properties (path,name,ns,value) VALUES(?,?,?,?)");
|
||||||
|
$query->execute(array($path,$name,$ns,$val));
|
||||||
} else {
|
} else {
|
||||||
$query = "DELETE FROM {$CONFIG_DBTABLEPREFIX}properties WHERE path = '$path' AND name = '$name' AND ns = '$ns'";
|
$query = $query = OC_DB::prepare("DELETE FROM *PREFIX*properties WHERE path = ? AND name = ? AND ns = ?");
|
||||||
|
$query->execute(array($path,$name,$ns));
|
||||||
}
|
}
|
||||||
OC_DB::query($query);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,7 +605,6 @@
|
||||||
*/
|
*/
|
||||||
function LOCK(&$options)
|
function LOCK(&$options)
|
||||||
{
|
{
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
|
|
||||||
// get absolute fs path to requested resource
|
// get absolute fs path to requested resource
|
||||||
$fspath = $options["path"];
|
$fspath = $options["path"];
|
||||||
|
@ -630,15 +626,15 @@
|
||||||
$options["timeout"] = time()+300; // 5min. hardcoded
|
$options["timeout"] = time()+300; // 5min. hardcoded
|
||||||
|
|
||||||
if (isset($options["update"])) { // Lock Update
|
if (isset($options["update"])) { // Lock Update
|
||||||
$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
|
$where = "WHERE path = ? AND token = ?";
|
||||||
|
|
||||||
$query = "SELECT owner, exclusivelock FROM {$CONFIG_DBTABLEPREFIX}locks $where";
|
$query = OC_DB::prepare("SELECT owner, exclusivelock FROM *PREFIX*locks $where");
|
||||||
$res = OC_DB::select($query);
|
$res = $query->execute(array($options[path],$options[update]))->fetchAll();
|
||||||
|
|
||||||
if (is_array($res) and isset($res[0])) {
|
if (is_array($res) and isset($res[0])) {
|
||||||
$row=$res[0];
|
$row=$res[0];
|
||||||
$query = "UPDATE `{$CONFIG_DBTABLEPREFIX}locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
|
$query = OC_DB::prepare("UPDATE `*PREFIX*locks` SET `expires` = , `modified` = $where");
|
||||||
OC_DB::query($query);
|
$query->execute(array($options[timeout],time(),$options[path],$options[update]));
|
||||||
|
|
||||||
$options['owner'] = $row['owner'];
|
$options['owner'] = $row['owner'];
|
||||||
$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
|
$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
|
||||||
|
@ -646,16 +642,13 @@
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {//check for indirect refresh
|
} else {//check for indirect refresh
|
||||||
$query = "SELECT *
|
$query = OC_DB::prepare("SELECT * FROM *PREFIX*locks WHERE recursive = 1");
|
||||||
FROM {$CONFIG_DBTABLEPREFIX}locks
|
$res = $query->execute();
|
||||||
WHERE recursive = 1
|
|
||||||
";
|
|
||||||
$res = OC_DB::select($query);
|
|
||||||
foreach($res as $row){
|
foreach($res as $row){
|
||||||
if(strpos($options['path'],$row['path'])==0){//are we a child of a folder with an recursive lock
|
if(strpos($options['path'],$row['path'])==0){//are we a child of a folder with an recursive lock
|
||||||
$where = "WHERE path = '$row[path]' AND token = '$options[update]'";
|
$where = "WHERE path = ? AND token = ?";
|
||||||
$query = "UPDATE `{$CONFIG_DBTABLEPREFIX}locks` SET `expires` = '$options[timeout]', `modified` = ".time()." $where";
|
$query = OC_DB::prepare("UPDATE `*PREFIX*locks` SET `expires` = ?, `modified` = ? $where");
|
||||||
OC_DB::query($query);
|
$query->execute(array($options[timeout],time(),$row[path],$options[update]));
|
||||||
$options['owner'] = $row['owner'];
|
$options['owner'] = $row['owner'];
|
||||||
$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
|
$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
|
||||||
$options['type'] = $row["exclusivelock"] ? "write" : "read";
|
$options['type'] = $row["exclusivelock"] ? "write" : "read";
|
||||||
|
@ -665,21 +658,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$locktoken=OC_DB::escape($options['locktoken']);
|
$locktoken=$options['locktoken'];
|
||||||
$path=OC_DB::escape($options['path']);
|
$path=$options['path'];
|
||||||
$time=time();
|
$time=time();
|
||||||
$owner=OC_DB::escape($options['owner']);
|
$owner=$options['owner'];
|
||||||
$timeout=OC_DB::escape($options['timeout']);
|
$timeout=$options['timeout'];
|
||||||
$exclusive=($options['scope'] === "exclusive" ? "1" : "0");
|
$exclusive=($options['scope'] === "exclusive" ? "1" : "0");
|
||||||
$query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}locks`
|
$query = OC_DB::prepare("INSERT INTO `*PREFIX*locks`
|
||||||
(`token`,`path`,`created`,`modified`,`owner`,`expires`,`exclusivelock`,`recursive`)
|
(`token`,`path`,`created`,`modified`,`owner`,`expires`,`exclusivelock`,`recursive`)
|
||||||
VALUES ('$locktoken','$path',$time,$time,'$owner','timeout',$exclusive,$recursion)";
|
VALUES (?,?,?,?,?,'timeout',?,?)");
|
||||||
OC_DB::query($query);
|
$result=$query->execute(array($locktoken,$path,$time,$time,$owner,$exclusive,$recursion));
|
||||||
$rows=OC_DB::affected_rows();
|
|
||||||
if(!OC_FILESYSTEM::file_exists($fspath) and $rows>0) {
|
if(!OC_FILESYSTEM::file_exists($fspath) and $rows>0) {
|
||||||
return "201 Created";
|
return "201 Created";
|
||||||
}
|
}
|
||||||
return OC_DB::affected_rows($rows) ? "200 OK" : "409 Conflict";
|
return PEAR::isError($result) ? "409 Conflict" : "200 OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -690,13 +682,11 @@ VALUES ('$locktoken','$path',$time,$time,'$owner','timeout',$exclusive,$recursio
|
||||||
*/
|
*/
|
||||||
function UNLOCK(&$options)
|
function UNLOCK(&$options)
|
||||||
{
|
{
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
$query = OC_DB::prepare("DELETE FROM *PREFIX*locks
|
||||||
$query = "DELETE FROM {$CONFIG_DBTABLEPREFIX}locks
|
WHERE path = ?
|
||||||
WHERE path = '$options[path]'
|
AND token = ?");
|
||||||
AND token = '$options[token]'";
|
$query->execute(array($options[path]),$options[token]);
|
||||||
OC_DB::query($query);
|
return PEAR::isError($result) ? "409 Conflict" : "204 No Content";
|
||||||
|
|
||||||
return OC_DB::affected_rows() ? "204 No Content" : "409 Conflict";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -707,14 +697,12 @@ VALUES ('$locktoken','$path',$time,$time,'$owner','timeout',$exclusive,$recursio
|
||||||
*/
|
*/
|
||||||
function checkLock($path)
|
function checkLock($path)
|
||||||
{
|
{
|
||||||
global $CONFIG_DBTABLEPREFIX;
|
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
$query = "SELECT *
|
$query = OC_DB::prepare("SELECT *
|
||||||
FROM {$CONFIG_DBTABLEPREFIX}locks
|
FROM *PREFIX*locks
|
||||||
WHERE path = '$path'
|
WHERE path = ?
|
||||||
";
|
");
|
||||||
$res = OC_DB::select($query);
|
$res = $query->execute(array($path))->fetchAll();
|
||||||
if (is_array($res) and isset($res[0])) {
|
if (is_array($res) and isset($res[0])) {
|
||||||
$row=$res[0];
|
$row=$res[0];
|
||||||
|
|
||||||
|
@ -732,11 +720,11 @@ VALUES ('$locktoken','$path',$time,$time,'$owner','timeout',$exclusive,$recursio
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//check for recursive locks;
|
//check for recursive locks;
|
||||||
$query = "SELECT *
|
$query = OC_DB::prepare("SELECT *
|
||||||
FROM {$CONFIG_DBTABLEPREFIX}locks
|
FROM *PREFIX*locks
|
||||||
WHERE recursive = 1
|
WHERE recursive = 1
|
||||||
";
|
");
|
||||||
$res = OC_DB::select($query);
|
$res = $query->execute()->fetchAll();
|
||||||
foreach($res as $row){
|
foreach($res as $row){
|
||||||
if(strpos($path,$row['path'])==0){//are we a child of a folder with an recursive lock
|
if(strpos($path,$row['path'])==0){//are we a child of a folder with an recursive lock
|
||||||
$result = array( "type" => "write",
|
$result = array( "type" => "write",
|
||||||
|
|
Loading…
Reference in New Issue