From 687ee6ba0769dffdaf1203af38ced7e269e67dbc Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 2 Nov 2015 20:35:20 -0500 Subject: [PATCH] Fix sync error from items dragged between libraries before first sync And fix bug in Zotero.URI.getURILibrary() --- .../content/zotero/xpcom/sync/syncRunner.js | 9 ++++---- chrome/content/zotero/xpcom/uri.js | 2 +- test/tests/syncRunnerTest.js | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index b86204a6e5..10e80342f5 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -486,8 +486,6 @@ Zotero.Sync.Runner_Module = function (options = {}) { yield Zotero.DB.executeTransaction(function* () { if (lastUserID != userID) { - yield Zotero.Users.setCurrentUserID(userID); - if (lastUserID) { // Delete all local groups if changing users for (let group of groups) { @@ -495,14 +493,15 @@ Zotero.Sync.Runner_Module = function (options = {}) { } // Update relations pointing to the old library to point to this one - yield Zotero.Relations.updateUser(lastUserID, userID); + yield Zotero.Relations.updateUser(userID); } // Replace local user key with libraryID, in case duplicates were // merged before the first sync else { - let repl = "local/" + Zotero.Users.getLocalUserKey(); - yield Zotero.Relations.updateUser(repl, userID); + yield Zotero.Relations.updateUser(userID); } + + yield Zotero.Users.setCurrentUserID(userID); } if (lastUsername != username) { diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index ca2629da12..a0b7e784a6 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -262,7 +262,7 @@ Zotero.URI = new function () { */ this.getURILibrary = function (libraryURI) { let library = this._getURIObjectLibrary(libraryURI); - return libraryID ? library.libraryID : false; + return library ? library.id : false; } diff --git a/test/tests/syncRunnerTest.js b/test/tests/syncRunnerTest.js index 8318655d4c..4043c6c573 100644 --- a/test/tests/syncRunnerTest.js +++ b/test/tests/syncRunnerTest.js @@ -439,6 +439,28 @@ describe("Zotero.Sync.Runner", function () { assert.equal(Zotero.Users.getCurrentUserID(), 1); assert.equal(Zotero.Users.getCurrentUsername(), "A"); }) + + it("should update local relations when syncing for the first time", function* () { + yield resetDB({ + thisArg: this, + skipBundledFiles: true + }); + + var item1 = yield createDataObject('item'); + var item2 = yield createDataObject( + 'item', { libraryID: Zotero.Libraries.publicationsLibraryID } + ); + + yield item1.addLinkedItem(item2); + + var cont = yield runner.checkUser(1, "A"); + assert.isTrue(cont); + + var json = yield item1.toJSON(); + var uri = json.relations[Zotero.Relations.linkedObjectPredicate][0]; + assert.notInclude(uri, 'users/local'); + assert.include(uri, 'users/1/publications'); + }) }) describe("#sync()", function () {