[Pkg-owncloud-commits] [php-sabredav] 117/148: Removed me-card workaround.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:27 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 75a79dd6070cec2237f05d3538221db12581ca3c
Author: Evert Pot <me at evertpot.com>
Date:   Thu Apr 2 16:55:46 2015 -0400

    Removed me-card workaround.
    
    The property storage plugin can now handle complex values, so it's no
    longer needed to have special support for the me-card.
    
    This patch removes all me-card functionality and adds some stuff to the
    migrate script to move it over with ease.
---
 bin/migrateto22.php                | 61 +++++++++++++++++++++++++++++++++++---
 examples/sql/mysql.principals.sql  |  1 -
 examples/sql/pgsql.principals.sql  |  3 +-
 examples/sql/sqlite.principals.sql |  1 -
 lib/CardDAV/Plugin.php             | 58 +-----------------------------------
 tests/Sabre/CardDAV/PluginTest.php | 49 ------------------------------
 6 files changed, 59 insertions(+), 114 deletions(-)

diff --git a/bin/migrateto22.php b/bin/migrateto22.php
index 0aa2572..068b0e2 100755
--- a/bin/migrateto22.php
+++ b/bin/migrateto22.php
@@ -10,8 +10,10 @@ if ($argc<2) {
 This script help you migrate from a pre-2.2 database to 2.2 and later
 
 Changes:
-  * Values in the propertystorage table are now serialized using PHP's
-    serialize()
+  * The propertystorage table has changed to allow storage of complex
+    properties.
+  * the vcardurl field in the principals table is no more. This was moved to
+    the propertystorage table.
 
 Keep in mind that ALTER TABLE commands will be executed. If you have a large
 dataset this may mean that this process takes a while.
@@ -83,8 +85,40 @@ try {
     $row = $result->fetch(\PDO::FETCH_ASSOC);
 
     if (!$row) {
-        echo "No data in table. Going to try to add the uid field anyway.\n";
-        $addValueType = true;
+        echo "No data in table. Going to re-create the table.\n";
+        $random = mt_rand(1000,9999);
+        echo "Renaming propertystorage -> propertystorage_old$random and creating new table.\n";
+
+        switch($driver) {
+
+            case 'mysql' :
+                $pdo->exec('RENAME TABLE propertystorage TO propertystorage_old' . $random);
+                $pdo->exec('
+    CREATE TABLE propertystorage (
+        id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+        path VARBINARY(1024) NOT NULL,
+        name VARBINARY(100) NOT NULL,
+        valuetype INT UNSIGNED,
+        value MEDIUMBLOB
+    );
+                ');
+                $pdo->exec('CREATE UNIQUE INDEX path_property_' . $random . '  ON propertystorage (path(600), name(100));');
+                break;
+            case 'sqlite' :
+                $pdo->exec('ALTER TABLE propertystorage RENAME TO propertystorage_old' . $random);
+                $pdo->exec('
+CREATE TABLE propertystorage (
+    id integer primary key asc,
+    path text,
+    name text,
+    valuetype integer,
+    value blob
+);');
+
+                $pdo->exec('CREATE UNIQUE INDEX path_property_' . $random . ' ON propertystorage (path, name);');
+                break;
+
+        }
     } elseif (array_key_exists('valuetype', $row)) {
         echo "valuetype field exists. Assuming that this part of the migration has\n";
         echo "Already been completed.\n";
@@ -96,6 +130,7 @@ try {
 } catch (Exception $e) {
     echo "Could not find a propertystorage table. Skipping this part of the\n";
     echo "upgrade.\n";
+    echo $e->getMessage(), "\n";
 }
 
 if ($addValueType) {
@@ -114,5 +149,23 @@ if ($addValueType) {
 
 }
 
+echo "Migrating vcardurl\n";
+
+$result = $pdo->query('SELECT id, uri, vcardurl FROM principals WHERE vcardurl IS NOT NULL');
+$stmt1 = $pdo->prepare('INSERT INTO propertystorage (path, name, valuetype, value) VALUES (?, ?, 3, ?)');
+
+while($row = $result->fetch(\PDO::FETCH_ASSOC)) {
+
+    // Inserting the new record
+    $stmt1->execute([
+        'addressbooks/' . basename($row['uri']),
+        '{http://calendarserver.org/ns/}me-card',
+        serialize(new Sabre\DAV\Xml\Property\Href($row['vcardurl']))
+    ]);
+
+    echo serialize(new Sabre\DAV\Xml\Property\Href($row['vcardurl']));
+
+}
+
 echo "Done.\n";
 echo "Upgrade to 2.2 schema completed.\n";
diff --git a/examples/sql/mysql.principals.sql b/examples/sql/mysql.principals.sql
index da92828..423a5d1 100644
--- a/examples/sql/mysql.principals.sql
+++ b/examples/sql/mysql.principals.sql
@@ -3,7 +3,6 @@ CREATE TABLE principals (
     uri VARCHAR(200) NOT NULL,
     email VARCHAR(80),
     displayname VARCHAR(80),
-    vcardurl VARCHAR(255),
     UNIQUE(uri)
 );
 
diff --git a/examples/sql/pgsql.principals.sql b/examples/sql/pgsql.principals.sql
index 69ef795..9157acd 100644
--- a/examples/sql/pgsql.principals.sql
+++ b/examples/sql/pgsql.principals.sql
@@ -2,8 +2,7 @@ CREATE TABLE principals (
     id SERIAL NOT NULL,
     uri VARCHAR(200) NOT NULL,
     email VARCHAR(80),
-    displayname VARCHAR(80),
-    vcardurl VARCHAR(255)
+    displayname VARCHAR(80)
 );
 
 ALTER TABLE ONLY principals
diff --git a/examples/sql/sqlite.principals.sql b/examples/sql/sqlite.principals.sql
index 09dbc4d..247252f 100644
--- a/examples/sql/sqlite.principals.sql
+++ b/examples/sql/sqlite.principals.sql
@@ -3,7 +3,6 @@ CREATE TABLE principals (
     uri TEXT,
     email TEXT,
     displayname TEXT,
-    vcardurl TEXT,
     UNIQUE(uri)
 );
 
diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php
index a0b8217..a636475 100644
--- a/lib/CardDAV/Plugin.php
+++ b/lib/CardDAV/Plugin.php
@@ -68,7 +68,6 @@ class Plugin extends DAV\ServerPlugin {
         /* Events */
         $server->on('propFind',            [$this, 'propFindEarly']);
         $server->on('propFind',            [$this, 'propFindLate'],150);
-        $server->on('propPatch',           [$this, 'propPatch']);
         $server->on('report',              [$this, 'report']);
         $server->on('onHTMLActionsPanel',  [$this, 'htmlActionsPanel']);
         $server->on('onBrowserPostAction', [$this, 'browserPostAction']);
@@ -89,7 +88,7 @@ class Plugin extends DAV\ServerPlugin {
         $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}addressbook-home-set';
         $server->protectedProperties[] = '{' . self::NS_CARDDAV . '}supported-collation-set';
 
-        $server->propertyMap['{http://calendarserver.org/ns/}me-card'] = 'Sabre\\DAV\\Xml\\Property\\Href';
+        $server->xml->elementMap['{http://calendarserver.org/ns/}me-card'] = 'Sabre\\DAV\\Xml\\Property\\Href';
 
         $this->server = $server;
 
@@ -184,61 +183,6 @@ class Plugin extends DAV\ServerPlugin {
 
         }
 
-        if ($node instanceof UserAddressBooks) {
-
-            $propFind->handle('{http://calendarserver.org/ns/}me-card', function() use ($node) {
-
-                $props = $this->server->getProperties($node->getOwner(), ['{http://sabredav.org/ns}vcard-url']);
-                if (isset($props['{http://sabredav.org/ns}vcard-url'])) {
-
-                    return new Href(
-                        $props['{http://sabredav.org/ns}vcard-url']
-                    );
-
-                }
-
-            });
-
-        }
-
-    }
-
-    /**
-     * This event is triggered when a PROPPATCH method is executed
-     *
-     * @param string $path
-     * @param DAV\PropPatch $propPatch
-     * @return bool
-     */
-    function propPatch($path, DAV\PropPatch $propPatch) {
-
-        $node = $this->server->tree->getNodeForPath($path);
-        if (!$node instanceof UserAddressBooks) {
-            return true;
-        }
-
-        $meCard = '{http://calendarserver.org/ns/}me-card';
-
-        $propPatch->handle($meCard, function($value) use ($node) {
-
-            if ($value instanceof Href) {
-                $value = $value->getHref();
-                $value = $this->server->calculateUri($value);
-            } elseif (!is_null($value)) {
-                return 400;
-            }
-
-            $innerResult = $this->server->updateProperties(
-                $node->getOwner(),
-                [
-                    '{http://sabredav.org/ns}vcard-url' => $value,
-                ]
-            );
-
-            return $innerResult['{http://sabredav.org/ns}vcard-url'];
-
-        });
-
     }
 
     /**
diff --git a/tests/Sabre/CardDAV/PluginTest.php b/tests/Sabre/CardDAV/PluginTest.php
index 3f95e66..a053e48 100644
--- a/tests/Sabre/CardDAV/PluginTest.php
+++ b/tests/Sabre/CardDAV/PluginTest.php
@@ -42,25 +42,6 @@ class PluginTest extends AbstractPluginTest {
 
     }
 
-    function testMeCardTest() {
-
-        $result = $this->server->getProperties(
-            'addressbooks/user1',
-            array(
-                '{http://calendarserver.org/ns/}me-card',
-            )
-        );
-
-        $this->assertEquals(
-            array(
-                '{http://calendarserver.org/ns/}me-card' =>
-                    new Href('addressbooks/user1/book1/vcard1.vcf')
-            ),
-            $result
-        );
-
-    }
-
     function testDirectoryGateway() {
 
         $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}directory-gateway'));
@@ -110,36 +91,6 @@ class PluginTest extends AbstractPluginTest {
 
     }
 
-    function testUpdatePropertiesMeCard() {
-
-        $result = $this->server->updateProperties('addressbooks/user1', [
-            '{http://calendarserver.org/ns/}me-card' => new Href('/addressbooks/user1/book1/vcard2',true),
-        ]);
-
-        $this->assertEquals(
-            [
-                '{http://calendarserver.org/ns/}me-card' => 200,
-            ],
-            $result
-        );
-
-    }
-
-    function testUpdatePropertiesMeCardBadValue() {
-
-        $result = $this->server->updateProperties('addressbooks/user1', [
-            '{http://calendarserver.org/ns/}me-card' => [],
-        ]);
-
-        $this->assertEquals(
-            [
-                '{http://calendarserver.org/ns/}me-card' => 400,
-            ],
-            $result
-        );
-
-    }
-
     function testAddressbookPluginProperties() {
 
         $ns = '{' . Plugin::NS_CARDDAV . '}';

-- 
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