diff --git a/ChangeLog b/ChangeLog index ab99c99d9..08939ad65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-08-15 Wolfgang Sourdeau + * OpenChange/SOGoMAPIDBObject.m (-setNameInContainer): update the + object record in the database to reflect the change of folder + name. + * OpenChange/MAPIStoreMailContext.m (-updateURLWithFolderName): change the folder name used in the context url to use the new folder name after a rename operation, so that further invocations diff --git a/OpenChange/SOGoMAPIDBFolder.m b/OpenChange/SOGoMAPIDBFolder.m index 914cba1c1..1ed8d23ff 100644 --- a/OpenChange/SOGoMAPIDBFolder.m +++ b/OpenChange/SOGoMAPIDBFolder.m @@ -215,6 +215,56 @@ Class SOGoMAPIDBObjectK = Nil; andSortOrderings: nil]; } +- (void) setNameInContainer: (NSString *) newName +{ + NSMutableString *sql; + NSString *oldPath, *newPath, *path, *parentPath; + NSMutableArray *queries; + NSArray *records; + NSDictionary *record; + NSUInteger count, max; + + /* change the paths in children records */ + if (nameInContainer) + oldPath = [self path]; + + [super setNameInContainer: newName]; + + if (nameInContainer) + { + newPath = [self path]; + + sql = [NSMutableString stringWithFormat: + @"SELECT c_path, c_parent_path FROM %@" + @" WHERE c_path LIKE '%@/%%'", + [self tableName], oldPath]; + 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"]; + 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 = '%@'", path]; + [queries addObject: sql]; + } + [self performBatchSQLQueries: queries]; + } + } +} + - (void) changePathTo: (NSString *) newPath { NSMutableString *sql// , *qualifierClause diff --git a/OpenChange/SOGoMAPIDBObject.m b/OpenChange/SOGoMAPIDBObject.m index deb760383..0b75270af 100644 --- a/OpenChange/SOGoMAPIDBObject.m +++ b/OpenChange/SOGoMAPIDBObject.m @@ -260,6 +260,29 @@ static EOAttribute *textColumn = nil; } /* actions */ +- (void) setNameInContainer: (NSString *) newNameInContainer +{ + NSMutableString *sql; + NSString *oldPath, *newPath; + + if (nameInContainer) + oldPath = [self path]; + + [super setNameInContainer: newNameInContainer]; + + if (nameInContainer) + { + newPath = [self path]; + + sql = [NSMutableString stringWithFormat: @"UPDATE %@" + @" SET c_path = '%@'", + [self tableName], + newPath]; + [sql appendFormat: @" WHERE c_path = '%@'", oldPath]; + [self performBatchSQLQueries: [NSArray arrayWithObject: sql]]; + } +} + - (void) changePathTo: (NSString *) newPath { NSMutableString *sql;