-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds "meta" properties to act as sorting helpers for post/pages.
Adds a core data revision: 31 Adds a new migration mapping and entity migration policy.
- Loading branch information
Showing
9 changed files
with
1,687 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <CoreData/CoreData.h> | ||
|
||
@interface PostToPost30To31 : NSEntityMigrationPolicy | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#import "PostToPost30To31.h" | ||
#import "AbstractPost.h" | ||
|
||
@implementation PostToPost30To31 | ||
|
||
- (BOOL)beginEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error | ||
{ | ||
DDLogInfo(@"%@ %@ (%@ -> %@)", self, NSStringFromSelector(_cmd), [mapping sourceEntityName], [mapping destinationEntityName]); | ||
return YES; | ||
} | ||
|
||
|
||
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sourceInstance | ||
entityMapping:(NSEntityMapping *)mapping | ||
manager:(NSMigrationManager *)manager | ||
error:(NSError *__autoreleasing *)error | ||
{ | ||
NSMutableArray *sourceKeys = [sourceInstance.entity.attributesByName.allKeys mutableCopy]; | ||
NSDictionary *sourceValues = [sourceInstance dictionaryWithValuesForKeys:sourceKeys]; | ||
NSManagedObject *destinationInstance = [NSEntityDescription insertNewObjectForEntityForName:mapping.destinationEntityName | ||
inManagedObjectContext:manager.destinationContext]; | ||
NSArray *destinationKeys = destinationInstance.entity.attributesByName.allKeys; | ||
for (NSString *key in destinationKeys) { | ||
id value = [sourceValues valueForKey:key]; | ||
// Avoid NULL values | ||
if (value && ![value isEqual:[NSNull null]]) { | ||
[destinationInstance setValue:value forKey:key]; | ||
} | ||
} | ||
|
||
// Sets the new meta publish immediately property value. | ||
id value = [sourceInstance valueForKey:@"date_created_gmt"]; | ||
id metaValue = (!value || [value isEqual:[NSNull null]]) ? @YES : @NO; | ||
[destinationInstance setValue:metaValue forKey:@"metaPublishImmediately"]; | ||
|
||
// Sets the new meta is local property value. | ||
value = [sourceInstance valueForKey:@"remoteStatusNumber"]; | ||
metaValue = [value isEqualToNumber:@2]? @YES : @NO; | ||
[destinationInstance setValue:@YES forKey:@"metaIsLocal"]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
[manager associateSourceInstance:sourceInstance | ||
withDestinationInstance:destinationInstance | ||
forEntityMapping:mapping]; | ||
return YES; | ||
} | ||
|
||
- (BOOL)endEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError *__autoreleasing *)error | ||
{ | ||
DDLogInfo(@"%@ %@ (%@ -> %@)", self, NSStringFromSelector(_cmd), [mapping sourceEntityName], [mapping destinationEntityName]); | ||
return YES; | ||
} | ||
|
||
|
||
@end |
1,165 changes: 1,165 additions & 0 deletions
1,165
WordPress/Classes/Utility/Migrations/WordPress-30-31.xcmappingmodel/xcmapping.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I think that
@YES
was meant to bemetaValue