From 0c5b5446dded9f3d9e998fe5bd7f006273279d92 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 16 May 2018 14:58:04 -0400 Subject: [PATCH] Remove invalid occurrences when saving master --- NEWS | 1 + .../Appointments/SOGoAppointmentObject.h | 4 ++- .../Appointments/SOGoAppointmentObject.m | 21 ++++++++---- UI/Scheduler/UIxAppointmentEditor.m | 33 ++++++++++++++++--- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 1570b7ab7..fc891a030 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Enhancements - [web] now possible to show events/task for the current year - [web] show current ordering setting in lists + - [web] remove invalid occurrences when modifying a recurrent event - [web] updated Angular Material to version 1.1.9 Bug fixes diff --git a/SoObjects/Appointments/SOGoAppointmentObject.h b/SoObjects/Appointments/SOGoAppointmentObject.h index 667e1e22d..1cb7483f9 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.h +++ b/SoObjects/Appointments/SOGoAppointmentObject.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2016 Inverse inc. + Copyright (C) 2007-2018 Inverse inc. This file is part of SOGo @@ -49,6 +49,8 @@ alarm: (iCalAlarm *) alarm forRecurrenceId: (NSCalendarDate *) _recurrenceId; +- (void) prepareDeleteOccurence: (iCalEvent *) occurence; + // // Old CalDAV scheduling (draft 4 and below) methods. We keep them since we still // advertise for its support but we do everything within the calendar-auto-scheduling code diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index d855a48e3..9771242b2 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -317,16 +317,23 @@ } count++; } - + // Add an date exception. event = (iCalRepeatableEntityObject*)[calendar firstChildWithTag: [object componentTag]]; - [event addToExceptionDates: recurrenceId]; - - [event increaseSequence]; - [event setLastModified: [NSCalendarDate calendarDate]]; + if (event) + { + [event addToExceptionDates: recurrenceId]; + [event increaseSequence]; + [event setLastModified: [NSCalendarDate calendarDate]]; - // We save the updated iCalendar in the database. - [object saveCalendar: calendar]; + // We save the updated iCalendar in the database. + [object saveCalendar: calendar]; + } + else + { + // No more child; kill the parent + [object delete]; + } } } else diff --git a/UI/Scheduler/UIxAppointmentEditor.m b/UI/Scheduler/UIxAppointmentEditor.m index 82f038ba7..1dc694988 100644 --- a/UI/Scheduler/UIxAppointmentEditor.m +++ b/UI/Scheduler/UIxAppointmentEditor.m @@ -1,6 +1,6 @@ /* UIxAppointmentEditor.m - this file is part of SOGo * - * Copyright (C) 2007-2017 Inverse inc. + * Copyright (C) 2007-2018 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ #import #import #import +#import #import #import #import @@ -189,14 +190,20 @@ - (NSException *) _adjustRecurrentRules { - iCalEvent *event; - iCalRecurrenceRule *rule; + NSArray *events; + NSCalendarDate *untilDate, *recurrenceId; NSEnumerator *rules; NSException *ex; - NSCalendarDate *untilDate; - SOGoUserDefaults *ud; NSTimeZone *timeZone; + SOGoAppointmentObject *co; + SOGoUserDefaults *ud; + iCalCalendar *calendar; + iCalEvent *event; + iCalRecurrenceRule *rule; + iCalRepeatableEntityObject *masterEvent, *occurrence; + int count, max; + co = [self clientObject]; event = [self event]; rules = [[event recurrenceRules] objectEnumerator]; ex = nil; @@ -234,6 +241,22 @@ } } + // Remove invalid occurrences + calendar = [event parent]; + events = [calendar events]; + masterEvent = [events objectAtIndex: 0]; + max = [events count]; + for (count = max - 1; count > 0; count--) + { + occurrence = [events objectAtIndex: count]; + recurrenceId = [occurrence recurrenceId]; + if (recurrenceId && ![masterEvent doesOccurOnDate: recurrenceId]) + { + [co prepareDeleteOccurence: (iCalEvent *)occurrence]; // notify attendees, update their calendars + [calendar removeChild: occurrence]; + } + } + return ex; }