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.
This commit is contained in:
Dan Stillman 2012-01-11 01:59:12 -05:00
parent 68f3da2c10
commit f425850764
3 changed files with 28 additions and 3 deletions

View file

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

View file

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

View file

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