summaryrefslogtreecommitdiff
path: root/plugins/calendar
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-10 13:30:50 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-10 13:30:50 (GMT)
commit60205136eeeecc0be3cc62bc5652206d3ab2009e (patch)
tree07c909ebc355d483868a6f6153fdfaa5897b8e54 /plugins/calendar
parent738cdb70176e67e6d4cc0635e7a9e261e26af1c9 (diff)
downloadroundcubemail-plugins-kolab-60205136eeeecc0be3cc62bc5652206d3ab2009e.tar.gz
Code cleanup: get recurrence instance identifiers from utility functions
Diffstat (limited to 'plugins/calendar')
-rw-r--r--plugins/calendar/drivers/calendar_driver.php2
-rw-r--r--plugins/calendar/drivers/database/database_driver.php11
-rw-r--r--plugins/calendar/drivers/kolab/kolab_calendar.php10
-rw-r--r--plugins/calendar/drivers/kolab/kolab_driver.php14
-rw-r--r--plugins/calendar/lib/calendar_recurrence.php3
5 files changed, 16 insertions, 24 deletions
diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index 659f4a0..1cd6956 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -463,7 +463,7 @@ abstract class calendar_driver
$rcmail = rcmail::get_instance();
$recurrence = new calendar_recurrence($rcmail->plugins->get_plugin('calendar'), $event);
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($event);
// determine a reasonable end date if none given
if (!$end) {
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 14a8891..402e0c3 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -388,10 +388,9 @@ class database_driver extends calendar_driver
// set exception to first instance (= master)
if ($event['id'] == $master['id']) {
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
$event += $old;
$event['recurrence_id'] = $master['id'];
- $event['_instance'] = $old['start']->format($recurrence_id_format);
+ $event['_instance'] = libcalendaring::recurrence_instance_identifier($old);
$event['isexception'] = 1;
$event_id = $this->_insert_event($event);
return $event_id;
@@ -463,7 +462,7 @@ class database_driver extends calendar_driver
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
if (is_array($event['recurrence']) && ($old_start_date != $new_start_date || $old_start_time != $new_start_time)
&& ($exceptions = $this->_load_exceptions($old))) {
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($event);
foreach ($exceptions as $exception) {
$recurrence_id = rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
if (is_a($recurrence_id, 'DateTime')) {
@@ -764,8 +763,9 @@ class database_driver extends calendar_driver
$recurrence = new calendar_recurrence($this->cal, $event);
$count = 0;
+ $event['allday'] = $event['all_day'];
$duration = $event['start']->diff($event['end']);
- $recurrence_id_format = $event['all_day'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($event);
while ($next_start = $recurrence->next_start()) {
$instance = $next_start->format($recurrence_id_format);
$datestr = substr($instance, 0, 8);
@@ -1075,8 +1075,7 @@ class database_driver extends calendar_driver
}
// check for exception on first instance
else {
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
- $instance = $event['start']->format($recurrence_id_format);
+ $instance = libcalendaring::recurrence_instance_identifier($event);
$exceptions = $this->_load_exceptions($event, $instance);
if ($exceptions && is_array($exceptions[$instance])) {
$event = $exceptions[$instance];
diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php
index a443ee2..f3c26c9 100644
--- a/plugins/calendar/drivers/kolab/kolab_calendar.php
+++ b/plugins/calendar/drivers/kolab/kolab_calendar.php
@@ -616,14 +616,12 @@ class kolab_calendar extends kolab_storage_folder_api
$events = array();
$exdata = array();
$futuredata = array();
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($event);
if (is_array($event['recurrence']['EXCEPTIONS'])) {
foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
- if (!$exception['_instance'] && is_a($exception['recurrence_date'], 'DateTime'))
- $exception['_instance'] = $exception['recurrence_date']->format($recurrence_id_format);
- else if (!$exception['_instance'] && is_a($exception['start'], 'DateTime'))
- $exception['_instance'] = $exception['start']->format($recurrence_id_format);
+ if (!$exception['_instance'])
+ $exception['_instance'] = libcalendaring::recurrence_instance_identifier($exception);
$rec_event = $this->_to_driver_event($exception);
$rec_event['id'] = $event['uid'] . '-' . $exception['_instance'];
@@ -717,7 +715,7 @@ class kolab_calendar extends kolab_storage_folder_api
}
// add instance identifier to first occurrence (master event)
- $recurrence_id_format = $record['allday'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($record);
if (!$noinst && $record['recurrence'] && !$record['recurrence_id'] && !$record['_instance']) {
$record['_instance'] = $record['start']->format($recurrence_id_format);
}
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index cc08e6b..f494e39 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -791,8 +791,7 @@ class kolab_driver extends calendar_driver
$_SESSION['calendar_restore_event_data'] = $master;
// removing the first instance => just move to next occurence
- $recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
- if ($master['recurrence'] && $event['_instance'] == $master['start']->format($recurrence_id_format)) {
+ if ($master['recurrence'] && $event['_instance'] == libcalendaring::recurrence_instance_identifier($master)) {
$recurring = reset($storage->get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
// no future instances found: delete the master event (bug #1677)
@@ -822,8 +821,7 @@ class kolab_driver extends calendar_driver
break;
case 'future':
- $recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
- $master['_instance'] = $master['start']->format($recurrence_id_format);
+ $master['_instance'] = libcalendaring::recurrence_instance_identifier($master);
if ($master['_instance'] != $event['_instance']) {
$_SESSION['calendar_restore_event_data'] = $master;
@@ -952,8 +950,7 @@ class kolab_driver extends calendar_driver
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] || $old['isexception'] ? 'current' : 'all');
// this-and-future on the first instance equals to 'all'
- $recurrence_id_format = $master['allday'] ? 'Ymd' : 'Ymd\THis';
- if ($savemode == 'future' && $master['start'] && $old['_instance'] == $master['start']->format($recurrence_id_format))
+ if ($savemode == 'future' && $master['start'] && $old['_instance'] == libcalendaring::recurrence_instance_identifier($master))
$savemode = 'all';
// force 'current' mode for single occurrences stored as exception
else if (!$old['recurrence'] && !$old['recurrence_id'] && $old['isexception'])
@@ -1176,7 +1173,7 @@ class kolab_driver extends calendar_driver
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
if ($old_start_date != $new_start_date || $old_start_time != $new_start_time) {
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
+ $recurrence_id_format = libcalendaring::recurrence_id_format($event);
foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
$recurrence_id = is_a($exception['recurrence_date'], 'DateTime') ? $exception['recurrence_date'] :
rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
@@ -1337,8 +1334,7 @@ class kolab_driver extends calendar_driver
}
if (!$event['_instance'] && is_a($event['recurrence_date'], 'DateTime')) {
- $recurrence_id_format = $event['allday'] ? 'Ymd' : 'Ymd\THis';
- $event['_instance'] = $event['recurrence_date']->format($recurrence_id_format);
+ $event['_instance'] = libcalendaring::recurrence_instance_identifier($event);
}
if (!is_array($master['exceptions']) && is_array($master['recurrence']['EXCEPTIONS'])) {
diff --git a/plugins/calendar/lib/calendar_recurrence.php b/plugins/calendar/lib/calendar_recurrence.php
index d3af94d..44d5b08 100644
--- a/plugins/calendar/lib/calendar_recurrence.php
+++ b/plugins/calendar/lib/calendar_recurrence.php
@@ -74,9 +74,8 @@ class calendar_recurrence extends libcalendaring_recurrence
$next['end']->add($this->duration);
}
- $recurrence_id_format = $next['allday'] ? 'Ymd' : 'Ymd\THis';
$next['recurrence_date'] = clone $next_start;
- $next['_instance'] = $next_start->format($recurrence_id_format);
+ $next['_instance'] = libcalendaring::recurrence_instance_identifier($next);
unset($next['_formatobj']);