summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2013-06-24 11:00:42 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2013-06-24 11:00:42 (GMT)
commit8ea287e37f46f7ebd51c7dafdf6ad8693a0fd801 (patch)
tree68e7f517a2e58d66cc973ba5f53dca51a77c2dda
parent8fb3a422f5e4af08490856b6632a1771762d1907 (diff)
downloadroundcubemail-plugins-kolab-8ea287e37f46f7ebd51c7dafdf6ad8693a0fd801.tar.gz
Revert "Make this-and-future recurrence exceptions work"
This reverts commit a616fa629fd0fda66675571c580723d23fc60610. Conflicts: plugins/libkolab/lib/kolab_format_event.php
-rw-r--r--plugins/calendar/calendar_ui.js3
-rw-r--r--plugins/calendar/drivers/kolab/kolab_calendar.php76
-rw-r--r--plugins/calendar/drivers/kolab/kolab_driver.php53
-rw-r--r--plugins/libkolab/lib/kolab_format_event.php32
4 files changed, 74 insertions, 90 deletions
diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js
index ddccd6d..d5a86a7 100644
--- a/plugins/calendar/calendar_ui.js
+++ b/plugins/calendar/calendar_ui.js
@@ -524,9 +524,8 @@ function rcube_calendar_ui(settings)
// show warning if editing a recurring event
if (event.id && event.recurrence) {
- var sel = event.thisandfuture ? 'future' : 'all';
$('#edit-recurring-warning').show();
- $('input.edit-recurring-savemode[value="'+sel+'"]').prop('checked', true);
+ $('input.edit-recurring-savemode[value="all"]').prop('checked', true);
}
else
$('#edit-recurring-warning').hide();
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index e5af7b0..da78a81 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -422,33 +422,23 @@ class kolab_calendar
$i = 0;
$events = array();
$exdates = array();
- $futuredata = array();
if (is_array($event['recurrence']['EXCEPTIONS'])) {
- // copy the recurrence rule from the master event (to be used in the UI)
- $recurrence_rule = $event['recurrence'];
- unset($recurrence_rule['EXCEPTIONS'], $recurrence_rule['EXDATE']);
-
- foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
- $rec_event = $this->_to_rcube_event($exception);
- $rec_event['id'] = $event['uid'] . '-' . ++$i;
- $rec_event['recurrence_id'] = $event['uid'];
- $rec_event['recurrence'] = $recurrence_rule;
- $rec_event['_instance'] = $i;
- $events[] = $rec_event;
-
- // found the specifically requested instance, exiting...
- if ($rec_event['id'] == $event_id) {
- $this->events[$rec_event['id']] = $rec_event;
- return $events;
- }
+ foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
+ $rec_event = $this->_to_rcube_event($exception);
+ $rec_event['id'] = $event['uid'] . '-' . ++$i;
+ $rec_event['recurrence_id'] = $event['uid'];
+ $rec_event['_instance'] = $i;
+ $events[] = $rec_event;
+
+ // found the specifically requested instance, exiting...
+ if ($rec_event['id'] == $event_id) {
+ $this->events[$rec_event['id']] = $rec_event;
+ return $events;
+ }
- // remember this exception's date
- $exdate = $rec_event['start']->format('Y-m-d');
- $exdates[$exdate] = $rec_event['id'];
- if ($rec_event['thisandfuture']) {
- $futuredata[$exdate] = $rec_event;
+ // remember this exception's date
+ $exdates[$rec_event['start']->format('Y-m-d')] = $rec_event['id'];
}
- }
}
// use libkolab to compute recurring events
@@ -456,29 +446,20 @@ class kolab_calendar
$recurrence = new kolab_date_recurrence($object);
}
else {
- // fallback to local recurrence implementation
- require_once($this->cal->home . '/lib/calendar_recurrence.php');
- $recurrence = new calendar_recurrence($this->cal, $event);
+ // fallback to local recurrence implementation
+ require_once($this->cal->home . '/lib/calendar_recurrence.php');
+ $recurrence = new calendar_recurrence($this->cal, $event);
}
while ($next_event = $recurrence->next_instance()) {
// skip if there's an exception at this date
- $datestr = $next_event['start']->format('Y-m-d');
- if ($exdates[$datestr]) {
- // use this event data for future recurring instances
- if ($futuredata[$datestr])
- $overlay_data = $futuredata[$datestr];
+ if ($exdates[$next_event['start']->format('Y-m-d')])
continue;
- }
// add to output if in range
$rec_id = $event['uid'] . '-' . ++$i;
if (($next_event['start'] <= $end && $next_event['end'] >= $start) || ($event_id && $rec_id == $event_id)) {
$rec_event = $this->_to_rcube_event($next_event);
-
- if ($overlay_data) // copy data from a 'this-and-future' exception
- $this->_merge_event_data($rec_event, $overlay_data);
-
$rec_event['id'] = $rec_id;
$rec_event['recurrence_id'] = $event['uid'];
$rec_event['_instance'] = $i;
@@ -502,27 +483,6 @@ class kolab_calendar
}
/**
- * Merge certain properties from the overlay event to the base event object
- *
- * @param array The event object to be altered
- * @param array The overlay event object to be merged over $event
- */
- private function _merge_event_data(&$event, $overlay)
- {
- static $forbidden = array('id','uid','created','changed','recurrence','organizer','attendees','sequence');
-
- foreach ($overlay as $prop => $value) {
- // adjust time of the recurring event instance
- if ($prop == 'start' || $prop == 'end') {
- if (is_object($event[$prop]) && is_a($event[$prop], 'DateTime'))
- $event[$prop]->setTime($value->format('G'), intval($value->format('i')), intval($value->format('s')));
- }
- else if ($prop[0] != '_' && !in_array($prop, $forbidden))
- $event[$prop] = $value;
- }
- }
-
- /**
* Convert from Kolab_Format to internal representation
*/
private function _to_rcube_event($record)
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index f873166..9b70018 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -424,14 +424,6 @@ class kolab_driver extends calendar_driver
$savemode = $event['_savemode'];
}
- // removing an exception instance
- if ($event['recurrence_id']) {
- $i = $event['_instance'] - 1;
- if (!empty($master['recurrence']['EXCEPTIONS'][$i])) {
- unset($master['recurrence']['EXCEPTIONS'][$i]);
- }
- }
-
switch ($savemode) {
case 'current':
$_SESSION['calendar_restore_event_data'] = $master;
@@ -605,12 +597,43 @@ class kolab_driver extends calendar_driver
$success = $storage->insert_event($event);
break;
-
- case 'future':
+
case 'current':
- // recurring instances shall not store recurrence rules
+ // save as exception to master event
$event['recurrence'] = array();
- $event['thisandfuture'] = $savemode == 'future';
+ $master['recurrence']['EXCEPTIONS'][] = $event;
+# $master['recurrence']['EXDATE'][] = $event['start'];
+ $success = $storage->update_event($master);
+ break;
+
+ case 'future':
+ if ($master['id'] != $event['id']) {
+ // set until-date on master event
+ $master['recurrence']['UNTIL'] = clone $old['start'];
+ $master['recurrence']['UNTIL']->sub(new DateInterval('P1D'));
+ unset($master['recurrence']['COUNT']);
+ $storage->update_event($master);
+
+ // save this instance as new recurring event
+ $event += $old;
+ $event['uid'] = $this->cal->generate_uid();
+
+ // if recurrence COUNT, update value to the correct number of future occurences
+ if ($event['recurrence']['COUNT']) {
+ $event['recurrence']['COUNT'] -= $old['_instance'];
+ }
+
+ // remove fixed weekday, will be re-set to the new weekday in kolab_calendar::insert_event()
+ if (strlen($event['recurrence']['BYDAY']) == 2)
+ unset($event['recurrence']['BYDAY']);
+ if ($master['recurrence']['BYMONTH'] == $master['start']->format('n'))
+ unset($event['recurrence']['BYMONTH']);
+
+ $success = $storage->insert_event($event);
+ break;
+ }
+
+ default: // 'all' is default
// remove some internal properties which should not be saved
unset($event['_savemode'], $event['_fromcalendar'], $event['_identity']);
@@ -625,12 +648,6 @@ class kolab_driver extends calendar_driver
}
}
- // save as new exception to master event
- $master['recurrence']['EXCEPTIONS'][] = $event;
- $success = $storage->update_event($master);
- break;
-
- default: // 'all' is default
$event['id'] = $master['id'];
$event['uid'] = $master['uid'];
diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php
index acf0b67..933fbee 100644
--- a/plugins/libkolab/lib/kolab_format_event.php
+++ b/plugins/libkolab/lib/kolab_format_event.php
@@ -114,7 +114,7 @@ class kolab_format_event extends kolab_format_xcal
foreach((array)$object['recurrence']['EXCEPTIONS'] as $exception) {
$exevent = new kolab_format_event;
$exevent->set($this->compact_exception($exception, $object)); // only save differing values
- $exevent->obj->setRecurrenceID(self::get_datetime($exception['start'], null, true), (bool)$exception['thisandfuture']);
+ $exevent->obj->setRecurrenceID(self::get_datetime($exception['start'], null, true), false);
$vexceptions->push($exevent->obj);
}
$this->obj->setExceptions($vexceptions);
@@ -190,7 +190,7 @@ class kolab_format_event extends kolab_format_xcal
}
// read exception event objects
- if (($exceptions = $this->obj->exceptions()) && $exceptions->size()) {
+ if ($exceptions = $this->obj->exceptions()) {
for ($i=0; $i < $exceptions->size(); $i++) {
if (($exobj = $exceptions->get($i))) {
$exception = new kolab_format_event($exobj);
@@ -200,10 +200,6 @@ class kolab_format_event extends kolab_format_xcal
}
}
}
- // this is an exception object
- else if ($this->obj->recurrenceID()->isValid()) {
- $object['thisandfuture'] = $this->obj->thisAndFuture();
- }
// merge with additional data, e.g. attachments from the message
if ($data) {
@@ -242,15 +238,25 @@ class kolab_format_event extends kolab_format_xcal
}
/**
- * Remove some attributes from the exception container
+ * Reduce the exception container to attributes which differ from the master event
*/
private function compact_exception($exception, $master)
{
- $forbidden = array('recurrence','organizer','attendees','sequence');
+ static $mandatory = array('uid','created','start');
+ static $forbidden = array('recurrence','attendees','sequence');
+
+ $out = $exception;
+ foreach ($exception as $prop => $val) {
+ if (in_array($prop, $mandatory))
+ continue;
- foreach ($forbidden as $prop) {
- if (array_key_exists($prop, $exception)) {
- unset($exception[$prop]);
+ if (is_object($exception[$prop]) && is_a($exception[$prop], 'DateTime'))
+ $equals = $exception[$prop] <> $master[$prop];
+ else
+ $equals = $exception[$prop] == $master[$prop];
+
+ if ($equals || in_array($prop, $forbidden)) {
+ unset($out[$prop]);
}
}
@@ -262,8 +268,10 @@ class kolab_format_event extends kolab_format_xcal
*/
private function expand_exception($exception, $master)
{
+ static $forbidden = array('recurrence');
+
foreach ($master as $prop => $value) {
- if (empty($exception[$prop]) && !empty($value))
+ if (empty($exception[$prop]) && !in_array($prop, $forbidden))
$exception[$prop] = $value;
}