| | 20 | + (void)upgradeV1JoinedFileFromContext:(NSManagedObjectContext *)oldMoc toContext:(NSManagedObjectContext *)newMoc file:(NSDictionary *)fileLookup |
| | 21 | { |
| | 22 | NSArray *joins = doFetchRequest(SapphireJoinedFileName, oldMoc, nil); |
| | 23 | NSEnumerator *joinEnum = [joins objectEnumerator]; |
| | 24 | NSManagedObject *oldJoin; |
| | 25 | while((oldJoin = [joinEnum nextObject]) != nil) |
| | 26 | { |
| | 27 | NSString *destinationPath = [oldJoin valueForKeyPath:@"file.path"]; |
| | 28 | SapphireFileMetaData *destination = nil; |
| | 29 | if(destinationPath != nil) |
| | 30 | destination = [fileLookup objectForKey:destinationPath]; |
| | 31 | if(destination == nil) |
| | 32 | continue; |
| | 33 | |
| | 34 | NSArray *containingPaths = [oldJoin valueForKeyPath:@"joinedFiles.path"]; |
| | 35 | NSEnumerator *pathEnum = [containingPaths objectEnumerator]; |
| | 36 | NSString *path; |
| | 37 | NSMutableSet *joined = [NSMutableSet set]; |
| | 38 | while((path = [pathEnum nextObject]) != nil) |
| | 39 | { |
| | 40 | SapphireFileMetaData *join = [fileLookup objectForKey:path]; |
| | 41 | if(join != nil) |
| | 42 | [joined addObject:join]; |
| | 43 | } |
| | 44 | if([joined count] == 0) |
| | 45 | continue; |
| | 46 | |
| | 47 | SapphireJoinedFile *newJoin = [NSEntityDescription insertNewObjectForEntityForName:SapphireJoinedFileName inManagedObjectContext:newMoc]; |
| | 48 | newJoin.file = destination; |
| | 49 | [newJoin.joinedFilesSet setSet:joined]; |
| | 50 | } |
| | 51 | } |
| | 52 | |