From 43dc7dee8748e97819c950e54d61932eb4f43b39 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 31 Mar 2017 15:33:19 -0400 Subject: [PATCH] (fix) calendar component move across collections (fixes #4116) --- NEWS | 1 + .../Appointments/SOGoCalendarComponent.m | 76 +++++++++---------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/NEWS b/NEWS index e70a3f917..7e3404077 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ ------------------- Bug fixes + - [core] fixed calendar component move across collections (#4116) - [eas] fixed opacity in EAS freebusy (#4033) 2.3.20 (2017-03-10) diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index ecf6b1be5..535120c83 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -1197,6 +1197,36 @@ return uids; } +- (NSException *) _copyComponent: (iCalCalendar *) calendar + toFolder: (SOGoGCSFolder *) newFolder + updateUID: (BOOL) updateUID +{ + NSString *newUID; + SOGoCalendarComponent *newComponent; + + if (updateUID) + { + NSArray *elements; + unsigned int count, max; + + newUID = [self globallyUniqueObjectId]; + elements = [calendar allObjects]; + max = [elements count]; + for (count = 0; count < max; count++) + [[elements objectAtIndex: count] setUid: newUID]; + } + else + { + newUID = [[[calendar allObjects] objectAtIndex: 0] uid]; + } + + newComponent = [[self class] objectWithName: + [NSString stringWithFormat: @"%@.ics", newUID] + inContainer: newFolder]; + + return [newComponent saveCalendar: calendar]; +} + - (NSException *) copyToFolder: (SOGoGCSFolder *) newFolder { return [self copyComponent: [self calendar: NO secure: NO] @@ -1206,51 +1236,21 @@ - (NSException *) copyComponent: (iCalCalendar *) calendar toFolder: (SOGoGCSFolder *) newFolder { - NSArray *elements; - NSString *newUID; - unsigned int count, max; - SOGoCalendarComponent *newComponent; - - newUID = [self globallyUniqueObjectId]; - elements = [calendar allObjects]; - max = [elements count]; - for (count = 0; count < max; count++) - [[elements objectAtIndex: count] setUid: newUID]; - - newComponent = [[self class] objectWithName: - [NSString stringWithFormat: @"%@.ics", newUID] - inContainer: newFolder]; - - return [newComponent saveCalendar: calendar]; + return [self _copyComponent: calendar + toFolder: newFolder + updateUID: YES]; } - (NSException *) moveToFolder: (SOGoGCSFolder *) newFolder { - SOGoCalendarComponent *newComponent; NSException *ex; - id o; - // Lookup to see if the event exists in the target calendar. During a MOVE, we do - // keep the ID of the event intact. - o = [newFolder lookupName: [self nameInContainer] - inContext: context - acquire: NO]; + ex = [self _copyComponent: [self calendar: NO secure: NO] + toFolder: newFolder + updateUID: NO]; - if ([o isKindOfClass: [NSException class]]) - { - newComponent = [[self class] objectWithName: [self nameInContainer] - inContainer: newFolder]; - - ex = [newComponent saveCalendar: [self calendar: NO secure: NO]]; - - if (!ex) - ex = [self delete]; - } - else - { - ex = [NSException exceptionWithHTTPStatus: 409 - reason: @"Target exists - MOVE disallowed."]; - } + if (!ex) + ex = [self delete]; return ex; }