Skip to content
Snippets Groups Projects
Commit e9d25e4f authored by Thomas Müller's avatar Thomas Müller
Browse files

using Doctrine\DBAL\Connection::executeUpdate()

parent f5b62267
Branches
No related tags found
No related merge requests found
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
namespace OC\Connector\Sabre; namespace OC\Connector\Sabre;
use \Sabre\DAV\PropFind; use OCP\IDBConnection;
use \Sabre\DAV\PropPatch; use OCP\IUser;
use \Sabre\HTTP\RequestInterface; use Sabre\DAV\PropertyStorage\Backend\BackendInterface;
use \Sabre\HTTP\ResponseInterface; use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
use Sabre\DAV\Tree;
class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\BackendInterface { class CustomPropertiesBackend implements BackendInterface {
/** /**
* Ignored properties * Ignored properties
...@@ -49,17 +51,17 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -49,17 +51,17 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
); );
/** /**
* @var \Sabre\DAV\Tree * @var Tree
*/ */
private $tree; private $tree;
/** /**
* @var \OCP\IDBConnection * @var IDBConnection
*/ */
private $connection; private $connection;
/** /**
* @var \OCP\IUser * @var IUser
*/ */
private $user; private $user;
...@@ -71,14 +73,14 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -71,14 +73,14 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
private $cache = []; private $cache = [];
/** /**
* @param \Sabre\DAV\Tree $tree node tree * @param Tree $tree node tree
* @param \OCP\IDBConnection $connection database connection * @param IDBConnection $connection database connection
* @param \OCP\IUser $user owner of the tree and properties * @param IUser $user owner of the tree and properties
*/ */
public function __construct( public function __construct(
\Sabre\DAV\Tree $tree, Tree $tree,
\OCP\IDBConnection $connection, IDBConnection $connection,
\OCP\IUser $user) { IUser $user) {
$this->tree = $tree; $this->tree = $tree;
$this->connection = $connection; $this->connection = $connection;
$this->user = $user->getUID(); $this->user = $user->getUID();
...@@ -93,7 +95,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -93,7 +95,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
*/ */
public function propFind($path, PropFind $propFind) { public function propFind($path, PropFind $propFind) {
$node = $this->tree->getNodeForPath($path); $node = $this->tree->getNodeForPath($path);
if (!($node instanceof \OC\Connector\Sabre\Node)) { if (!($node instanceof Node)) {
return; return;
} }
...@@ -109,7 +111,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -109,7 +111,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
return; return;
} }
if ($node instanceof \OC\Connector\Sabre\Directory if ($node instanceof Directory
&& $propFind->getDepth() !== 0 && $propFind->getDepth() !== 0
) { ) {
// note: pre-fetching only supported for depth <= 1 // note: pre-fetching only supported for depth <= 1
...@@ -132,7 +134,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -132,7 +134,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
*/ */
public function propPatch($path, PropPatch $propPatch) { public function propPatch($path, PropPatch $propPatch) {
$node = $this->tree->getNodeForPath($path); $node = $this->tree->getNodeForPath($path);
if (!($node instanceof \OC\Connector\Sabre\Node)) { if (!($node instanceof Node)) {
return; return;
} }
...@@ -175,7 +177,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -175,7 +177,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
/** /**
* Returns a list of properties for this nodes.; * Returns a list of properties for this nodes.;
* @param \OC\Connector\Sabre\Node $node * @param Node $node
* @param array $requestedProperties requested properties or empty array for "all" * @param array $requestedProperties requested properties or empty array for "all"
* @return array * @return array
* @note The properties list is a list of propertynames the client * @note The properties list is a list of propertynames the client
...@@ -183,7 +185,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -183,7 +185,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
* http://www.example.org/namespace#author If the array is empty, all * http://www.example.org/namespace#author If the array is empty, all
* properties should be returned * properties should be returned
*/ */
private function getProperties(\OC\Connector\Sabre\Node $node, array $requestedProperties) { private function getProperties(Node $node, array $requestedProperties) {
$path = $node->getPath(); $path = $node->getPath();
if (isset($this->cache[$path])) { if (isset($this->cache[$path])) {
return $this->cache[$path]; return $this->cache[$path];
...@@ -222,7 +224,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -222,7 +224,7 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
/** /**
* Update properties * Update properties
* *
* @param \OC\Connector\Sabre\Node $node node for which to update properties * @param Node $node node for which to update properties
* @param array $properties array of properties to update * @param array $properties array of properties to update
* *
* @return bool * @return bool
...@@ -230,20 +232,14 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -230,20 +232,14 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
private function updateProperties($node, $properties) { private function updateProperties($node, $properties) {
$path = $node->getPath(); $path = $node->getPath();
$deleteStatement = $this->connection->prepare( $deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
'DELETE FROM `*PREFIX*properties`' . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'
);
$insertStatement = $this->connection->prepare( $insertStatement = 'INSERT INTO `*PREFIX*properties`' .
'INSERT INTO `*PREFIX*properties`' . ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'
);
$updateStatement = $this->connection->prepare( $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'
);
// TODO: use "insert or update" strategy ? // TODO: use "insert or update" strategy ?
$existing = $this->getProperties($node, array()); $existing = $this->getProperties($node, array());
...@@ -252,18 +248,17 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -252,18 +248,17 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
// If it was null, we need to delete the property // If it was null, we need to delete the property
if (is_null($propertyValue)) { if (is_null($propertyValue)) {
if (array_key_exists($propertyName, $existing)) { if (array_key_exists($propertyName, $existing)) {
$deleteStatement->execute( $this->connection->executeUpdate($deleteStatement,
array( array(
$this->user, $this->user,
$path, $path,
$propertyName $propertyName
) )
); );
$deleteStatement->closeCursor();
} }
} else { } else {
if (!array_key_exists($propertyName, $existing)) { if (!array_key_exists($propertyName, $existing)) {
$insertStatement->execute( $this->connection->executeUpdate($insertStatement,
array( array(
$this->user, $this->user,
$path, $path,
...@@ -271,9 +266,8 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -271,9 +266,8 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
$propertyValue $propertyValue
) )
); );
$insertStatement->closeCursor();
} else { } else {
$updateStatement->execute( $this->connection->executeUpdate($updateStatement,
array( array(
$propertyValue, $propertyValue,
$this->user, $this->user,
...@@ -281,7 +275,6 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -281,7 +275,6 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
$propertyName $propertyName
) )
); );
$updateStatement->closeCursor();
} }
} }
} }
...@@ -295,12 +288,12 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -295,12 +288,12 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
/** /**
* Bulk load properties for directory children * Bulk load properties for directory children
* *
* @param \OC\Connector\Sabre\Directory $node * @param Directory $node
* @param array $requestedProperties requested properties * @param array $requestedProperties requested properties
* *
* @return void * @return void
*/ */
private function loadChildrenProperties(\OC\Connector\Sabre\Directory $node, $requestedProperties) { private function loadChildrenProperties(Directory $node, $requestedProperties) {
$path = $node->getPath(); $path = $node->getPath();
if (isset($this->cache[$path])) { if (isset($this->cache[$path])) {
// we already loaded them at some point // we already loaded them at some point
...@@ -322,7 +315,6 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back ...@@ -322,7 +315,6 @@ class CustomPropertiesBackend implements \Sabre\DAV\PropertyStorage\Backend\Back
array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
); );
$props = [];
$oldPath = null; $oldPath = null;
$props = []; $props = [];
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment