| | 54 | } |
| | 55 | |
| | 56 | + (NSDictionary *)upgradeV1DirectoriesFromContext:(NSManagedObjectContext *)oldMoc toContext:(NSManagedObjectContext *)newMoc |
| | 57 | { |
| | 58 | NSMutableDictionary *lookup = [NSMutableDictionary dictionary]; |
| | 59 | NSArray *dirs = doFetchRequest(SapphireDirectoryMetaDataName, oldMoc, nil); |
| | 60 | NSEnumerator *dirEnum = [dirs objectEnumerator]; |
| | 61 | NSManagedObjectContext *oldDir; |
| | 62 | while((oldDir = [dirEnum nextObject]) != nil) |
| | 63 | { |
| | 64 | SapphireDirectoryMetaData *newDir = [NSEntityDescription insertNewObjectForEntityForName:SapphireDirectoryMetaDataName inManagedObjectContext:newMoc]; |
| | 65 | NSString *path = [oldDir valueForKey:@"path"]; |
| | 66 | newDir.path = path; |
| | 67 | NSManagedObject *oldCollection = [newDir valueForKey:@"collectionDirectory"]; |
| | 68 | if(oldCollection != nil) |
| | 69 | newDir.collectionDirectory = [SapphireCollectionDirectory upgradeV1CollectionDirectory:oldCollection toContext:newMoc]; |
| | 70 | [lookup setObject:newDir forKey:path]; |
| | 71 | } |
| | 72 | dirEnum = [dirs objectEnumerator]; |
| | 73 | while((oldDir = [dirEnum nextObject]) != nil) |
| | 74 | { |
| | 75 | NSString *path = [oldDir valueForKey:@"path"]; |
| | 76 | NSString *parentPath = [oldDir valueForKeyPath:@"parent.path"]; |
| | 77 | if(parentPath != nil) |
| | 78 | ((SapphireDirectoryMetaData *)[lookup objectForKey:path]).parent = [lookup objectForKey:parentPath]; |
| | 79 | } |
| | 80 | return lookup; |