Fix sync error from items dragged between libraries before first sync

And fix bug in Zotero.URI.getURILibrary()
This commit is contained in:
Dan Stillman 2015-11-02 20:35:20 -05:00
parent 318528df4d
commit 687ee6ba07
3 changed files with 27 additions and 6 deletions

View file

@ -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) {

View file

@ -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;
}

View file

@ -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 () {