[Pkg-owncloud-commits] [php-sabre-vobject] 06/38: Support for detecting significant changes in iTip objects.

David Prévot taffit at moszumanska.debian.org
Tue Sep 23 03:10:21 UTC 2014


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

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

commit 282819ec1ae0a054f5da35212317472e9770606c
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Mon Sep 15 16:01:07 2014 +0100

    Support for detecting significant changes in iTip objects.
    
    Fixes #119
---
 ChangeLog.md                                 |   1 +
 lib/ITip/Broker.php                          |  56 ++++++++++-
 lib/ITip/Message.php                         |  18 +++-
 tests/VObject/ITip/BrokerUpdateEventTest.php | 136 +++++++++++++++++++++++++++
 4 files changed, 208 insertions(+), 3 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 35ea05c..2fbe843 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -6,6 +6,7 @@ ChangeLog
 
 * Changed: iTip broker now sets RSVP status to false when replies are received.
 * #118: iTip Message now has a `getScheduleStatus()` method.
+* #119: Support for detecting 'significant changes'.
 
 
 3.3.1 (2014-08-18)
diff --git a/lib/ITip/Broker.php b/lib/ITip/Broker.php
index d28b5b7..5b85460 100644
--- a/lib/ITip/Broker.php
+++ b/lib/ITip/Broker.php
@@ -55,6 +55,29 @@ class Broker {
     public $scheduleAgentServerRules = true;
 
     /**
+     * The broker will try during 'parseEvent' figure out whether the change
+     * was significant.
+     *
+     * It uses a few different ways to do this. One of these ways is seeing if
+     * certain properties changed values. This list of specified here.
+     *
+     * This list is taken from:
+     * * http://tools.ietf.org/html/rfc5546#section-2.1.4
+     *
+     * @var string[]
+     */
+    public $significantChangeProperties = [
+        'DTSTART',
+        'DTEND',
+        'DURATION',
+        'DUE',
+        'RRULE',
+        'RDATE',
+        'EXDATE',
+        'STATUS',
+    ];
+
+    /**
      * This method is used to process an incoming itip message.
      *
      * Examples:
@@ -155,6 +178,7 @@ class Broker {
             $oldEventInfo = $this->parseEventInfo($oldCalendar);
         } else {
             $oldEventInfo = array(
+                'significantChangeHash' => '',
                 'attendees' => array(),
             );
         }
@@ -197,7 +221,9 @@ class Broker {
                 // This is an attendee deleting the event.
                 foreach($eventInfo['attendees'] as $key=>$attendee) {
                     if (in_array($attendee['href'], $userHref)) {
-                        $eventInfo['attendees'][$key]['instances'] = array('master' => array('id'=>'master', 'partstat' => 'DECLINED'));
+                        $eventInfo['attendees'][$key]['instances'] = array('master' =>
+                            array('id'=>'master', 'partstat' => 'DECLINED')
+                        );
                     }
                 }
             }
@@ -481,6 +507,7 @@ class Broker {
                 ));
                 $org = $event->add('ORGANIZER', $eventInfo['organizer']);
                 if ($eventInfo['organizerName']) $org['CN'] = $eventInfo['organizerName'];
+                $message->significantChange = true;
 
             } else {
 
@@ -495,6 +522,18 @@ class Broker {
                     $icalMsg->add(clone $timezone);
                 }
 
+                // We need to find out that this change is significant. If it's
+                // not, systems may op to not send messages.
+                //
+                // We do this based on the 'significantChangeHash' which is
+                // some value that changes if there's a certain set of
+                // properties changed in the event, or simply if there's a
+                // difference in instances that the attendee is invited to.
+
+                $message->significantChange =
+                    array_keys($attendee['oldInstances']) != array_keys($attendee['newInstances']) ||
+                    $oldEventInfo['significantChangeHash']!==$eventInfo['significantChangeHash'];
+
                 foreach($attendee['newInstances'] as $instanceId => $instanceInfo) {
 
                     $currentEvent = clone $eventInfo['instances'][$instanceId];
@@ -670,6 +709,8 @@ class Broker {
         $sequence = null;
         $timezone = null;
 
+        $significantChangeHash = '';
+
         // Now we need to collect a list of attendees, and which instances they
         // are a part of.
         $attendees = array();
@@ -749,7 +790,17 @@ class Broker {
 
             }
 
+            foreach($this->significantChangeProperties as $prop) {
+                if (isset($vevent->$prop)) {
+                    $significantChangeHash.=$prop.':';
+                    foreach($vevent->select($prop) as $val) {
+                        $significantChangeHash.= $val->getValue().';';
+                    }
+                }
+            }
+
         }
+        $significantChangeHash = md5($significantChangeHash);
 
         return compact(
             'uid',
@@ -759,7 +810,8 @@ class Broker {
             'attendees',
             'sequence',
             'exdate',
-            'timezone'
+            'timezone',
+            'significantChangeHash'
         );
 
     }
diff --git a/lib/ITip/Message.php b/lib/ITip/Message.php
index 2a777b4..ff8b4a9 100644
--- a/lib/ITip/Message.php
+++ b/lib/ITip/Message.php
@@ -100,6 +100,22 @@ class Message {
     public $message;
 
     /**
+     * This will be set to true, if the iTip broker considers the change
+     * 'significant'.
+     *
+     * In practice, this means that we'll only mark it true, if for instance
+     * DTSTART changed. This allows systems to only send iTip messages when
+     * significant changes happened. This is especially useful for iMip, as
+     * normally a ton of messages may be generated for normal calendar use.
+     *
+     * To see the list of properties that are considered 'significant', check
+     * out Sabre\VObject\ITip\Broker::$significantChangeProperties.
+     *
+     * @var bool
+     */
+    public $significantChange = true;
+
+    /**
      * Returns the schedule status as an array:
      * [
      *     0 => '1.2',
@@ -115,7 +131,7 @@ class Message {
             return false;
 
         } else {
-            
+
             $scheduleStatus = explode(';', $this->scheduleStatus);
 
             if(!isset($scheduleStatus[1])) {
diff --git a/tests/VObject/ITip/BrokerUpdateEventTest.php b/tests/VObject/ITip/BrokerUpdateEventTest.php
index 18a3f75..332d1c9 100644
--- a/tests/VObject/ITip/BrokerUpdateEventTest.php
+++ b/tests/VObject/ITip/BrokerUpdateEventTest.php
@@ -48,6 +48,7 @@ ICS;
                 'senderName' => 'Strunk',
                 'recipient' => 'mailto:one at example.org',
                 'recipientName' => 'One',
+                'significantChange' => true,
                 'message' => <<<ICS
 BEGIN:VCALENDAR
 VERSION:2.0
@@ -72,6 +73,7 @@ ICS
                 'senderName' => 'Strunk',
                 'recipient' => 'mailto:two at example.org',
                 'recipientName' => 'Two',
+                'significantChange' => false,
                 'message' => <<<ICS
 BEGIN:VCALENDAR
 VERSION:2.0
@@ -99,6 +101,7 @@ ICS
                 'senderName' => 'Strunk',
                 'recipient' => 'mailto:three at example.org',
                 'recipientName' => 'Three',
+                'significantChange' => true,
                 'message' => <<<ICS
 BEGIN:VCALENDAR
 VERSION:2.0
@@ -286,6 +289,139 @@ ICS
 
     }
 
+    /**
+     * This test is identical to the first test, except this time we change the
+     * DURATION property.
+     *
+     * This should ensure that the message is significant for every attendee,
+     */
+    function testInviteChangeSignificantChange() {
+
+        $oldMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+DURATION:PT1H
+SEQUENCE:1
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=One:mailto:one at example.org
+ATTENDEE;CN=Two:mailto:two at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+
+        $newMessage = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:foobar
+DURATION:PT2H
+SEQUENCE:2
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Two:mailto:two at example.org
+ATTENDEE;CN=Three:mailto:three at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $version = \Sabre\VObject\Version::VERSION;
+
+        $expected = array(
+            array(
+                'uid' => 'foobar',
+                'method' => 'CANCEL',
+                'component' => 'VEVENT',
+                'sender' => 'mailto:strunk at example.org',
+                'senderName' => 'Strunk',
+                'recipient' => 'mailto:one at example.org',
+                'recipientName' => 'One',
+                'significantChange' => true,
+                'message' => <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject $version//EN
+CALSCALE:GREGORIAN
+METHOD:CANCEL
+BEGIN:VEVENT
+SEQUENCE:2
+UID:foobar
+ATTENDEE;CN=One:mailto:one at example.org
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+END:VEVENT
+END:VCALENDAR
+ICS
+
+            ),
+            array(
+                'uid' => 'foobar',
+                'method' => 'REQUEST',
+                'component' => 'VEVENT',
+                'sender' => 'mailto:strunk at example.org',
+                'senderName' => 'Strunk',
+                'recipient' => 'mailto:two at example.org',
+                'recipientName' => 'Two',
+                'significantChange' => true,
+                'message' => <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject $version//EN
+CALSCALE:GREGORIAN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:foobar
+DURATION:PT2H
+SEQUENCE:2
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Two:mailto:two at example.org
+ATTENDEE;CN=Three:mailto:three at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS
+
+            ),
+            array(
+                'uid' => 'foobar',
+                'method' => 'REQUEST',
+                'component' => 'VEVENT',
+                'sender' => 'mailto:strunk at example.org',
+                'senderName' => 'Strunk',
+                'recipient' => 'mailto:three at example.org',
+                'recipientName' => 'Three',
+                'significantChange' => true,
+                'message' => <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject $version//EN
+CALSCALE:GREGORIAN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:foobar
+DURATION:PT2H
+SEQUENCE:2
+ORGANIZER;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Strunk:mailto:strunk at example.org
+ATTENDEE;CN=Two:mailto:two at example.org
+ATTENDEE;CN=Three:mailto:three at example.org
+DTSTART:20140716T120000Z
+END:VEVENT
+END:VCALENDAR
+ICS
+
+            ),
+        );
+
+        $result = $this->parse($oldMessage, $newMessage, $expected);
+
+    }
+
     function parse($oldMessage, $newMessage, $expected = array()) {
 
         $broker = new Broker();

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