[Pkg-owncloud-commits] [php-sabredav] 53/75: Deleting properties when parent nodes get deleted.

David Prévot taffit at moszumanska.debian.org
Thu Feb 26 18:51:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit ff814c39f694ee1688726fdc9f70fa026530c772
Author: Evert Pot <me at evertpot.com>
Date:   Mon Feb 23 14:35:28 2015 -0500

    Deleting properties when parent nodes get deleted.
    
    Fixes #612.
---
 ChangeLog.md                                       |  3 +++
 .../PropertyStorage/Backend/BackendInterface.php   | 16 +++++++++++
 lib/DAV/PropertyStorage/Backend/PDO.php            | 31 ++++++++++++++++++++--
 lib/DAV/PropertyStorage/Plugin.php                 | 15 +++++++++++
 .../PropertyStorage/Backend/AbstractPDOTest.php    | 17 ++++++++++++
 5 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 522f9d3..74da72d 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -11,6 +11,9 @@ ChangeLog
 * #610: Don't allow discovery of arbitrary files using `..` in the browser
   plugin (@LukasReschke).
 * Browser plugin now shows quota properties.
+* #612: PropertStorage didn't delete properties from nodes when a node's
+  parents get deleted.
+
 
 2.1.2 (2014-12-10)
 ------------------
diff --git a/lib/DAV/PropertyStorage/Backend/BackendInterface.php b/lib/DAV/PropertyStorage/Backend/BackendInterface.php
index 746378b..5eee5c9 100644
--- a/lib/DAV/PropertyStorage/Backend/BackendInterface.php
+++ b/lib/DAV/PropertyStorage/Backend/BackendInterface.php
@@ -5,6 +5,16 @@ namespace Sabre\DAV\PropertyStorage\Backend;
 use Sabre\DAV\PropFind;
 use Sabre\DAV\PropPatch;
 
+/**
+ * Propertystorage backend interface.
+ *
+ * Propertystorage backends must implement this interface to be used by the
+ * propertystorage plugin.
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
 interface BackendInterface {
 
     /**
@@ -42,6 +52,12 @@ interface BackendInterface {
      * This method is called after a node is deleted.
      *
      * This allows a backend to clean up all associated properties.
+     *
+     * The delete method will get called once for the deletion of an entire
+     * tree.
+     *
+     * @param string $path
+     * @return void
      */
     function delete($path);
 
diff --git a/lib/DAV/PropertyStorage/Backend/PDO.php b/lib/DAV/PropertyStorage/Backend/PDO.php
index f518e92..4d69255 100644
--- a/lib/DAV/PropertyStorage/Backend/PDO.php
+++ b/lib/DAV/PropertyStorage/Backend/PDO.php
@@ -5,6 +5,18 @@ namespace Sabre\DAV\PropertyStorage\Backend;
 use Sabre\DAV\PropFind;
 use Sabre\DAV\PropPatch;
 
+/**
+ * PropertyStorage PDO backend.
+ *
+ * This backend class uses a PDO-enabled database to store webdav properties.
+ * Both sqlite and mysql have been tested.
+ *
+ * The database structure can be found in the examples/sql/ directory.
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
 class PDO implements BackendInterface {
 
     /**
@@ -96,11 +108,26 @@ class PDO implements BackendInterface {
      * This method is called after a node is deleted.
      *
      * This allows a backend to clean up all associated properties.
+     *
+     * The delete method will get called once for the deletion of an entire
+     * tree.
+     *
+     * @param string $path
+     * @return void
      */
     function delete($path) {
 
-        $stmt = $this->pdo->prepare("DELETE FROM propertystorage WHERE path = ?");
-        $stmt->execute([$path]);
+        $stmt = $this->pdo->prepare("DELETE FROM propertystorage WHERE path = ? OR path LIKE ? ESCAPE '='");
+        $childPath = strtr(
+            $path,
+            [
+                '=' => '==',
+                '%' => '=%',
+                '_' => '=_'
+            ]
+        ) . '/%';
+
+        $stmt->execute([$path, $childPath]);
 
     }
 
diff --git a/lib/DAV/PropertyStorage/Plugin.php b/lib/DAV/PropertyStorage/Plugin.php
index 14f60bf..d785020 100644
--- a/lib/DAV/PropertyStorage/Plugin.php
+++ b/lib/DAV/PropertyStorage/Plugin.php
@@ -8,6 +8,21 @@ use Sabre\DAV\PropPatch;
 use Sabre\DAV\PropFind;
 use Sabre\DAV\INode;
 
+/**
+ * PropertyStorage Plugin.
+ *
+ * Adding this plugin to your server allows clients to store any arbitrary
+ * WebDAV property.
+ *
+ * See:
+ *   http://sabre.io/dav/property-storage/
+ *
+ * for more information.
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
 class Plugin extends ServerPlugin {
 
     /**
diff --git a/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php b/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
index 31f56f2..bb1f729 100644
--- a/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/DAV/PropertyStorage/Backend/AbstractPDOTest.php
@@ -127,4 +127,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals('child', $propFind->get('{DAV:}displayname'));
     }
 
+    /**
+     * @depends testPropFind
+     */
+    function testDeepDelete() {
+
+        $backend = $this->getBackend();
+        $propPatch = new PropPatch(['{DAV:}displayname' => 'child']);
+        $backend->propPatch('dir/child', $propPatch);
+        $propPatch->commit();
+        $backend->delete('dir');
+
+        $propFind = new PropFind('dir/child', ['{DAV:}displayname']);
+        $backend->propFind('dir/child', $propFind);
+
+        $this->assertEquals(null, $propFind->get('{DAV:}displayname'));
+
+    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list