diff --git a/.env b/.env index f9b779a..e0747b8 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -CONTENTFUL_PERSISTENCE_VERSION=0.6.1 +CONTENTFUL_PERSISTENCE_VERSION=0.6.2 diff --git a/.envrc b/.envrc index 5dd60f5..5d5d851 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -export CONTENTFUL_PERSISTENCE_VERSION=0.6.1 +export CONTENTFUL_PERSISTENCE_VERSION=0.6.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b789e..1c6f15b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,20 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from #### 0.x Releases -- `0.6.x` Releases - [0.6.0](#060) | [0.6.1](#061) +- `0.6.x` Releases - [0.6.0](#060) | [0.6.1](#061) | [0.6.2](#062) - `0.5.x` Releases - [0.5.0](#050) - `0.4.x` Releases - [0.4.0](#040) --- +## [`0.6.2`](https://github.com/contentful/contentful-persistence.swift/releases/tag/0.6.2) +Released on 2017-09-20 + +#### Fixed +- Bug that caused `SynchronizationManager` to fail seeding a CoreData database from bundled content because of lack of localization context. + +--- + ## [`0.6.1`](https://github.com/contentful/contentful-persistence.swift/releases/tag/0.6.1) Released on 2017-09-08 diff --git a/Config.xcconfig b/Config.xcconfig index f9b779a..e0747b8 100644 --- a/Config.xcconfig +++ b/Config.xcconfig @@ -1 +1 @@ -CONTENTFUL_PERSISTENCE_VERSION=0.6.1 +CONTENTFUL_PERSISTENCE_VERSION=0.6.2 diff --git a/Sources/ContentfulPersistence/SynchronizationManager+SeedDB.swift b/Sources/ContentfulPersistence/SynchronizationManager+SeedDB.swift index 24b2db8..c0cf5da 100644 --- a/Sources/ContentfulPersistence/SynchronizationManager+SeedDB.swift +++ b/Sources/ContentfulPersistence/SynchronizationManager+SeedDB.swift @@ -27,11 +27,25 @@ public extension SynchronizationManager { var fileIndex = 0 let filePaths = bundle.paths(forResourcesOfType: "json", inDirectory: directory) + let spaceJSONFilePath = filePaths.filter({ URL(string: $0)?.deletingPathExtension().lastPathComponent == "space" }).first let firstFilePath = filePaths.filter({ URL(string: $0)?.deletingPathExtension().lastPathComponent == String(fileIndex) }).first - guard let initialSyncJSONFilePath = firstFilePath else { + + guard let initialSyncJSONFilePath = firstFilePath, let spaceFilePath = spaceJSONFilePath else { throw DatabaseSeedingError.invalidFilePath } + // Get the space first to give the client context. + guard let data = FileManager.default.contents(atPath: spaceFilePath) else { + let error = SDKError.invalidURL(string: spaceFilePath) + throw error + } + guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { + let error = SDKError.unparseableJSON(data: data, errorMessage: "Foundation.JSONSerialization failed") + throw error + } + + let map = Map(mappingType: .fromJSON, JSON: json) + let space = try Space(map: map) var filePath: String? = initialSyncJSONFilePath while let path = filePath { @@ -45,7 +59,7 @@ public extension SynchronizationManager { throw error } - let map = Map(mappingType: .fromJSON, JSON: json) + let map = Map(mappingType: .fromJSON, JSON: json, context: space.localizationContext) let syncSpace = try SyncSpace(map: map) self.update(with: syncSpace) diff --git a/Tests/ContentfulPersistenceTests/MultifilePreseedJSONFiles/space.json b/Tests/ContentfulPersistenceTests/MultifilePreseedJSONFiles/space.json new file mode 100644 index 0000000..02b6527 --- /dev/null +++ b/Tests/ContentfulPersistenceTests/MultifilePreseedJSONFiles/space.json @@ -0,0 +1,21 @@ +{ + "sys": { + "type": "Space", + "id": "smf0sqiu0c5s" + }, + "name": "Complex-Sync-Test-Space", + "locales": [ + { + "code": "en-US", + "default": true, + "name": "U.S. English", + "fallbackCode": null + }, + { + "code": "es-MX", + "default": false, + "name": "Spanish (Mexico)", + "fallbackCode": "en-US" + } + ] +} diff --git a/Tests/ContentfulPersistenceTests/PreseedJSONFiles/space.json b/Tests/ContentfulPersistenceTests/PreseedJSONFiles/space.json new file mode 100644 index 0000000..02b6527 --- /dev/null +++ b/Tests/ContentfulPersistenceTests/PreseedJSONFiles/space.json @@ -0,0 +1,21 @@ +{ + "sys": { + "type": "Space", + "id": "smf0sqiu0c5s" + }, + "name": "Complex-Sync-Test-Space", + "locales": [ + { + "code": "en-US", + "default": true, + "name": "U.S. English", + "fallbackCode": null + }, + { + "code": "es-MX", + "default": false, + "name": "Spanish (Mexico)", + "fallbackCode": "en-US" + } + ] +}