Show
Ignore:
Timestamp:
01/08/09 21:03:22 (3 years ago)
Author:
gbooker
Message:

Switched the the next version of the metadata.
Fixes #264

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/CoreData/SapphireFrappliance/MetaData/SapphireMObjects/SapphireEpisode.m

    r732 r734  
    88#import "SapphireXMLData.h" 
    99#import "SapphireApplianceController.h" 
     10#import "CoreDataSupportFunctions.h" 
    1011 
    1112@implementation SapphireEpisode 
     
    4546        [ret addSubEpisodesObject:[SapphireSubEpisode createSubEpisodeTitle:title inEpisode:ret]]; 
    4647        return ret; 
     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        } 
    4788} 
    4889