Update relations using local user key when first setting sync user
In case items are merged before the first sync
This commit is contained in:
parent
ba91a2ea52
commit
0d8643087a
4 changed files with 30 additions and 4 deletions
|
@ -165,14 +165,14 @@ Zotero.Relations = new function () {
|
|||
};
|
||||
|
||||
|
||||
this.updateUser = Zotero.Promise.coroutine(function* (toUserID) {
|
||||
var fromUserID = Zotero.Users.getCurrentUserID();
|
||||
this.updateUser = Zotero.Promise.coroutine(function* (fromUserID, toUserID) {
|
||||
if (!fromUserID) {
|
||||
fromUserID = "local/" + Zotero.Users.getLocalUserKey();
|
||||
}
|
||||
if (!toUserID) {
|
||||
throw new Error("Invalid target userID " + toUserID);
|
||||
}
|
||||
|
||||
Zotero.DB.requireTransaction();
|
||||
for (let type of _types) {
|
||||
let sql = `SELECT DISTINCT object FROM ${type}Relations WHERE object LIKE ?`;
|
||||
|
|
|
@ -169,6 +169,10 @@ Zotero.Sync.Data.Local = {
|
|||
}
|
||||
if (!lastUserID) {
|
||||
yield Zotero.Users.setCurrentUserID(userID);
|
||||
|
||||
// Replace local user key with libraryID, in case duplicates were merged before the
|
||||
// first sync
|
||||
yield Zotero.Relations.updateUser(null, userID);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ describe("Zotero.Relations", function () {
|
|||
assert.include(rels[0], "/users/local");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(1);
|
||||
yield Zotero.Relations.updateUser(null, 1);
|
||||
})
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
|
@ -57,7 +57,7 @@ describe("Zotero.Relations", function () {
|
|||
assert.include(rels[0], "/users/1");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(2);
|
||||
yield Zotero.Relations.updateUser(1, 2);
|
||||
});
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
|
|
|
@ -94,6 +94,28 @@ describe("Zotero.Sync.Data.Local", function() {
|
|||
|
||||
Zotero.DataDirectory.forceChange.restore();
|
||||
});
|
||||
|
||||
it("should migrate relations using local user key", function* () {
|
||||
yield Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='account'");
|
||||
yield Zotero.Users.init();
|
||||
|
||||
var item1 = yield createDataObject('item');
|
||||
var item2 = createUnsavedDataObject('item');
|
||||
item2.addRelatedItem(item1);
|
||||
yield item2.save();
|
||||
|
||||
var pred = Zotero.Relations.relatedItemPredicate;
|
||||
assert.isTrue(
|
||||
item2.toJSON().relations[pred][0].startsWith('http://zotero.org/users/local/')
|
||||
);
|
||||
|
||||
waitForDialog(false, 'accept', 'chrome://zotero/content/hardConfirmationDialog.xul');
|
||||
yield Zotero.Sync.Data.Local.checkUser(window, 1, "A");
|
||||
|
||||
assert.isTrue(
|
||||
item2.toJSON().relations[pred][0].startsWith('http://zotero.org/users/1/items/')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue