diff --git a/chrome/content/zotero/xpcom/data/relations.js b/chrome/content/zotero/xpcom/data/relations.js index 70f0ab431..532489073 100644 --- a/chrome/content/zotero/xpcom/data/relations.js +++ b/chrome/content/zotero/xpcom/data/relations.js @@ -124,15 +124,15 @@ Zotero.Relations = new function () { Zotero.DB.beginTransaction(); var sql = "UPDATE relations SET libraryID=? WHERE libraryID=?"; - Zotero.DB.query(sql, [fromLibraryID, toLibraryID]); + Zotero.DB.query(sql, [toLibraryID, fromLibraryID]); sql = "UPDATE relations SET " + "subject=REPLACE(subject, 'zotero.org/users/" + fromUserID + "', " + "'zotero.org/users/" + toUserID + "'), " + "object=REPLACE(object, 'zotero.org/users/" + fromUserID + "', " + "'zotero.org/users/" + toUserID + "') " - + "WHERE predicate='owl:sameAs'"; - Zotero.DB.query(sql); + + "WHERE predicate IN (?, ?)"; + Zotero.DB.query(sql, [this.linkedObjectPredicate, this.deletedItemPredicate]); Zotero.DB.commitTransaction(); } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 3c29ffd42..128890a68 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -3067,6 +3067,7 @@ Zotero.Schema = new function(){ // TODO // // Replace customBaseFieldMappings to fix FK fields/customField -> customFields->customFieldID + // If libraryID set, make sure no relations still use a local user key, and then remove on-error code in sync.js _updateDBVersion('userdata', toVersion); diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index d05336875..7752af297 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -1890,6 +1890,21 @@ Zotero.Sync.Server = new function () { } } } + + // Make sure this isn't due to relations using a local user key + // + // TEMP: This can be removed once a DB upgrade step is added + try { + var sql = "SELECT libraryID FROM relations WHERE libraryID LIKE 'local/%' LIMIT 1"; + var repl = Zotero.DB.valueQuery(sql); + if (repl) { + Zotero.Relations.updateUser(repl, repl, Zotero.userID, Zotero.libraryID); + } + } + catch (e) { + Components.utils.reportError(e); + Zotero.debug(e); + } break; case 'FULL_SYNC_REQUIRED': @@ -2200,6 +2215,10 @@ Zotero.Sync.Server = new function () { } if (lastUserID != userID || lastLibraryID != libraryID) { + if (!lastLibraryID) { + var repl = "local/" + Zotero.getLocalUserKey(); + } + Zotero.userID = userID; Zotero.libraryID = libraryID; @@ -2211,6 +2230,11 @@ Zotero.Sync.Server = new function () { Zotero.Sync.Server.resetClient(); Zotero.Sync.Storage.resetAllSyncStates(); } + // Replace local user key with libraryID, in case duplicates were + // merged before the first sync + else if (!lastLibraryID) { + Zotero.Relations.updateUser(repl, repl, userID, libraryID); + } } if (lastUsername != username) {