From 8eb9cc25da93291f91cc876693f0502a4929a3d2 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 5 Jul 2011 19:45:09 +0200 Subject: [PATCH] Finalize recurring events: use patched Horde_Date_Recurrence class for recurrence computing; fix some misbehavior of the Kolab backend --- .../calendar/drivers/kolab/kolab_calendar.php | 6 +-- .../calendar/drivers/kolab/kolab_driver.php | 6 +-- .../calendar/lib/Horde_Date_Recurrence.php | 53 +++++++++---------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/plugins/calendar/drivers/kolab/kolab_calendar.php b/plugins/calendar/drivers/kolab/kolab_calendar.php index e9cf514b..a40b7ba2 100644 --- a/plugins/calendar/drivers/kolab/kolab_calendar.php +++ b/plugins/calendar/drivers/kolab/kolab_calendar.php @@ -323,7 +323,7 @@ class kolab_calendar private function _get_recurring_events($event, $start, $end, $event_id = null) { // use Horde classes to compute recurring instances - require_once 'Horde/Date/Recurrence.php'; + require_once($this->cal->home . '/lib/Horde_Date_Recurrence.php'); $recurrence = new Horde_Date_Recurrence($event['start']); $recurrence->fromRRule20(calendar::to_rrule($event['recurrence'])); @@ -415,7 +415,7 @@ class kolab_calendar else if ($recurrence['type'] == 'yearday') $rrule['BYYEARDAY'] = $recurrence['daynumber']; } - if ($rec['month']) { + if ($recurrence['month']) { $monthmap = array_flip($this->month_map); $rrule['BYMONTH'] = strtolower($monthmap[$recurrence['month']]); } @@ -585,7 +585,7 @@ class kolab_calendar $object['_attachments'] = array(); if (!empty($event['attachments'])) { foreach ($event['attachments'] as $idx => $attachment) { - // Roundcube ID has nothing to Horde ID, remove it + // Roundcube ID has nothing to do with Horde ID, remove it unset($attachment['id']); $object['_attachments'][$attachment['name']] = $attachment; unset($event['attachments'][$idx]); diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php index d5d158b0..935c7600 100644 --- a/plugins/calendar/drivers/kolab/kolab_driver.php +++ b/plugins/calendar/drivers/kolab/kolab_driver.php @@ -369,7 +369,7 @@ class kolab_driver extends calendar_driver } } - $event['attachments'] = array_merge($old['attachments'], $attachments); + $event['attachments'] = array_merge((array)$old['attachments'], $attachments); // modify a recurring event, check submitted savemode to do the right things if ($old['recurrence'] || $old['recurrence_id']) { @@ -420,7 +420,7 @@ class kolab_driver extends calendar_driver // 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 ($event['recurrence']['BYMONTH']) + if ($master['recurrence']['BYMONTH'] == gmdate('n', $master['start'])) unset($event['recurrence']['BYMONTH']); $success = $storage->insert_event($event); @@ -448,7 +448,7 @@ class kolab_driver extends calendar_driver // remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event() if (strlen($event['recurrence']['BYDAY']) == 2) unset($event['recurrence']['BYDAY']); - if ($event['recurrence']['BYMONTH']) + if ($old['recurrence']['BYMONTH'] == gmdate('n', $old['start'])) unset($event['recurrence']['BYMONTH']); } diff --git a/plugins/calendar/lib/Horde_Date_Recurrence.php b/plugins/calendar/lib/Horde_Date_Recurrence.php index 51a0bad2..2d14128a 100644 --- a/plugins/calendar/lib/Horde_Date_Recurrence.php +++ b/plugins/calendar/lib/Horde_Date_Recurrence.php @@ -5313,7 +5313,7 @@ class Horde_Date_Recurrence { */ function setRecurByMonth($months) { - $this->recurMonths = $months; + $this->recurMonths = (array)$months; } /** @@ -5332,7 +5332,7 @@ class Horde_Date_Recurrence { */ function setRecurNthWeekday($nthDay) { - $this->recurNthDay = $nthDay; + $this->recurNthDay = (int)$nthDay; } /** @@ -5842,7 +5842,7 @@ class Horde_Date_Recurrence { $weekday = $estart->dayOfWeek(); } - // set month from recurrence rule (FEXME: support more than one month) + // set month from recurrence rule (FIXME: support more than one month) if ($this->recurMonths) { $estart->month = $this->recurMonths[0]; } @@ -6430,6 +6430,21 @@ class Horde_Date_Recurrence { return false; } + $month2number = array( + 'january' => 1, + 'february' => 2, + 'march' => 3, + 'april' => 4, + 'may' => 5, + 'june' => 6, + 'july' => 7, + 'august' => 8, + 'september' => 9, + 'october' => 10, + 'november' => 11, + 'december' => 12, + ); + $this->setRecurInterval((int) $hash['interval']); $parse_day = false; @@ -6464,11 +6479,9 @@ class Horde_Date_Recurrence { case 'weekday': $this->setRecurType(HORDE_DATE_RECUR_MONTHLY_WEEKDAY); - $nth_weekday = (int) $hash['daynumber']; - $hash['daynumber'] = 1; + $this->setRecurNthWeekday($hash['daynumber']); $parse_day = true; - $update_daynumber = true; - $update_weekday = true; + $set_daymask = true; break; } break; @@ -6506,12 +6519,13 @@ class Horde_Date_Recurrence { } $this->setRecurType(HORDE_DATE_RECUR_YEARLY_WEEKDAY); - $nth_weekday = (int) $hash['daynumber']; - $hash['daynumber'] = 1; + $this->setRecurNthWeekday($hash['daynumber']); $parse_day = true; - $update_month = true; - $update_daynumber = true; - $update_weekday = true; + $set_daymask = true; + + if ($hash['month'] && isset($month2number[$hash['month']])) { + $this->setRecurByMonth($month2number[$hash['month']]); + } break; } } @@ -6580,21 +6594,6 @@ class Horde_Date_Recurrence { if ($update_month || $update_daynumber || $update_weekday) { if ($update_month) { - $month2number = array( - 'january' => 1, - 'february' => 2, - 'march' => 3, - 'april' => 4, - 'may' => 5, - 'june' => 6, - 'july' => 7, - 'august' => 8, - 'september' => 9, - 'october' => 10, - 'november' => 11, - 'december' => 12, - ); - if (isset($month2number[$hash['month']])) { $this->start->month = $month2number[$hash['month']]; }