| | 48 | } |
| | 49 | |
| | 50 | + (void)upgradeV1EpisodesFromContext:(NSManagedObjectContext *)oldMoc toContext:(NSManagedObjectContext *)newMoc file:(NSDictionary *)fileLookup |
| | 51 | { |
| | 52 | NSArray *eps = doFetchRequest(SapphireEpisodeName, oldMoc, nil); |
| | 53 | NSEnumerator *epEnum = [eps objectEnumerator]; |
| | 54 | NSManagedObject *oldEp; |
| | 55 | while((oldEp = [epEnum nextObject]) != nil) |
| | 56 | { |
| | 57 | NSArray *oldFilePaths = [oldEp valueForKeyPath:@"files.path"]; |
| | 58 | NSEnumerator *pathEnum = [oldFilePaths objectEnumerator]; |
| | 59 | NSString *path; |
| | 60 | NSMutableSet *newFiles = [NSMutableSet set]; |
| | 61 | while((path = [pathEnum nextObject]) != nil) |
| | 62 | { |
| | 63 | SapphireFileMetaData *newFile = [fileLookup objectForKey:path]; |
| | 64 | if(newFile != nil) |
| | 65 | [newFiles addObject:newFile]; |
| | 66 | } |
| | 67 | if([newFiles count] == 0) |
| | 68 | continue; |
| | 69 | |
| | 70 | NSNumber *seasonNum = [oldEp valueForKeyPath:@"season.seasonNumber"]; |
| | 71 | NSString *showName = [oldEp valueForKeyPath:@"tvShow.name"]; |
| | 72 | NSString *showPath = [oldEp valueForKeyPath:@"tvShow.showPath"]; |
| | 73 | |
| | 74 | SapphireSeason *season = [SapphireSeason season:[seasonNum intValue] forShow:showName withPath:showPath inContext:newMoc]; |
| | 75 | if(season == nil) |
| | 76 | continue; |
| | 77 | |
| | 78 | SapphireEpisode *newEp = [NSEntityDescription insertNewObjectForEntityForName:SapphireEpisodeName inManagedObjectContext:newMoc]; |
| | 79 | newEp.season = season; |
| | 80 | newEp.tvShow = season.tvShow; |
| | 81 | [newEp.filesSet setSet:newFiles]; |
| | 82 | |
| | 83 | NSEnumerator *subEpEnum = [[oldEp valueForKey:@"subEpisodes"] objectEnumerator]; |
| | 84 | NSManagedObject *subEp; |
| | 85 | while((subEp = [subEpEnum nextObject]) != nil) |
| | 86 | [SapphireSubEpisode upgradeV1SubEpisode:subEp toContext:newMoc inEpisode:newEp]; |
| | 87 | } |