4 commits - plugins/calendar plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Thu Oct 18 21:54:29 CEST 2012


 plugins/calendar/calendar.php              |   17 ++++++++---------
 plugins/libkolab/lib/kolab_format_xcal.php |   10 +++++-----
 2 files changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 219a7a41a79c52be7f51478290099861fb9ec317
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Oct 18 21:54:14 2012 +0200

    Compare sequence numbers for iTip updates

diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index a526570..d82971b 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -735,9 +735,9 @@ class calendar extends rcube_plugin
         }
         else if (in_array($status, array('ACCEPTED','TENTATIVE','DECLINED'))) {
           $html = html::div('rsvp-status ' . strtolower($status), $this->gettext('youhave'.strtolower($status)));
-          if ($existing['changed'] && $event['changed'] < $existing['changed']) {
-            $action = '';
-          }
+          if ($existing['sequence'] > $event['sequence'] || (!$event['sequence'] && $existing['changed'] && $existing['changed'] > $event['changed'])) {
+            $action = '';  // nothing to do here
+         }
         }
         
         $default_calendar = $calendar_select ? $this->get_default_calendar(true) : null;
@@ -1670,7 +1670,7 @@ class calendar extends rcube_plugin
         }
         else if ($this->ical->method == 'REQUEST') {
           $emails = $this->get_user_emails();
-          $title = $event['SEQUENCE'] > 0 ? $this->gettext('itipupdate') : $this->gettext('itipinvitation');
+          $title = $event['sequence'] > 0 ? $this->gettext('itipupdate') : $this->gettext('itipinvitation');
           
           // add (hidden) buttons and activate them from asyncronous request
           foreach (array('accepted','tentative','declined') as $method) {
@@ -1702,7 +1702,7 @@ class calendar extends rcube_plugin
           $buttons .= html::div(array('id' => 'import-'.$dom_id, 'style' => 'display:none'), $import_button);
           $buttons_pre = html::div(array('id' => 'loading-'.$dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading'));
           
-          $this->rc->output->add_script('rcube_calendar.fetch_event_rsvp_status(' . json_serialize(array('uid' => $event['uid'], 'changed' => $event['changed'], 'fallback' => $status)) . ')', 'docready');
+          $this->rc->output->add_script('rcube_calendar.fetch_event_rsvp_status(' . json_serialize(array('uid' => $event['uid'], 'changed' => $event['changed'], 'sequence' => intval($event['sequence']), 'fallback' => $status)) . ')', 'docready');
         }
         else if ($this->ical->method == 'CANCEL') {
           $title = $this->gettext('itipcancellation');
@@ -1726,7 +1726,7 @@ class calendar extends rcube_plugin
           $buttons .= html::div(array('id' => 'import-'.$dom_id, 'style' => 'display:none'), $button_import);
           $buttons_pre = html::div(array('id' => 'loading-'.$dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading'));
           
-          $this->rc->output->add_script('rcube_calendar.fetch_event_rsvp_status(' . json_serialize(array('uid' => $event['uid'], 'changed' => $event['changed'], 'fallback' => 'CANCELLED')) . ')', 'docready');
+          $this->rc->output->add_script('rcube_calendar.fetch_event_rsvp_status(' . json_serialize(array('uid' => $event['uid'], 'changed' => $event['changed'], 'sequence' => intval($event['sequence']), 'fallback' => 'CANCELLED')) . ')', 'docready');
         }
         else {
           $buttons = html::tag('input', array(
@@ -1808,7 +1808,6 @@ class calendar extends rcube_plugin
       
       // save to calendar
       if ($calendar && !$calendar['readonly']) {
-        $event['id'] = $event['uid'];
         $event['calendar'] = $calendar['id'];
         
         // check for existing event with the same UID
@@ -1851,8 +1850,8 @@ class calendar extends rcube_plugin
             }
           }
           // import the (newer) event
-          // TODO: compare SEQUENCE numbers instead of changed dates
-          else if ($event['changed'] >= $existing['changed']) {
+          else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
+            $event['id'] = $existing['id'];
             $success = $this->driver->edit_event($event);
           }
           else if (!empty($status)) {


commit 29b4c075e71c363a7e93a06cead6ab87f2e28734
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Oct 18 21:51:55 2012 +0200

    Treat as new even if uid property is given

diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index 57f0892..3e1a721 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -214,6 +214,8 @@ abstract class kolab_format_xcal extends kolab_format
      */
     public function set(&$object)
     {
+        $is_new = !$this->obj->uid();
+
         // set some automatic values if missing
         if (!$this->obj->created()) {
             if (!empty($object['created']))
@@ -228,7 +230,7 @@ abstract class kolab_format_xcal extends kolab_format
         $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
 
         // increment sequence on updates
-        $object['sequence'] = $object['uid'] ? $this->obj->sequence()+1 : 0;
+        $object['sequence'] = !$is_new ? $this->obj->sequence()+1 : 0;
         $this->obj->setSequence($object['sequence']);
 
         $this->obj->setSummary($object['title']);


commit d783b487f60587845806beb8422654b07c3347e8
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Oct 18 21:28:08 2012 +0200

    Fix sequence fix. Man is it already that late?

diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index 7cef840..57f0892 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -223,14 +223,12 @@ abstract class kolab_format_xcal extends kolab_format
 
         if (!empty($object['uid']))
             $this->obj->setUid($object['uid']);
-        else
-            $object['sequence'] = -1;  // make the first sequence increment being 0
 
         $object['changed'] = new DateTime('now', self::$timezone);
         $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
 
-        // increment sequence
-        $object['sequence'] = $this->obj->sequence()+1;
+        // increment sequence on updates
+        $object['sequence'] = $object['uid'] ? $this->obj->sequence()+1 : 0;
         $this->obj->setSequence($object['sequence']);
 
         $this->obj->setSummary($object['title']);


commit 433a5420a2161686d62cd1cc29a860ee08587678
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Oct 18 21:25:39 2012 +0200

    Fix sequence increment

diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index c5fdd8e..7cef840 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -221,10 +221,10 @@ abstract class kolab_format_xcal extends kolab_format
             $this->obj->setCreated(self::get_datetime($object['created']));
         }
 
-        if (!empty($object['uid'])) {
+        if (!empty($object['uid']))
             $this->obj->setUid($object['uid']);
-            $object['sequence'] = -1;
-        }
+        else
+            $object['sequence'] = -1;  // make the first sequence increment being 0
 
         $object['changed'] = new DateTime('now', self::$timezone);
         $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));





More information about the commits mailing list