Skip to content

Commit

Permalink
Use GCSSpecialQueries in sogo-tool rename-user
Browse files Browse the repository at this point in the history
Fixes #1924
The SQL syntax used by the former query would only work
with postgresql and Oracle.
  • Loading branch information
Jean Raby committed Nov 13, 2012
1 parent 8c96f71 commit 378eef4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
41 changes: 41 additions & 0 deletions SOPE/GDLContentStore/GCSSpecialQueries.m
Expand Up @@ -110,6 +110,14 @@ - (NSDictionary *) sessionsAttributeTypes
return nil;
}

- (NSString *) updateCPathInFolderInfo: (NSString *) tableName
withCPath2: (NSString *) c_path2
{
[self subclassResponsibility: _cmd];

return nil;
}


@end

Expand Down Expand Up @@ -205,6 +213,17 @@ - (NSDictionary *) sessionsAttributeTypes
return types;
}

- (NSString *) updateCPathInFolderInfo: (NSString *) tableName
withCPath2: (NSString *) c_path2
{
static NSString *sqlFolderFormat
= (@"UPDATE %@"
@" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4"
@" WHERE c_path2 = '%@'");

return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2];
}

@end

//
Expand Down Expand Up @@ -299,6 +318,17 @@ - (NSDictionary *) sessionsAttributeTypes
return types;
}

- (NSString *) updateCPathInFolderInfo: (NSString *) tableName
withCPath2: (NSString *) c_path2
{
static NSString *sqlFolderFormat
= (@"UPDATE %@"
@" SET c_path = CONCAT('/', c_path1, '/', c_path2, '/', c_path3, '/', c_path4)"
@" WHERE c_path2 = '%@'");

return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2];
}

@end

//
Expand Down Expand Up @@ -392,4 +422,15 @@ - (NSDictionary *) sessionsAttributeTypes
return types;
}

- (NSString *) updateCPathInFolderInfo: (NSString *) tableName
withCPath2: (NSString *) c_path2
{
static NSString *sqlFolderFormat
= (@"UPDATE %@"
@" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4"
@" WHERE c_path2 = '%@'");

return [NSString stringWithFormat: sqlFolderFormat, tableName, c_path2];
}

@end
19 changes: 13 additions & 6 deletions Tools/SOGoToolRenameUser.m
Expand Up @@ -35,6 +35,7 @@
#import <GDLContentStore/GCSChannelManager.h>
#import <GDLContentStore/GCSFolder.h>
#import <GDLContentStore/GCSFolderManager.h>
#import <GDLContentStore/GCSSpecialQueries.h>
#import <GDLContentStore/NSURL+GCS.h>

#import <SOGo/NSString+Utilities.h>
Expand Down Expand Up @@ -113,6 +114,7 @@ - (BOOL) _updateSOGoFolderInfoFromUser: (NSString *) fromUserID
BOOL rc = NO;
GCSFolderManager *fm;
GCSChannelManager *cm;
GCSSpecialQueries *specialQueries;
NSURL *folderLocation;
EOAdaptorContext *ac;
EOAdaptorChannel *fc;
Expand All @@ -125,6 +127,7 @@ - (BOOL) _updateSOGoFolderInfoFromUser: (NSString *) fromUserID
folderLocation = [fm folderInfoLocation];
fc = [cm acquireOpenChannelForURL: folderLocation];
ac = [fc adaptorContext];
specialQueries = [fc specialQueries];
sqlFromUserID = [fromUserID asSafeSQLString];
sqlToUserID = [toUserID asSafeSQLString];

Expand All @@ -137,15 +140,16 @@ - (BOOL) _updateSOGoFolderInfoFromUser: (NSString *) fromUserID
if (!sqlError)
{
sql
= [NSString stringWithFormat: @"UPDATE %@"
@" SET c_path = '/'||c_path1||'/'||c_path2||'/'||c_path3||'/'||c_path4"
@" WHERE c_path2 = '%@'",
[folderLocation gcsTableName], sqlToUserID];
= [specialQueries updateCPathInFolderInfo: [folderLocation gcsTableName]
withCPath2: sqlToUserID];
sqlError = [fc evaluateExpressionX: sql];
}

if (sqlError)
[ac rollbackTransaction];
{
[ac rollbackTransaction];
NSLog([sqlError reason]);
}
else
rc = [ac commitTransaction];

Expand Down Expand Up @@ -195,7 +199,10 @@ - (BOOL) _updateSOGoUserProfileFromUser: (NSString *) fromUserID
[profileLocation gcsTableName], sqlToUserID, sqlFromUserID];
sqlError = [fc evaluateExpressionX: sql];
if (sqlError)
[ac rollbackTransaction];
{
[ac rollbackTransaction];
NSLog([sqlError reason]);
}
else
rc = [ac commitTransaction];

Expand Down

0 comments on commit 378eef4

Please sign in to comment.