From 2009bfe84462c0f9017a0e984bc462d22b94f2b6 Mon Sep 17 00:00:00 2001 From: Alex Grebenyuk Date: Wed, 8 Oct 2025 13:49:09 -0400 Subject: [PATCH] Add Core Data Model 156 --- MIGRATIONS.md | 11 + .../WordPressKitObjC/MediaServiceRemoteREST.m | 1 + .../WordPressKitObjC/PostServiceRemoteREST.m | 2 + .../WordPressKitObjC/include/RemoteMedia.h | 1 + .../WordPressKitObjC/include/RemotePost.h | 2 + .../WordPressData/Objective-C/AbstractPost.m | 1 + Sources/WordPressData/Objective-C/Blog.m | 1 - Sources/WordPressData/Objective-C/Media.m | 1 + .../WordPressData/Objective-C/PostHelper.m | 4 + .../Objective-C/include/AbstractPost.h | 4 + .../WordPressData/Objective-C/include/Blog.h | 2 - .../WordPressData/Objective-C/include/Media.h | 1 + .../WordPress.xcdatamodeld/.xccurrentversion | 2 +- .../WordPress 156.xcdatamodel/contents | 884 ++++++++++++++++++ Sources/WordPressData/Swift/BlobEntity.swift | 7 - .../Swift/Post+CoreDataProperties.swift | 2 + .../Swift/PostHelper+Metadata.swift | 24 +- WordPress/Classes/Services/MediaHelper.swift | 4 +- 18 files changed, 938 insertions(+), 16 deletions(-) create mode 100644 Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress 156.xcdatamodel/contents delete mode 100644 Sources/WordPressData/Swift/BlobEntity.swift diff --git a/MIGRATIONS.md b/MIGRATIONS.md index 09b54f3fed43..e34863b794b3 100644 --- a/MIGRATIONS.md +++ b/MIGRATIONS.md @@ -3,6 +3,17 @@ This file documents changes in the data model. Please explain any changes to the data model as well as any custom migrations. +## WordPress 156 + +@kean 2025-10-08 + +- Remove unused `AbstactPost` properties: `metaIsLocal`, `metaPublishImmediatelly`, `statusAfterSync`, `confirmedChangesHash` +- Remove unused `Blog` properties: `rawBlockEditorSettings` +- Remove unused `BlobEntity` +- Add `metadata` field to `AbstractPost` +- Add `commentsStatus` and `pingsStatus` to `Post` +- Add `formattedSize` to `Media` + ## WordPress 155 @crazytonyli 2025-04-07 diff --git a/Modules/Sources/WordPressKitObjC/MediaServiceRemoteREST.m b/Modules/Sources/WordPressKitObjC/MediaServiceRemoteREST.m index df727fd40bee..0b20b1d5a118 100644 --- a/Modules/Sources/WordPressKitObjC/MediaServiceRemoteREST.m +++ b/Modules/Sources/WordPressKitObjC/MediaServiceRemoteREST.m @@ -412,6 +412,7 @@ + (RemoteMedia *)remoteMediaFromJSONDictionary:(NSDictionary *)jsonMedia remoteMedia.remoteThumbnailURL = [jsonMedia stringForKeyPath:@"thumbnails.fmt_std"]; remoteMedia.videopressGUID = [jsonMedia stringForKey:@"videopress_guid"]; remoteMedia.length = [jsonMedia numberForKey:@"length"]; + remoteMedia.formattedSize = [jsonMedia stringForKey:@"size"]; return remoteMedia; } diff --git a/Modules/Sources/WordPressKitObjC/PostServiceRemoteREST.m b/Modules/Sources/WordPressKitObjC/PostServiceRemoteREST.m index d8b967fe4a0c..2ac9412f889e 100644 --- a/Modules/Sources/WordPressKitObjC/PostServiceRemoteREST.m +++ b/Modules/Sources/WordPressKitObjC/PostServiceRemoteREST.m @@ -431,6 +431,8 @@ + (RemotePost *)remotePostFromJSONDictionary:(NSDictionary *)jsonPost { post.format = jsonPost[@"format"]; post.order = [jsonPost numberForKey:@"menu_order"].integerValue; + post.commentsStatus = [jsonPost stringForKeyPath:@"discussion.comment_status"]; + post.pingsStatus = [jsonPost stringForKeyPath:@"discussion.ping_status"]; post.commentCount = [jsonPost numberForKeyPath:@"discussion.comment_count"] ?: @0; post.likeCount = [jsonPost numberForKeyPath:@"like_count"] ?: @0; diff --git a/Modules/Sources/WordPressKitObjC/include/RemoteMedia.h b/Modules/Sources/WordPressKitObjC/include/RemoteMedia.h index a5f02f317c5d..cbe3520ad9f1 100644 --- a/Modules/Sources/WordPressKitObjC/include/RemoteMedia.h +++ b/Modules/Sources/WordPressKitObjC/include/RemoteMedia.h @@ -24,5 +24,6 @@ @property (nonatomic, strong, nullable) NSString *videopressGUID; @property (nonatomic, strong, nullable) NSNumber *length; @property (nonatomic, strong, nullable) NSString *remoteThumbnailURL; +@property (nonatomic, strong, nullable) NSString *formattedSize; @end diff --git a/Modules/Sources/WordPressKitObjC/include/RemotePost.h b/Modules/Sources/WordPressKitObjC/include/RemotePost.h index e74cee04301d..ea4766824f2d 100644 --- a/Modules/Sources/WordPressKitObjC/include/RemotePost.h +++ b/Modules/Sources/WordPressKitObjC/include/RemotePost.h @@ -45,6 +45,8 @@ extern NSString * const PostStatusDeleted; */ @property (nonatomic, strong) RemotePostAutosave *autosave; +@property (nonatomic, strong) NSString *commentsStatus; +@property (nonatomic, strong) NSString *pingsStatus; @property (nonatomic, strong) NSNumber *commentCount; @property (nonatomic, strong) NSNumber *likeCount; diff --git a/Sources/WordPressData/Objective-C/AbstractPost.m b/Sources/WordPressData/Objective-C/AbstractPost.m index 7f34f36528c6..1eb86f2e5dbc 100644 --- a/Sources/WordPressData/Objective-C/AbstractPost.m +++ b/Sources/WordPressData/Objective-C/AbstractPost.m @@ -23,6 +23,7 @@ @implementation AbstractPost @dynamic autosaveIdentifier; @dynamic foreignID; @dynamic order; +@dynamic rawMetadata; @synthesize voiceContent; #pragma mark - Life Cycle Methods diff --git a/Sources/WordPressData/Objective-C/Blog.m b/Sources/WordPressData/Objective-C/Blog.m index 7933b853b017..e246132c7d72 100644 --- a/Sources/WordPressData/Objective-C/Blog.m +++ b/Sources/WordPressData/Objective-C/Blog.m @@ -91,7 +91,6 @@ @implementation Blog @dynamic quotaSpaceUsed; @dynamic pageTemplateCategories; @dynamic publicizeInfo; -@dynamic rawBlockEditorSettings; @synthesize videoPressEnabled; @synthesize xmlrpcApi = _xmlrpcApi; diff --git a/Sources/WordPressData/Objective-C/Media.m b/Sources/WordPressData/Objective-C/Media.m index 73069c92d5a4..45fb6393000e 100644 --- a/Sources/WordPressData/Objective-C/Media.m +++ b/Sources/WordPressData/Objective-C/Media.m @@ -16,6 +16,7 @@ @implementation Media @dynamic height; @dynamic filename; @dynamic filesize; +@dynamic formattedSize; @dynamic creationDate; @dynamic blog; @dynamic posts; diff --git a/Sources/WordPressData/Objective-C/PostHelper.m b/Sources/WordPressData/Objective-C/PostHelper.m index 82d3d7c4bf43..8b18979d7f6b 100644 --- a/Sources/WordPressData/Objective-C/PostHelper.m +++ b/Sources/WordPressData/Objective-C/PostHelper.m @@ -57,6 +57,8 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost [self updateCommentsForPost:post]; } + post.rawMetadata = [PostHelper makeRawMetadataFrom:remotePost]; + post.autosaveTitle = remotePost.autosave.title; post.autosaveExcerpt = remotePost.autosave.excerpt; post.autosaveContent = remotePost.autosave.content; @@ -69,6 +71,8 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost pagePost.foreignID = remotePost.foreignID; } else if ([post isKindOfClass:[Post class]]) { Post *postPost = (Post *)post; + postPost.commentsStatus = remotePost.commentsStatus; + postPost.pingsStatus = remotePost.pingsStatus; postPost.commentCount = remotePost.commentCount; postPost.likeCount = remotePost.likeCount; postPost.postFormat = remotePost.format; diff --git a/Sources/WordPressData/Objective-C/include/AbstractPost.h b/Sources/WordPressData/Objective-C/include/AbstractPost.h index 304aa8f5e8bd..586746f23c79 100644 --- a/Sources/WordPressData/Objective-C/include/AbstractPost.h +++ b/Sources/WordPressData/Objective-C/include/AbstractPost.h @@ -53,6 +53,10 @@ typedef NS_ENUM(NSUInteger, AbstractPostRemoteStatus) { @property (nonatomic, strong, nullable) NSDate *confirmedChangesTimestamp; +/// Contains all the custom metadata associated with a post, including the +/// Jetpack plugin metadata.` +@property (nonatomic, strong, nullable) NSData *rawMetadata; + @property (nonatomic, strong, nullable) NSString *voiceContent; // Revision management diff --git a/Sources/WordPressData/Objective-C/include/Blog.h b/Sources/WordPressData/Objective-C/include/Blog.h index bb7e836f163b..37c2fc18cab2 100644 --- a/Sources/WordPressData/Objective-C/include/Blog.h +++ b/Sources/WordPressData/Objective-C/include/Blog.h @@ -17,7 +17,6 @@ NS_ASSUME_NONNULL_BEGIN @class SiteSuggestion; @class PageTemplateCategory; @class PublicizeInfo; -@class BlobEntity; @class PostCategory; @class PostTag; @class PublicizeConnection; @@ -179,7 +178,6 @@ typedef NS_ENUM(NSInteger, SiteVisibility) { @property (nonatomic, strong, readwrite, nullable) NSNumber *quotaSpaceAllowed; @property (nonatomic, strong, readwrite, nullable) NSNumber *quotaSpaceUsed; @property (nullable, nonatomic, retain) NSSet *pageTemplateCategories; -@property (nonatomic, strong, readwrite, nullable) BlobEntity *rawBlockEditorSettings __deprecated_msg("Use BlockEditorCache instead");; /** * @details Maps to a BlogSettings instance, which contains a collection of the available preferences, diff --git a/Sources/WordPressData/Objective-C/include/Media.h b/Sources/WordPressData/Objective-C/include/Media.h index f2881eb65bae..32eb04bb3a02 100644 --- a/Sources/WordPressData/Objective-C/include/Media.h +++ b/Sources/WordPressData/Objective-C/include/Media.h @@ -31,6 +31,7 @@ typedef NS_ENUM(NSUInteger, MediaType) { @property (nonatomic, strong, nullable) NSString *desc; @property (nonatomic, strong, nullable) NSString *filename; @property (nonatomic, strong, nullable) NSNumber *filesize; +@property (nonatomic, strong, nullable) NSString *formattedSize; @property (nonatomic, strong, nullable) NSNumber *height; @property (nonatomic, strong, nullable) NSNumber *length; @property (nonatomic, strong, nullable) NSString *localThumbnailIdentifier; diff --git a/Sources/WordPressData/Resources/WordPress.xcdatamodeld/.xccurrentversion b/Sources/WordPressData/Resources/WordPress.xcdatamodeld/.xccurrentversion index 80f88276341c..fc374e081fc8 100644 --- a/Sources/WordPressData/Resources/WordPress.xcdatamodeld/.xccurrentversion +++ b/Sources/WordPressData/Resources/WordPress.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - WordPress 155.xcdatamodel + WordPress 156.xcdatamodel diff --git a/Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress 156.xcdatamodel/contents b/Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress 156.xcdatamodel/contents new file mode 100644 index 000000000000..94ae04e73519 --- /dev/null +++ b/Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress 156.xcdatamodel/contents @@ -0,0 +1,884 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sources/WordPressData/Swift/BlobEntity.swift b/Sources/WordPressData/Swift/BlobEntity.swift deleted file mode 100644 index 9ccf55c70c2a..000000000000 --- a/Sources/WordPressData/Swift/BlobEntity.swift +++ /dev/null @@ -1,7 +0,0 @@ -import Foundation - -/// A data blob stored that uses external storage and is loaded on demand. -@objc(BlobEntity) -public final class BlobEntity: NSManagedObject { - @NSManaged public var data: Data -} diff --git a/Sources/WordPressData/Swift/Post+CoreDataProperties.swift b/Sources/WordPressData/Swift/Post+CoreDataProperties.swift index dbc45eb2d365..b7e0a9dad3cf 100644 --- a/Sources/WordPressData/Swift/Post+CoreDataProperties.swift +++ b/Sources/WordPressData/Swift/Post+CoreDataProperties.swift @@ -14,6 +14,8 @@ public extension Post { @NSManaged var tags: String? @NSManaged var categories: Set? @NSManaged var isStickyPost: Bool + @NSManaged var commentsStatus: String? + @NSManaged var pingsStatus: String? // If the post is created as an answer to a Blogging Prompt, the promptID is stored here. @NSManaged var bloggingPromptID: String? diff --git a/Sources/WordPressData/Swift/PostHelper+Metadata.swift b/Sources/WordPressData/Swift/PostHelper+Metadata.swift index 940a12682ed0..e35247478913 100644 --- a/Sources/WordPressData/Swift/PostHelper+Metadata.swift +++ b/Sources/WordPressData/Swift/PostHelper+Metadata.swift @@ -2,10 +2,26 @@ import Foundation import WordPressShared import WordPressKit -public extension PostHelper { - @objc static let foreignIDKey = "wp_jp_foreign_id" +extension PostHelper { + @objc public static let foreignIDKey = "wp_jp_foreign_id" - static func mapDictionaryToMetadataItems(_ dictionary: [String: Any]) -> RemotePostMetadataItem? { + @objc public static func makeRawMetadata(from post: RemotePost) -> Data? { + guard let metadata = post.metadata else { + return nil + } + guard JSONSerialization.isValidJSONObject(metadata) else { + wpAssertionFailure("metadata is not a valid JSON object") + return nil + } + do { + return try JSONSerialization.data(withJSONObject: metadata) + } catch { + wpAssertionFailure("failed to convert metadata to JSON", userInfo: ["error": "\(error)"]) + return nil + } + } + + public static func mapDictionaryToMetadataItems(_ dictionary: [String: Any]) -> RemotePostMetadataItem? { let id = dictionary["id"] return RemotePostMetadataItem( id: (id as? String) ?? (id as? NSNumber)?.stringValue, @@ -15,7 +31,7 @@ public extension PostHelper { } @objc(createOrUpdateCategoryForRemoteCategory:blog:context:) - class func createOrUpdateCategory(for remoteCategory: RemotePostCategory, in blog: Blog, in context: NSManagedObjectContext) -> PostCategory? { + public class func createOrUpdateCategory(for remoteCategory: RemotePostCategory, in blog: Blog, in context: NSManagedObjectContext) -> PostCategory? { guard let categoryID = remoteCategory.categoryID else { wpAssertionFailure("remote category missing categoryID") return nil diff --git a/WordPress/Classes/Services/MediaHelper.swift b/WordPress/Classes/Services/MediaHelper.swift index bd633f5c1728..7663505d2891 100644 --- a/WordPress/Classes/Services/MediaHelper.swift +++ b/WordPress/Classes/Services/MediaHelper.swift @@ -70,7 +70,9 @@ public class MediaHelper: NSObject { if media.error != nil { media.error = nil } - + if media.formattedSize != remoteMedia.formattedSize { + media.formattedSize = remoteMedia.formattedSize + } } }