From c74fe214846baf2f5c58f0c4b73bca79543f4454 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 28 Mar 2011 23:44:08 +0000 Subject: [PATCH] Monotone-Parent: 4d4875b78377fad6c271a5fa4aca9647af06baed Monotone-Revision: cbeb8ed4edd6c44d422f9251785ee9bfad432e71 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-03-28T23:44:08 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 +++++ Tools/SOGoToolRemoveDoubles.m | 46 +++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76f19bebf..a1aec3963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-28 Wolfgang Sourdeau + + * Tools/SOGoToolRemoveDoubles.m + (-detectDoublesFromRecords:withQuickField:): added a quick field + parameter to enable the use of other fields than just c_mail. + 2011-03-27 Ludovic Marcotte * Added the SOGoLocalStorageURL preference that allows diff --git a/Tools/SOGoToolRemoveDoubles.m b/Tools/SOGoToolRemoveDoubles.m index a81575e26..4f90de62c 100644 --- a/Tools/SOGoToolRemoveDoubles.m +++ b/Tools/SOGoToolRemoveDoubles.m @@ -86,14 +86,15 @@ return @"remove duplicate contacts from the specified user addressbook"; } -- (void) feedDoubleEmails: (NSMutableDictionary *) doubleEmails - withRecord: (NSDictionary *) record +- (void) feedDoubles: (NSMutableDictionary *) doubleEmails + withRecord: (NSDictionary *) record + andQuickField: (NSString *) field { NSString *recordEmail; NSMutableArray *recordList; - /* we want to match c_mail case-insensitively */ - recordEmail = [[record objectForKey: @"c_mail"] uppercaseString]; + /* we want to match the field value case-insensitively */ + recordEmail = [[record objectForKey: field] uppercaseString]; if ([recordEmail length]) { recordList = [doubleEmails objectForKey: recordEmail]; @@ -117,19 +118,21 @@ [doubleEmails removeObjectForKey: currentKey]; } -- (NSDictionary *) detectDoubleEmailsFromRecords: (NSArray *) records +- (NSDictionary *) detectDoublesFromRecords: (NSArray *) records + withQuickField: (NSString *) quickField { - NSMutableDictionary *doubleEmails; + NSMutableDictionary *doubles; unsigned int count, max; - doubleEmails = [NSMutableDictionary dictionaryWithCapacity: [records count]]; + doubles = [NSMutableDictionary dictionaryWithCapacity: [records count]]; max = [records count]; for (count = 0; count < max; count++) - [self feedDoubleEmails: doubleEmails - withRecord: [records objectAtIndex: count]]; - [self cleanupSingleRecords: doubleEmails]; + [self feedDoubles: doubles + withRecord: [records objectAtIndex: count] + andQuickField: quickField]; + [self cleanupSingleRecords: doubles]; - return doubleEmails; + return doubles; } - (NSArray *) fetchCardsInListsFromFolder: (GCSFolder *) folder @@ -164,13 +167,19 @@ usingChannel: (EOAdaptorChannel *) channel { NSString *delSql; + NSCalendarDate *now; /* We remove the records without regards to c_deleted because we really want to recover table space. */ - delSql = [NSString stringWithFormat: @"DELETE FROM %@" + now = [NSCalendarDate date]; + delSql = [NSString stringWithFormat: @"UPDATE %@" + @" SET c_deleted = 1, c_lastmodified = %d," + @" c_content = ''" @" WHERE c_name = '%@'", - tableName, recordName]; + tableName, + (NSUInteger) [now timeIntervalSince1970], + recordName]; [channel evaluateExpressionX: delSql]; delSql = [NSString stringWithFormat: @"DELETE FROM %@" @" WHERE c_name = '%@'", @@ -451,6 +460,7 @@ - (BOOL) removeDoublesFromFolder: (GCSFolder *) folder { NSArray *fields, *records, *recordsToRemove; + NSMutableDictionary *doubles; EOQualifier *qualifier; BOOL rc; @@ -465,8 +475,14 @@ if (records) { rc = YES; - recordsToRemove = [self detectRecordsToRemove: - [self detectDoubleEmailsFromRecords: records] + doubles = [NSMutableDictionary dictionary]; + [doubles addEntriesFromDictionary: + [self detectDoublesFromRecords: records + withQuickField: @"c_mail"]]; + [doubles addEntriesFromDictionary: + [self detectDoublesFromRecords: records + withQuickField: @"c_cn"]]; + recordsToRemove = [self detectRecordsToRemove: doubles withCardsInLists: [self fetchCardsInListsFromFolder: folder]]; if ([recordsToRemove count])