commit 687ee6ba0769dffdaf1203af38ced7e269e67dbc
parent 318528df4da90723328b82a4b89cc2cd639001bc
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 2 Nov 2015 20:35:20 -0500
Fix sync error from items dragged between libraries before first sync
And fix bug in Zotero.URI.getURILibrary()
Diffstat:
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
@@ -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
@@ -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
@@ -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 () {