From a5a324ed54bacdf6a5ac9954cdce6093f74ce5b5 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Wed, 3 Nov 2021 12:38:32 +0100 Subject: [PATCH] Fix migration from schema <= 12 to schema > 16. Issue #1282 Signed-off-by: N-Pex --- .../Store/MXRealmCryptoStore/MXRealmCryptoStore.m | 15 +++++++++------ changelog.d/1282.bugfix | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 changelog.d/1282.bugfix diff --git a/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m b/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m index 1f9faf2299..1edc5655ed 100644 --- a/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m +++ b/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m @@ -2143,12 +2143,15 @@ + (BOOL)finaliseMigrationWith:(RLMMigration *)migration oldSchemaVersion:(uint64 MXLogDebug(@"[MXRealmCryptoStore] Make sure MXRealmOlmAccount.cryptoVersion is MXCryptoVersion2"); [migration enumerateObjects:MXRealmOlmAccount.className block:^(RLMObject *oldObject, RLMObject *newObject) { - NSNumber *version; - MXJSONModelSetNumber(version, oldObject[@"cryptoVersion"]); - if (version && version.intValue == 0) - { - MXLogDebug(@"[MXRealmCryptoStore] -> Fix MXRealmOlmAccount.cryptoVersion"); - newObject[@"cryptoVersion"] = @(MXCryptoVersion2); + if (oldSchemaVersion > 12) { + // cryptoVersion available + NSNumber *version; + MXJSONModelSetNumber(version, oldObject[@"cryptoVersion"]); + if (version && version.intValue == 0) + { + MXLogDebug(@"[MXRealmCryptoStore] -> Fix MXRealmOlmAccount.cryptoVersion"); + newObject[@"cryptoVersion"] = @(MXCryptoVersion2); + } } }]; } diff --git a/changelog.d/1282.bugfix b/changelog.d/1282.bugfix new file mode 100644 index 0000000000..54d8f1387b --- /dev/null +++ b/changelog.d/1282.bugfix @@ -0,0 +1 @@ +MXRealmCryptoStore: fix migration from schema < 13 to schema > 16. \ No newline at end of file