From 6cd140cc5db1d4db7fd10284ea1f46a7a2c2ef59 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 28 Oct 2010 15:47:29 +0000 Subject: [PATCH] see ChangeLog Monotone-Parent: e614ca6146bb5052469a2b393909509aa081acc0 Monotone-Revision: fb42e2a1670666605ac484d419b64d92c83f004d Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-10-28T15:47:29 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 +++ .../Appointments/SOGoAppointmentFolders.m | 52 +++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0caa1e65..0206e0734 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-10-28 Wolfgang Sourdeau + + * SoObjects/Appointments/SOGoAppointmentFolders.m + (-_migrateWebCalendarsSettings): fixed a bug where the active + user's login name would be used as comparison prefix, leading to a + corrupted and very long calendar key. Added code to migrate those + previously corrupted keys to their proper form. + 2010-10-27 Wolfgang Sourdeau * UI/Contacts/UIxContactView.m (-categories): new accessor for diff --git a/SoObjects/Appointments/SOGoAppointmentFolders.m b/SoObjects/Appointments/SOGoAppointmentFolders.m index 46c256336..5b466d24d 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolders.m +++ b/SoObjects/Appointments/SOGoAppointmentFolders.m @@ -414,6 +414,44 @@ static SoSecurityManager *sm = nil; return componentSet; } +/* This method fixes an issue that occurred previously in + _migrateWebCalendarsSettings, where the active user, rather than the + owner's login would be taken to compose the expected key prefix, leading to + a corrupted calendar key with an endless chain of + [user]:/Calendar/[user]:/Calendar/[user].... occurrences. */ +- (NSString *) _fixedWebCalendarKey: (NSString *) oldKey +{ + NSString *newKey; + NSRange lastOccurrence, fullOccurrence; + + lastOccurrence = [oldKey rangeOfString: @":Calendar/" + options: NSBackwardsSearch]; + if ([oldKey rangeOfString: @":Calendar/"].location != lastOccurrence.location) + { + fullOccurrence + = [oldKey rangeOfString: + [NSString stringWithFormat: @"%@:Calendar/", + owner] + options: NSBackwardsSearch]; + if (fullOccurrence.location != NSNotFound) + { + newKey = [oldKey substringFromIndex: fullOccurrence.location]; + [self logWithFormat: @"fixed erroneous calendar key: '%@' -> '%@'", + oldKey, newKey]; + } + else + { + [self errorWithFormat: @"calendar key cannot be fixed: '%@'", + oldKey]; + newKey = nil; + } + } + else + newKey = nil; + + return newKey; +} + - (void) _migrateWebCalendarsSettings { SOGoUserSettings *us; @@ -426,20 +464,24 @@ static SoSecurityManager *sm = nil; hasChanged = NO; - us = [[context activeUser] userSettings]; + prefix = [NSString stringWithFormat: @"%@:Calendar/", + [self ownerInContext: context]]; + + us = [[SOGoUser userWithLogin: owner] userSettings]; module = [us objectForKey: @"Calendar"]; webCalendars = [module objectForKey: @"WebCalendars"]; keys = [webCalendars allKeys]; max = [keys count]; - prefix = [NSString stringWithFormat: @"%@:Calendar/", - [self ownerInContext: context]]; for (count = 0; count < max; count++) { oldKey = [keys objectAtIndex: count]; - if (![oldKey hasPrefix: prefix]) + if ([oldKey hasPrefix: prefix]) + newKey = [self _fixedWebCalendarKey: oldKey]; + else + newKey = [prefix stringByAppendingString: oldKey]; + if (newKey) { - newKey = [prefix stringByAppendingString: oldKey]; [webCalendars setObject: [webCalendars objectForKey: oldKey] forKey: newKey]; [webCalendars removeObjectForKey: oldKey];