Properties work fine now

This commit is contained in:
Jakob Sack 2011-07-22 22:30:45 +02:00
parent 5851da47f1
commit 3b92ec12c2
2 changed files with 19 additions and 15 deletions

View File

@ -20,6 +20,7 @@ require_once("lib/base.php");
* *
* CREATE TABLE locks ( * CREATE TABLE locks (
* `id` INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, * `id` INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
* `userid` VARCHAR(200),
* `owner` VARCHAR(100), * `owner` VARCHAR(100),
* `timeout` INTEGER UNSIGNED, * `timeout` INTEGER UNSIGNED,
* `created` INTEGER, * `created` INTEGER,
@ -50,8 +51,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
// NOTE: the following 10 lines or so could be easily replaced by // NOTE: the following 10 lines or so could be easily replaced by
// pure sql. MySQL's non-standard string concatination prevents us // pure sql. MySQL's non-standard string concatination prevents us
// from doing this though. // from doing this though.
$query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM *PREFIX*locks WHERE ((created + timeout) > CAST(? AS UNSIGNED INTEGER)) AND ((uri = ?)'; $query = 'SELECT * FROM *PREFIX*locks WHERE userid = ? AND ((created + timeout) > CAST(? AS UNSIGNED INTEGER)) AND ((uri = ?)';
$params = array(time(),$uri); $params = array(OC_USER::getUser(),time(),$uri);
// We need to check locks for every part in the uri. // We need to check locks for every part in the uri.
$uriParts = explode('/',$uri); $uriParts = explode('/',$uri);
@ -122,19 +123,17 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
} }
if ($exists) { if ($exists) {
$query = OC_DB::prepare( 'UPDATE *PREFIX*locks SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?' ); $query = OC_DB::prepare( 'UPDATE *PREFIX*locks SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE userid = ? AND token = ?' );
$result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token)); $result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,OC_USER::getUser(),$lockInfo->token));
} else { } else {
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*locks (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)' ); $query = OC_DB::prepare( 'INSERT INTO *PREFIX*locks (userid,owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?,?)' );
$result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token)); $result = $query->execute( array(OC_USER::getUser(),$lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token));
} }
return true; return true;
} }
/** /**
* Removes a lock from a uri * Removes a lock from a uri
* *
@ -144,8 +143,8 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract {
*/ */
public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) { public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) {
$query = OC_DB::prepare( 'DELETE FROM *PREFIX*locks WHERE path=? AND token=?' ); $query = OC_DB::prepare( 'DELETE FROM *PREFIX*locks WHERE userid = ? AND path=? AND token=?' );
$result = $query->execute( array($uri,$lockInfo->token)); $result = $query->execute( array(OC_USER::getUser(),$uri,$lockInfo->token));
return $result->numRows() === 1; return $result->numRows() === 1;

View File

@ -71,10 +71,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
list(, $newName) = Sabre_DAV_URLUtil::splitPath($name); list(, $newName) = Sabre_DAV_URLUtil::splitPath($name);
$newPath = $parentPath . '/' . $newName; $newPath = $parentPath . '/' . $newName;
$oldPath = $this->path;
OC_FILESYSTEM::rename($this->path,$newPath); OC_FILESYSTEM::rename($this->path,$newPath);
$this->path = $newPath; $this->path = $newPath;
$query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertypath = ? WHERE userid = ? AND propertypath = ?' );
$query->execute( array( $newPath,OC_USER::getUser(), $oldPath ));
} }
@ -104,17 +109,17 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
if (is_null($propertyValue)) { if (is_null($propertyValue)) {
if(array_key_exists( $propertyName, $existing )){ if(array_key_exists( $propertyName, $existing )){
$query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' );
$query->execute( array( 'OC_USER::getUser()', $this->path, $propertyName )); $query->execute( array( OC_USER::getUser(), $this->path, $propertyName ));
} }
} }
else { else {
if(!array_key_exists( $propertyName, $existing )){ if(!array_key_exists( $propertyName, $existing )){
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' );
$query->execute( array( 'OC_USER::getUser()', $this->path, $propertyName,$propertyValue )); $query->execute( array( OC_USER::getUser(), $this->path, $propertyName,$propertyValue ));
} }
elseif($existing[$propertyName] !== $propertyValue){ else{
$query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertyvalue = ? WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); $query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertyvalue = ? WHERE userid = ? AND propertypath = ? AND propertyname = ?' );
$query->execute( array( $propertyValue,'OC_USER::getUser()', $this->path, $propertyName )); $query->execute( array( $propertyValue,OC_USER::getUser(), $this->path, $propertyName ));
} }
} }
@ -134,7 +139,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
function getProperties($properties) { function getProperties($properties) {
// At least some magic in here :-) // At least some magic in here :-)
$query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' );
$result = $query->execute( array( 'OC_USER::getUser()', $this->path )); $result = $query->execute( array( OC_USER::getUser(), $this->path ));
$existing = array(); $existing = array();
while( $row = $result->fetchRow()){ while( $row = $result->fetchRow()){