From 32a1b4070494c839eff16a86a1bbe69f9cbc6326 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 27 Jan 2015 18:11:54 +0000 Subject: [PATCH] * Calendar/CalDAV: fixed not synced recurrences, because invitation was to a group only or first recurrence was an exception --- calendar/inc/class.calendar_groupdav.inc.php | 30 +++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/calendar/inc/class.calendar_groupdav.inc.php b/calendar/inc/class.calendar_groupdav.inc.php index fdf3616de0..5c02dad457 100644 --- a/calendar/inc/class.calendar_groupdav.inc.php +++ b/calendar/inc/class.calendar_groupdav.inc.php @@ -647,24 +647,28 @@ class calendar_groupdav extends groupdav_handler $events =& $bo->search($params); + // find master, which is not always first event, eg. when first event is an exception $master = null; foreach($events as $k => &$recurrence) { - if (!isset($master)) // first event is master + if ($recurrence['recur_type']) { $master = $recurrence; $exceptions =& $master['recur_exception']; unset($events[$k]); - continue; + break; } + } + foreach($events as $k => &$recurrence) + { //error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($uid)[$k]:" . array2string($recurrence)); if ($recurrence['id'] != $master['id']) // real exception { // user is NOT participating in this exception - if ($user && !isset($recurrence['participants'][$user])) + if ($user && !self::isParticipant($recurrence, $user)) { // if he is NOT in master, delete this exception - if (!isset($master['participants'][$user])) + if (!self::isParticipant($master, $user)) { unset($events[$k]); continue; @@ -698,15 +702,27 @@ class calendar_groupdav extends groupdav_handler // not for included exceptions (Lightning): $master['recur_exception'][] = $recurrence['start']; } // only add master if we are not expanding and current user participates in master (and not just some exceptions) - if (!$expand && (!$user || isset($master['participants'][$user]) || - // for group-invitations we need to check memberships of $user too - array_intersect(array_keys($master['participants']), $GLOBALS['egw']->accounts->memberships($user, true)))) + if (!$expand && (!$user || self::isParticipant($master, $user))) { $events = array_merge(array($master), $events); } return $events; } + /** + * Check if $user is a participant of given $event incl. group-invitations + * + * @param array $event + * @param int|string $user + * @return boolean + */ + public static function isParticipant(array $event, $user) + { + return isset($event['participants'][$user]) || + // for group-invitations we need to check memberships of $user too + array_intersect(array_keys($event['participants']), $GLOBALS['egw']->accounts->memberships($user, true)); + } + /** * Handle put request for an event *