Monotone-Parent: dbc58efbc938f11a813baa01021a534ed90f70b8

Monotone-Revision: ded960271197442de0917fc8f66509f7377b6a75

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2012-08-13T17:48:43
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2012-08-13 17:48:43 +00:00
parent 57afca1c74
commit 5c1610c070
3 changed files with 58 additions and 0 deletions

View File

@ -1,5 +1,8 @@
2012-08-13 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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

View File

@ -52,6 +52,8 @@
matchingQualifier: (EOQualifier *) qualifier
andSortOrderings: (NSArray *) sortOrderings;
- (void) changePathTo: (NSString *) newPath;
@end
#endif /* SOGOMAPIDBFOLDER_H */

View File

@ -30,11 +30,13 @@
#import <Foundation/NSURL.h>
#import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSNull+misc.h>
#import <GDLAccess/EOAdaptorChannel.h>
#import <GDLContentStore/GCSChannelManager.h>
// #import <GDLContentStore/EOQualifier+GCS.m>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoUser.h>
#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
// {