Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(upgradeNeeded) {
- NSManagedObjectModel *sourceModel = [NSManagedObjectModel mergedModelFromBundles:VUIModelBundles() orStoreMetadata:meta];
- if(sourceModel == nil) {
- *error = [NSError errorWithDomain:VUIErrorDomainn ode:VUICoreDataErrorCode localizedReason:BWLocalizedString(@"Unable to find original data model for project.")];
- return NO;
- }
- NSManagedObjectModel *destinationModel = [self managedObjectModel];
- NSMigrationManager *migrationManager = [[NSMigrationManager alloc] initWithSourceModel:sourceModel destinationModel:destinationModel];
- NSMappingModel *mappingModel = [NSMappingModel mappingModelFromBundles:VUIModelBundles() forSourceModel:sourceModel destinationModel:destinationModel];
- if(mappingModel == nil) {
- *error = [NSError errorWithDomain:VUIErrorDomain code:VUICoreDataErrorCode localizedReason:BWLocalizedString(@"Unable to find mapping model to convert project to most recent project format.")];
- return NO;
- }
- @try {
- //move file to backup
- NSAssert([url isFileURL], @"store url is not a file URL");
- NSString *tmpPath = [NSString tempFilePath];
- id storeType = [meta objectForKey:NSStoreTypeKey];
- if(![migrationManager migrateStoreFromURL:url
- type:storeType
- options:storeOptions
- withMappingModel:mappingModel
- toDestinationURL:[NSURLfileURLWithPath:tmpPath]
- destinationType:storeType
- destinationOptions:storeOptions
- error:error]) {
- return NO;
- } else {
- //replace old with new
- if(![[NSFileManager defaultManager] removeItemAtPath:[url path] error:error] ||
- ![[NSFileManager defaultManager] moveItemAtPath:tmpPath toPath:[url path] error:error]) {
- return NO;
- }
- // update document file modification date to prevent warning (#292)
- NSDate *newModificationDate = [[[NSFileManager defaultManager] fileAttributesAtPath:[url path] traverseLink:NO] bjectForKey:NSFileModificationDate];
- [self setFileModificationDate:newModificationDate];
- }
- }
- @finally {
- [migrationManager release];
- }
- }
- }
- return [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:storeOptions error:error];
Add Comment
Please, Sign In to add comment