MLFileEntityMappingPolicy_2_5_to_2_6.m 1.36 KB
Newer Older
1
/*****************************************************************************
2
 * MLFileEntityMappingPolicy_2_5_to_2_6.m
3 4 5 6 7 8 9 10 11 12
 * MobileMediaLibraryKit
 *****************************************************************************
 * Copyright (c) 2015 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Tobias Conradi <videolan # tobias-conradi.de>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

13
#import "MLFileEntityMappingPolicy_2_5_to_2_6.h"
14

15
@implementation MLFileEntityMappingPolicy_2_5_to_2_6
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
{
    NSString *fullPath = [sInstance primitiveValueForKey:@"url"];
    NSString *relativePath = [self relativePathForFullPath:fullPath];
    if (relativePath) {
        [sInstance setPrimitiveValue:relativePath forKey:@"url"];
    }
    BOOL success = [super createDestinationInstancesForSourceInstance:sInstance entityMapping:mapping manager:manager error:error];
    return success;
}

- (NSString *)relativePathForFullPath:(NSString *)fullPath
{
    NSArray *components = [fullPath componentsSeparatedByString:@"Documents"];
    return [components.lastObject stringByRemovingPercentEncoding];
}

@end