From 1830ee9fd25c770699995a1db62dadd4949dc302 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 2 Dec 2017 15:18:15 +0000 Subject: [PATCH] All: Fixed sync issue and database migration issue --- ReactNativeClient/lib/joplin-database.js | 4 +++- ReactNativeClient/lib/synchronizer.js | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ReactNativeClient/lib/joplin-database.js b/ReactNativeClient/lib/joplin-database.js index b47ba5183..e6407d8f3 100644 --- a/ReactNativeClient/lib/joplin-database.js +++ b/ReactNativeClient/lib/joplin-database.js @@ -205,7 +205,9 @@ class JoplinDatabase extends Database { const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7]; let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion); - if (currentVersionIndex == existingDatabaseVersions.length - 1) return false; + // currentVersionIndex < 0 if for the case where an old version of Joplin used with a newer + // version of the database, so that migration is not run in this case. + if (currentVersionIndex == existingDatabaseVersions.length - 1 || currentVersionIndex < 0) return false; while (currentVersionIndex < existingDatabaseVersions.length - 1) { const targetVersion = existingDatabaseVersions[currentVersionIndex + 1]; diff --git a/ReactNativeClient/lib/synchronizer.js b/ReactNativeClient/lib/synchronizer.js index 2d2384630..c70bbe5dc 100644 --- a/ReactNativeClient/lib/synchronizer.js +++ b/ReactNativeClient/lib/synchronizer.js @@ -421,10 +421,13 @@ class Synchronizer { let ItemClass = BaseItem.itemClass(content); content = ItemClass.filter(content); + if (!content.user_updated_time) content.user_updated_time = content.updated_time; + if (!content.user_created_time) content.user_created_time = content.created_time; + let newContent = null; if (action === 'createLocal') { - newContent = Object.assign({}, content); + newContent = Object.assign({}, content); } else if (action === 'updateLocal') { newContent = BaseModel.diffObjects(local, content); newContent.type_ = content.type_; @@ -445,9 +448,6 @@ class Synchronizer { await this.api().get(remoteResourceContentPath, { path: localResourceContentPath, target: 'file' }); } - if (!newContent.user_updated_time) newContent.user_updated_time = newContent.updated_time; - if (!newContent.user_created_time) newContent.user_created_time = newContent.created_time; - await ItemClass.save(newContent, options); } else if (action == 'deleteLocal') {