[Pkg-owncloud-commits] [php-sabre-vobject] 08/29: Automatically insert UID in VCard, VJournal and VTodo.

David Prévot taffit at moszumanska.debian.org
Sat Dec 12 19:26:58 UTC 2015


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

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

commit 10208809ba87b8fa68392f1ce008e73a16d0f617
Author: Evert Pot <me at evertpot.com>
Date:   Wed Dec 2 16:27:53 2015 -0500

    Automatically insert UID in VCard, VJournal and VTodo.
    
    Fixes #275
---
 lib/Component/VCard.php         |  1 +
 lib/Component/VJournal.php      | 14 ++++++++++++++
 lib/Component/VTodo.php         | 14 ++++++++++++++
 lib/VCardConverter.php          |  3 +++
 tests/VObject/ComponentTest.php |  3 ++-
 tests/VObject/Issue40Test.php   |  2 ++
 6 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/lib/Component/VCard.php b/lib/Component/VCard.php
index 5905e47..3330a6a 100644
--- a/lib/Component/VCard.php
+++ b/lib/Component/VCard.php
@@ -419,6 +419,7 @@ class VCard extends VObject\Document {
         return [
             'VERSION' => '3.0',
             'PRODID'  => '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN',
+            'UID'     => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
         ];
 
     }
diff --git a/lib/Component/VJournal.php b/lib/Component/VJournal.php
index abea2a7..48efaef 100644
--- a/lib/Component/VJournal.php
+++ b/lib/Component/VJournal.php
@@ -90,4 +90,18 @@ class VJournal extends VObject\Component {
         ];
 
     }
+
+    /**
+     * This method should return a list of default property values.
+     *
+     * @return array
+     */
+    protected function getDefaults() {
+
+        return [
+            'UID'     => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
+            'DTSTAMP' => date('Ymd\\THis\\Z'),
+        ];
+
+    }
 }
diff --git a/lib/Component/VTodo.php b/lib/Component/VTodo.php
index 9a44caf..6721c29 100644
--- a/lib/Component/VTodo.php
+++ b/lib/Component/VTodo.php
@@ -176,4 +176,18 @@ class VTodo extends VObject\Component {
 
     }
 
+    /**
+     * This method should return a list of default property values.
+     *
+     * @return array
+     */
+    protected function getDefaults() {
+
+        return [
+            'UID'     => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
+            'DTSTAMP' => date('Ymd\\THis\\Z'),
+        ];
+
+    }
+
 }
diff --git a/lib/VCardConverter.php b/lib/VCardConverter.php
index 37b6c03..6a54ba6 100644
--- a/lib/VCardConverter.php
+++ b/lib/VCardConverter.php
@@ -49,6 +49,9 @@ class VCardConverter {
             'VERSION' => $newVersion,
         ]);
 
+        // We might have generated a default UID. Remove it!
+        unset($output->UID);
+
         foreach ($input->children() as $property) {
 
             $this->convertProperty($input, $output, $property, $targetVersion);
diff --git a/tests/VObject/ComponentTest.php b/tests/VObject/ComponentTest.php
index b37624e..9323a43 100644
--- a/tests/VObject/ComponentTest.php
+++ b/tests/VObject/ComponentTest.php
@@ -346,7 +346,8 @@ class ComponentTest extends \PHPUnit_Framework_TestCase {
         $comp = new VCalendar([], false);
         $event = $comp->add($comp->createComponent('VEVENT'));
         unset($event->DTSTAMP, $event->UID);
-        $comp->add($comp->createComponent('VTODO'));
+        $todo = $comp->add($comp->createComponent('VTODO'));
+        unset($todo->DTSTAMP, $todo->UID);
 
         $str = $comp->serialize();
 
diff --git a/tests/VObject/Issue40Test.php b/tests/VObject/Issue40Test.php
index c5f61b0..b9a9d0e 100644
--- a/tests/VObject/Issue40Test.php
+++ b/tests/VObject/Issue40Test.php
@@ -14,6 +14,8 @@ class Issue40Test extends \PHPUnit_Framework_TestCase {
         $card = new Component\VCard();
         $card->add('N', ['van der Harten', ['Rene', 'J.'], "", 'Sir', 'R.D.O.N.'], ['SORT-AS' => ['Harten', 'Rene']]);
 
+        unset($card->UID);
+
         $expected = implode("\r\n", [
             "BEGIN:VCARD",
             "VERSION:3.0",

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



More information about the Pkg-owncloud-commits mailing list