plugins/calendar

Thomas Brüderli bruederli at kolabsys.com
Wed Jan 9 11:49:25 CET 2013


 plugins/calendar/drivers/database/database_driver.php |    4 +-
 plugins/calendar/drivers/kolab/kolab_calendar.php     |   25 +++++++++++++++---
 plugins/calendar/drivers/kolab/kolab_driver.php       |   12 ++------
 3 files changed, 27 insertions(+), 14 deletions(-)

New commits:
commit 8d3f1803cc75dae08900e9c752c873514641ffb5
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Jan 9 11:49:12 2013 +0100

    Fix modification of recurring events (#1499)

diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index d6a4483..5a518f7 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -363,11 +363,11 @@ class database_driver extends calendar_driver
             
             // use start date from master but try to be smart on time or duration changes
             $old_start_date = $old['start']->format('Y-m-d');
-            $old_start_time = $old['start']->format('H:i');
+            $old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
             $old_duration = $old['end']->format('U') - $old['start']->format('U');
             
             $new_start_date = $event['start']->format('Y-m-d');
-            $new_start_time = $event['start']->format('H:i');
+            $new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
             $new_duration = $event['end']->format('U') - $event['start']->format('U');
             
             $diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index 5200cff..f2c106e 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -181,9 +181,7 @@ class kolab_calendar
         $this->events[$master_id] = $this->_to_rcube_event($record);
 
       if (($master = $this->events[$master_id]) && $master['recurrence']) {
-        $limit = clone $master['start'];
-        $limit->add(new DateInterval('P10Y'));
-        $this->_get_recurring_events($record, $master['start'], $limit, $id);
+        $this->_get_recurring_events($record, $master['start'], null, $id);
       }
     }
 
@@ -386,8 +384,14 @@ class kolab_calendar
 
   /**
    * Create instances of a recurring event
+   *
+   * @param array  Hash array with event properties
+   * @param object DateTime Start date of the recurrence window
+   * @param object DateTime End date of the recurrence window
+   * @param string ID of a specific recurring event instance
+   * @return array List of recurring event instances
    */
-  public function _get_recurring_events($event, $start, $end, $event_id = null)
+  public function _get_recurring_events($event, $start, $end = null, $event_id = null)
   {
     $object = $event['_formatobj'];
     if (!$object) {
@@ -397,6 +401,19 @@ class kolab_calendar
     if (!is_object($object))
       return array();
 
+    // determine a reasonable end date if none given
+    if (!$end) {
+      switch ($event['recurrence']['FREQ']) {
+        case 'YEARLY':  $intvl = 'P100Y'; break;
+        case 'MONTHLY': $intvl = 'P20Y';  break;
+        default:        $intvl = 'P10Y';  break;
+      }
+
+      $end = clone $event['start'];
+      $end->add(new DateInterval($intvl));
+    }
+
+    // use libkolab to compute recurring events
     $recurrence = new kolab_date_recurrence($object);
 
     $i = 0;
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index fe6f3ad..5854840 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -427,9 +427,7 @@ class kolab_driver extends calendar_driver
 
           // removing the first instance => just move to next occurence
           if ($master['id'] == $event['id']) {
-            $limit = clone $event['end'];
-            $limit->add(new DateInterval('P370D'));
-            $recurring = reset($storage->_get_recurring_events($event, $event['start'], $limit, $event['id'].'-1'));
+            $recurring = reset($storage->_get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
             $master['start'] = $recurring['start'];
             $master['end'] = $recurring['end'];
             if ($master['recurrence']['COUNT'])
@@ -586,9 +584,7 @@ class kolab_driver extends calendar_driver
       case 'current':
         // modifying the first instance => just move to next occurence
         if ($master['id'] == $event['id']) {
-          $limit = clone $old['end'];
-          $limit->add(new DateInterval('P370D'));
-          $recurring = reset($storage->_get_recurring_events($event, $event['start'], $limit, $event['id'].'-1'));
+          $recurring = reset($storage->_get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
           $master['start'] = $recurring['start'];
           $master['end'] = $recurring['end'];
           if ($master['recurrence']['COUNT'])
@@ -641,11 +637,11 @@ class kolab_driver extends calendar_driver
 
         // use start date from master but try to be smart on time or duration changes
         $old_start_date = $old['start']->format('Y-m-d');
-        $old_start_time = $old['start']->format('H:i');
+        $old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
         $old_duration = $old['end']->format('U') - $old['start']->format('U');
         
         $new_start_date = $event['start']->format('Y-m-d');
-        $new_start_time = $event['start']->format('H:i');
+        $new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
         $new_duration = $event['end']->format('U') - $event['start']->format('U');
         
         $diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;





More information about the commits mailing list