Restore on-demand backward compatibility (#338)

In #333, the non-optional field `disconnectsIfNotMatching` was removed
completely. Therefore, downgrading from 2.2.0 may lose profiles due to
the missing required field.

Mitigate the issue by restoring the field as optional, even if it's
unused, for the sake of not breaking profile serialization until the
2.2.0 release. Remove the deprecated field after that.
This commit is contained in:
Davide De Rosa 2023-07-30 17:43:03 +02:00 committed by GitHub
parent db4c6094ea
commit c8abb245f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -49,6 +49,9 @@ extension Profile {
public var withOtherNetworks: Set<OtherNetwork> = [] public var withOtherNetworks: Set<OtherNetwork> = []
@available(*, deprecated, message: "Drop field after releasing as optional to the App Store")
public var disconnectsIfNotMatching: Bool? = true
public init() { public init() {
} }
} }

View File

@ -98,7 +98,12 @@ final class CDProfileRepository: ProfileRepository {
existing.forEach(context.delete) existing.forEach(context.delete)
try profiles.forEach { try profiles.forEach {
_ = try ProfileMapper(context).toDTO($0)
// FIXME: on-demand, workaround to retain profiles on downgrade (field is required before 2.2.0)
var copy = $0
copy.onDemand.disconnectsIfNotMatching = true
_ = try ProfileMapper(context).toDTO(copy)
} }
try context.save() try context.save()
} catch { } catch {