Skip to content

Commit 8f2143f

Browse files
keanmokagio
authored andcommitted
Fix WordPressData runtime issues (#24494)
* Move remaining types to WordPressData * Use Current Module for Swift-only types * Fix ReaderTeamTopic compilation * Add missing class names * Remove unused SiteInfo * Add Bundle.wordPressData and update DataMigratorTests * Update CoreDataMigrationTests * Fix unit tests (AppEnvironment required)
1 parent 2a45fbf commit 8f2143f

27 files changed

+95
-85
lines changed

Sources/WordPressData/Resources/WordPress.xcdatamodeld/WordPress 155.xcdatamodel/contents

+20-20
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<fetchIndexElement property="blogs" type="Binary" order="ascending"/>
5656
</fetchIndex>
5757
</entity>
58-
<entity name="AccountSettings" representedClassName="ManagedAccountSettings" syncable="YES">
58+
<entity name="AccountSettings" representedClassName=".ManagedAccountSettings" syncable="YES">
5959
<attribute name="aboutMe" attributeType="String" syncable="YES"/>
6060
<attribute name="blockEmailNotifications" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
6161
<attribute name="displayName" attributeType="String" syncable="YES"/>
@@ -210,7 +210,7 @@
210210
</fetchIndex>
211211
<userInfo/>
212212
</entity>
213-
<entity name="BlogAuthor" representedClassName="BlogAuthor" syncable="YES">
213+
<entity name="BlogAuthor" representedClassName=".BlogAuthor" syncable="YES">
214214
<attribute name="avatarURL" optional="YES" attributeType="String" syncable="YES"/>
215215
<attribute name="deletedFromBlog" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
216216
<attribute name="displayName" optional="YES" attributeType="String" syncable="YES"/>
@@ -221,7 +221,7 @@
221221
<attribute name="username" optional="YES" attributeType="String" syncable="YES"/>
222222
<relationship name="blog" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Blog" inverseName="authors" inverseEntity="Blog" syncable="YES"/>
223223
</entity>
224-
<entity name="BloggingPrompt" representedClassName="BloggingPrompt" syncable="YES">
224+
<entity name="BloggingPrompt" representedClassName=".BloggingPrompt" syncable="YES">
225225
<attribute name="additionalPostTags" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromData" customClassName="[String]" syncable="YES"/>
226226
<attribute name="answerCount" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
227227
<attribute name="answered" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
@@ -232,15 +232,15 @@
232232
<attribute name="siteID" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
233233
<attribute name="text" attributeType="String" defaultValueString="" syncable="YES"/>
234234
</entity>
235-
<entity name="BloggingPromptSettings" representedClassName="BloggingPromptSettings" syncable="YES">
235+
<entity name="BloggingPromptSettings" representedClassName=".BloggingPromptSettings" syncable="YES">
236236
<attribute name="isPotentialBloggingSite" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
237237
<attribute name="promptCardEnabled" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES" syncable="YES"/>
238238
<attribute name="promptRemindersEnabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
239239
<attribute name="reminderTime" attributeType="String" defaultValueString="" syncable="YES"/>
240240
<attribute name="siteID" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
241241
<relationship name="reminderDays" maxCount="1" deletionRule="Cascade" destinationEntity="BloggingPromptSettingsReminderDays" inverseName="settings" inverseEntity="BloggingPromptSettingsReminderDays" syncable="YES"/>
242242
</entity>
243-
<entity name="BloggingPromptSettingsReminderDays" representedClassName="BloggingPromptSettingsReminderDays" syncable="YES">
243+
<entity name="BloggingPromptSettingsReminderDays" representedClassName=".BloggingPromptSettingsReminderDays" syncable="YES">
244244
<attribute name="friday" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
245245
<attribute name="monday" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
246246
<attribute name="saturday" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
@@ -250,7 +250,7 @@
250250
<attribute name="wednesday" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
251251
<relationship name="settings" maxCount="1" deletionRule="Cascade" destinationEntity="BloggingPromptSettings" inverseName="reminderDays" inverseEntity="BloggingPromptSettings" syncable="YES"/>
252252
</entity>
253-
<entity name="BlogSettings" representedClassName="BlogSettings" syncable="YES">
253+
<entity name="BlogSettings" representedClassName=".BlogSettings" syncable="YES">
254254
<attribute name="ampEnabled" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
255255
<attribute name="ampSupported" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
256256
<attribute name="commentsAllowed" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
@@ -351,19 +351,19 @@
351351
</fetchIndex>
352352
<userInfo/>
353353
</entity>
354-
<entity name="DiffAbstractValue" representedClassName="DiffAbstractValue" isAbstract="YES" syncable="YES">
354+
<entity name="DiffAbstractValue" representedClassName=".DiffAbstractValue" isAbstract="YES" syncable="YES">
355355
<attribute name="diffOperation" optional="YES" attributeType="String" syncable="YES"/>
356356
<attribute name="diffType" optional="YES" attributeType="String" syncable="YES"/>
357357
<attribute name="index" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
358358
<attribute name="value" optional="YES" attributeType="String" syncable="YES"/>
359359
</entity>
360-
<entity name="DiffContentValue" representedClassName="DiffContentValue" parentEntity="DiffAbstractValue" syncable="YES">
360+
<entity name="DiffContentValue" representedClassName=".DiffContentValue" parentEntity="DiffAbstractValue" syncable="YES">
361361
<relationship name="revisionDiff" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="RevisionDiff" inverseName="contentDiffs" inverseEntity="RevisionDiff" syncable="YES"/>
362362
</entity>
363-
<entity name="DiffTitleValue" representedClassName="DiffTitleValue" parentEntity="DiffAbstractValue" syncable="YES">
363+
<entity name="DiffTitleValue" representedClassName=".DiffTitleValue" parentEntity="DiffAbstractValue" syncable="YES">
364364
<relationship name="revisionDiff" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="RevisionDiff" inverseName="titleDiffs" inverseEntity="RevisionDiff" syncable="YES"/>
365365
</entity>
366-
<entity name="Domain" representedClassName="ManagedDomain" syncable="YES">
366+
<entity name="Domain" representedClassName=".ManagedDomain" syncable="YES">
367367
<attribute name="autoRenewalDate" optional="YES" attributeType="String" syncable="YES"/>
368368
<attribute name="autoRenewing" optional="YES" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
369369
<attribute name="domainName" optional="YES" attributeType="String" syncable="YES"/>
@@ -512,7 +512,7 @@
512512
<attribute name="title" optional="YES" attributeType="String" syncable="YES"/>
513513
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PageTemplateCategory" inverseName="layouts" inverseEntity="PageTemplateCategory" syncable="YES"/>
514514
</entity>
515-
<entity name="Person" representedClassName="ManagedPerson" syncable="YES">
515+
<entity name="Person" representedClassName=".ManagedPerson" syncable="YES">
516516
<attribute name="avatarURL" optional="YES" attributeType="String" syncable="YES"/>
517517
<attribute name="creationDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
518518
<attribute name="displayName" attributeType="String" syncable="YES"/>
@@ -526,7 +526,7 @@
526526
<attribute name="userID" attributeType="Integer 64" usesScalarValueType="NO" syncable="YES"/>
527527
<attribute name="username" attributeType="String" syncable="YES"/>
528528
</entity>
529-
<entity name="Plan" representedClassName="Plan" syncable="YES">
529+
<entity name="Plan" representedClassName=".Plan" syncable="YES">
530530
<attribute name="features" attributeType="String" syncable="YES"/>
531531
<attribute name="groups" attributeType="String" syncable="YES"/>
532532
<attribute name="icon" attributeType="String" syncable="YES"/>
@@ -540,12 +540,12 @@
540540
<attribute name="supportPriority" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
541541
<attribute name="tagline" attributeType="String" syncable="YES"/>
542542
</entity>
543-
<entity name="PlanFeature" representedClassName="PlanFeature" syncable="YES">
543+
<entity name="PlanFeature" representedClassName=".PlanFeature" syncable="YES">
544544
<attribute name="slug" attributeType="String" syncable="YES"/>
545545
<attribute name="summary" attributeType="String" syncable="YES"/>
546546
<attribute name="title" attributeType="String" syncable="YES"/>
547547
</entity>
548-
<entity name="PlanGroup" representedClassName="PlanGroup" syncable="YES">
548+
<entity name="PlanGroup" representedClassName=".PlanGroup" syncable="YES">
549549
<attribute name="name" attributeType="String" syncable="YES"/>
550550
<attribute name="order" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
551551
<attribute name="slug" attributeType="String" syncable="YES"/>
@@ -583,7 +583,7 @@
583583
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
584584
<relationship name="blog" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Blog" inverseName="postTypes" inverseEntity="Blog" syncable="YES"/>
585585
</entity>
586-
<entity name="PublicizeConnection" representedClassName="PublicizeConnection" syncable="YES">
586+
<entity name="PublicizeConnection" representedClassName=".PublicizeConnection" syncable="YES">
587587
<attribute name="connectionID" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
588588
<attribute name="dateExpires" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
589589
<attribute name="dateIssued" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
@@ -611,7 +611,7 @@
611611
<attribute name="toBePublicizedCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
612612
<relationship name="blog" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Blog" inverseName="publicizeInfo" inverseEntity="Blog"/>
613613
</entity>
614-
<entity name="PublicizeService" representedClassName="PublicizeService" syncable="YES">
614+
<entity name="PublicizeService" representedClassName=".PublicizeService" syncable="YES">
615615
<attribute name="connectURL" optional="YES" attributeType="String" syncable="YES"/>
616616
<attribute name="detail" optional="YES" attributeType="String" syncable="YES"/>
617617
<attribute name="externalUsersOnly" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
@@ -648,7 +648,7 @@
648648
<fetchIndexElement property="path" type="Binary" order="ascending"/>
649649
</fetchIndex>
650650
</entity>
651-
<entity name="ReaderCard" representedClassName="ReaderCard" syncable="YES">
651+
<entity name="ReaderCard" representedClassName=".ReaderCard" syncable="YES">
652652
<attribute name="sortRank" attributeType="Double" defaultValueString="0.0" usesScalarValueType="NO" syncable="YES"/>
653653
<relationship name="post" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="ReaderPost" inverseName="card" inverseEntity="ReaderPost" syncable="YES"/>
654654
<relationship name="sites" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="ReaderSiteTopic" inverseName="cards" inverseEntity="ReaderSiteTopic" syncable="YES"/>
@@ -794,7 +794,7 @@
794794
<attribute name="organizationID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
795795
<attribute name="slug" optional="YES" attributeType="String" syncable="YES"/>
796796
</entity>
797-
<entity name="Revision" representedClassName="Revision" syncable="YES">
797+
<entity name="Revision" representedClassName=".Revision" syncable="YES">
798798
<attribute name="postAuthorId" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
799799
<attribute name="postContent" optional="YES" attributeType="String" syncable="YES"/>
800800
<attribute name="postDateGmt" optional="YES" attributeType="String" syncable="YES"/>
@@ -806,7 +806,7 @@
806806
<attribute name="siteId" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
807807
<relationship name="diff" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="RevisionDiff" inverseName="revision" inverseEntity="RevisionDiff" syncable="YES"/>
808808
</entity>
809-
<entity name="RevisionDiff" representedClassName="RevisionDiff" syncable="YES">
809+
<entity name="RevisionDiff" representedClassName=".RevisionDiff" syncable="YES">
810810
<attribute name="fromRevisionId" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
811811
<attribute name="toRevisionId" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
812812
<attribute name="totalAdditions" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
@@ -815,7 +815,7 @@
815815
<relationship name="revision" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Revision" inverseName="diff" inverseEntity="Revision" syncable="YES"/>
816816
<relationship name="titleDiffs" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="DiffTitleValue" inverseName="revisionDiff" inverseEntity="DiffTitleValue" syncable="YES"/>
817817
</entity>
818-
<entity name="Role" representedClassName="Role" syncable="YES">
818+
<entity name="Role" representedClassName=".Role" syncable="YES">
819819
<attribute name="name" attributeType="String" syncable="YES"/>
820820
<attribute name="order" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
821821
<attribute name="slug" attributeType="String" syncable="YES"/>

WordPress/Classes/Utility/Environment/AppEnvironment.swift renamed to Sources/WordPressData/Swift/AppEnvironment.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import Foundation
22
import WordPressKit
33

4-
/// A collection of global variables and singletons that the app wants access to.
5-
///
6-
struct AppEnvironment {
4+
/// - warning: Soft-deprecated.
5+
public struct AppEnvironment {
76

87
// MARK: - Globals
98

109
/// A type to create derived context, save context, etc...
11-
let contextManager: CoreDataStackSwift
10+
public let contextManager: CoreDataStackSwift
1211

1312
/// The base url to use for WP.com api requests
14-
let wordPressComApiBase: URL
13+
public let wordPressComApiBase: URL
1514

1615
/// The mainContext that has concurrency type NSMainQueueConcurrencyType and should be used
1716
/// for UI elements and fetched results controllers.
18-
var mainContext: NSManagedObjectContext {
17+
public var mainContext: NSManagedObjectContext {
1918
return contextManager.mainContext
2019
}
2120

2221
// MARK: - Static current environment implementation
2322

2423
/// The current environment. Use this to access the app globals.
2524
///
26-
static private(set) var current = AppEnvironment()
25+
public static private(set) var current = AppEnvironment()
2726

2827
// MARK: - Initialization
2928

@@ -40,7 +39,7 @@ extension AppEnvironment {
4039
/// Creates a new Environment, changing just a subset of the current global dependencies.
4140
///
4241
@discardableResult
43-
static func replaceEnvironment(
42+
public static func replaceEnvironment(
4443
contextManager: CoreDataStackSwift = AppEnvironment.current.contextManager,
4544
wordPressComApiBase: URL = AppEnvironment.current.wordPressComApiBase) -> AppEnvironment {
4645

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
extension Bundle {
4+
@objc public class var wordPressData: Bundle {
5+
Bundle(for: BundleToken.self)
6+
}
7+
}
8+
9+
private final class BundleToken {}

Sources/WordPressData/Swift/ContextManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class ContextManager: NSObject, CoreDataStack, CoreDataStackSwift {
155155

156156
DDLogWarn("Migration required for persistent store.")
157157

158-
guard let modelFileURL = Bundle(for: ContextManager.self).url(forResource: "WordPress", withExtension: "momd") else {
158+
guard let modelFileURL = Bundle.wordPressData.url(forResource: "WordPress", withExtension: "momd") else {
159159
fatalError("Can't find WordPress.momd")
160160
}
161161

@@ -222,7 +222,7 @@ private extension ContextManager {
222222

223223
private extension ContextManager {
224224
static func createPersistentContainer(storeURL: URL, modelName: String) -> NSPersistentContainer {
225-
guard var modelFileURL = Bundle(for: ContextManager.self).url(forResource: "WordPress", withExtension: "momd") else {
225+
guard var modelFileURL = Bundle.wordPressData.url(forResource: "WordPress", withExtension: "momd") else {
226226
fatalError("Can't find WordPress.momd")
227227
}
228228

Sources/WordPressData/Swift/CoreDataHelper.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public extension CoreDataStack {
358358
}
359359

360360
private func migrateDatabaseIfNecessary(at databaseLocation: URL) throws {
361-
guard let modelFileURL = Bundle(for: ContextManager.self).url(forResource: "WordPress", withExtension: "momd"),
361+
guard let modelFileURL = Bundle.wordPressData.url(forResource: "WordPress", withExtension: "momd"),
362362
let objectModel = NSManagedObjectModel(contentsOf: modelFileURL) else {
363363
return
364364
}

Sources/WordPressData/Swift/CoreDataIterativeMigrator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private extension CoreDataIterativeMigrator {
263263
}
264264

265265
static func model(for metadata: [String: Any]) throws -> NSManagedObjectModel? {
266-
let bundle = Bundle(for: ContextManager.self)
266+
let bundle = Bundle.wordPressData
267267
guard let sourceModel = NSManagedObjectModel.mergedModel(from: [bundle], forStoreMetadata: metadata) else {
268268
let description = "Failed to find source model for metadata: \(metadata)"
269269
throw error(with: .noSourceModelForMetadata, description: description)
@@ -287,7 +287,7 @@ private extension CoreDataIterativeMigrator {
287287
}
288288

289289
static func urlForModel(name: String, in directory: String?) -> URL? {
290-
let bundle = Bundle(for: ContextManager.self)
290+
let bundle = Bundle.wordPressData
291291
var url = bundle.url(forResource: name, withExtension: "mom", subdirectory: directory)
292292

293293
if url != nil {

Sources/WordPressData/Swift/PublicizeInfo+CoreDataClass.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import WordPressKit
88
/// Furthermore, sites eligible for unlimited sharing will still return a `PublicizeInfo` along with its sharing
99
/// limitations, but the numbers should be ignored (at least for now).
1010
///
11-
@objc public class PublicizeInfo: NSManagedObject {
11+
@objc(PublicizeInfo)
12+
public class PublicizeInfo: NSManagedObject {
1213

1314
public var sharingLimit: SharingLimit {
1415
SharingLimit(remaining: Int(sharesRemaining), limit: Int(shareLimit))

Sources/WordPressData/Swift/ReaderAbstractTopic.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Foundation
22
import CoreData
33

4-
@objc open class ReaderAbstractTopic: NSManagedObject {
4+
@objc(ReaderAbstractTopic)
5+
open class ReaderAbstractTopic: NSManagedObject {
56
// Relations
67
@NSManaged open var posts: [ReaderPost]
78

Sources/WordPressData/Swift/ReaderCrossPostMeta.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Foundation
22
import CoreData
33

4-
@objc open class ReaderCrossPostMeta: NSManagedObject {
4+
@objc(ReaderCrossPostMeta)
5+
open class ReaderCrossPostMeta: NSManagedObject {
56
// Relations
67
@NSManaged open var post: ReaderPost
78

WordPress/Classes/Models/ReaderDefaultTopic.swift renamed to Sources/WordPressData/Swift/ReaderDefaultTopic.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22

3-
@objc open class ReaderDefaultTopic: ReaderAbstractTopic {
3+
@objc(ReaderDefaultTopic)
4+
open class ReaderDefaultTopic: ReaderAbstractTopic {
45
override open class var TopicType: String {
56
return "default"
67
}

WordPress/Classes/Models/ReaderListTopic.swift renamed to Sources/WordPressData/Swift/ReaderListTopic.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22

3-
@objc open class ReaderListTopic: ReaderAbstractTopic {
3+
@objc(ReaderListTopic)
4+
open class ReaderListTopic: ReaderAbstractTopic {
45
@NSManaged open var isOwner: Bool
56
@NSManaged open var isPublic: Bool
67
@NSManaged open var listDescription: String

0 commit comments

Comments
 (0)