From 5c1610c070b53b372c2ea05e0ab96d72599c57da Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 13 Aug 2012 17:48:43 +0000 Subject: [PATCH] Monotone-Parent: dbc58efbc938f11a813baa01021a534ed90f70b8 Monotone-Revision: ded960271197442de0917fc8f66509f7377b6a75 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-08-13T17:48:43 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 ++ OpenChange/SOGoMAPIDBFolder.h | 2 ++ OpenChange/SOGoMAPIDBFolder.m | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/ChangeLog b/ChangeLog index d215a538c..3a0249635 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-08-13 Wolfgang Sourdeau + * OpenChange/SOGoMAPIDBFolder.m (-changePathTo:): overriden method + in order to update children records too. + * OpenChange/SOGoMAPIDBObject.m (-performBatchSQLQueries:) new method to perform void queries under a transaction. (-changePathTo:) new method that updates the references for the diff --git a/OpenChange/SOGoMAPIDBFolder.h b/OpenChange/SOGoMAPIDBFolder.h index e2d29058f..d055291bc 100644 --- a/OpenChange/SOGoMAPIDBFolder.h +++ b/OpenChange/SOGoMAPIDBFolder.h @@ -52,6 +52,8 @@ matchingQualifier: (EOQualifier *) qualifier andSortOrderings: (NSArray *) sortOrderings; +- (void) changePathTo: (NSString *) newPath; + @end #endif /* SOGOMAPIDBFOLDER_H */ diff --git a/OpenChange/SOGoMAPIDBFolder.m b/OpenChange/SOGoMAPIDBFolder.m index 2607eb1aa..2e9556dcb 100644 --- a/OpenChange/SOGoMAPIDBFolder.m +++ b/OpenChange/SOGoMAPIDBFolder.m @@ -30,11 +30,13 @@ #import #import +#import #import #import // #import #import +#import #import #import #import "EOQualifier+MAPI.h" @@ -213,6 +215,57 @@ Class SOGoMAPIDBObjectK = Nil; andSortOrderings: nil]; } +- (void) changePathTo: (NSString *) newPath +{ + NSMutableString *sql// , *qualifierClause + ; + NSString *oldPath, *oldPathAsPrefix, *path, *parentPath; + NSMutableArray *queries; + NSArray *records; + NSDictionary *record; + NSUInteger count, max; + + /* change the paths in children records */ + oldPath = [self path]; + oldPathAsPrefix = [NSString stringWithFormat: @"%@/", oldPath]; + + sql = [NSMutableString stringWithFormat: + @"SELECT c_path, c_parent_path FROM %@" + @" WHERE c_path LIKE '%@%%'", + [self tableName], oldPathAsPrefix]; + records = [self performSQLQuery: sql]; + max = [records count]; + queries = [NSMutableArray arrayWithCapacity: max + 1]; + if (max > 0) + { + for (count = 0; count < max; count++) + { + record = [records objectAtIndex: count]; + path = [record objectForKey: @"c_path"]; + if ([path isEqualToString: oldPath] + || [path hasPrefix: oldPathAsPrefix]) + { + sql = [NSMutableString stringWithFormat: @"UPDATE %@" + @" SET c_path = '%@'", + [self tableName], + [path stringByReplacingPrefix: oldPath + withPrefix: newPath]]; + parentPath = [record objectForKey: @"c_parent_path"]; + if ([parentPath isNotNull]) + [sql appendFormat: @", c_parent_path = '%@'", + [parentPath stringByReplacingPrefix: oldPath + withPrefix: newPath]]; + [sql appendFormat: @" WHERE c_path = '%@'", oldPath]; + [queries addObject: sql]; + } + } + [self performBatchSQLQueries: queries]; + } + + /* change the path in this folder record */ + [super changePathTo: newPath]; +} + // - (NSArray *) toOneRelationshipKeysMatchingQualifier: (EOQualifier *) qualifier // andSortOrderings: (NSArray *) sortOrderings // {