Monotone-Parent: 4d4875b78377fad6c271a5fa4aca9647af06baed

Monotone-Revision: cbeb8ed4edd6c44d422f9251785ee9bfad432e71

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2011-03-28T23:44:08
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2011-03-28 23:44:08 +00:00
parent 4998932fdd
commit c74fe21484
2 changed files with 37 additions and 15 deletions

View File

@@ -1,3 +1,9 @@
2011-03-28 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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 <lmarcotte@inverse.ca>
* Added the SOGoLocalStorageURL preference that allows

View File

@@ -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])