www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit f4258507643e1622b6d298eb4994fa15afd78da8
parent 68f3da2c10aef7a8510abef4e0dded2015604b97
Author: Dan Stillman <dstillman@zotero.org>
Date:   Wed, 11 Jan 2012 01:59:12 -0500

Fix sync error if duplicates are merged before first sync

Replace local user key in relations with libraryID on sync user changes
and invalid upload sync errors. The latter will be unnecessary after a
DB upgrade step.

Also fixes libraryID in relations not being replaced correctly when
switching sync users.

Diffstat:
Mchrome/content/zotero/xpcom/data/relations.js | 6+++---
Mchrome/content/zotero/xpcom/schema.js | 1+
Mchrome/content/zotero/xpcom/sync.js | 24++++++++++++++++++++++++
3 files changed, 28 insertions(+), 3 deletions(-)

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