Fix possible "Parent collection for keyed parent doesn't exist in Zotero.Collection._getParent()" sync error

This commit is contained in:
Dan Stillman 2009-08-21 05:37:20 +00:00
parent 87e2924984
commit cf5eb92799
2 changed files with 38 additions and 38 deletions

View file

@ -943,7 +943,7 @@ Zotero.Collection.prototype.serialize = function(nested) {
}, },
fields: { fields: {
name: this.name, name: this.name,
parent: this.parent, parentKey: this.parentKey,
}, },
childCollections: childCollections ? childCollections : [], childCollections: childCollections ? childCollections : [],
childItems: childItems ? childItems : [], childItems: childItems ? childItems : [],

View file

@ -421,12 +421,13 @@ Zotero.Sync.EventListener = new function () {
} }
} }
catch(e) { catch(e) {
var errMsg = Zotero.DB.getLastErrorString();
syncStatement.reset(); syncStatement.reset();
if (storageEnabled) { if (storageEnabled) {
storageStatement.reset(); storageStatement.reset();
} }
Zotero.DB.rollbackTransaction(); Zotero.DB.rollbackTransaction();
throw(Zotero.DB.getLastErrorString()); throw (errMsg + " in Zotero.Sync.EventListener.notify()");
} }
} }
@ -1841,6 +1842,8 @@ Zotero.Sync.Server.Session = function () {
this.uploadKeys = {}; this.uploadKeys = {};
this.uploadKeys.updated = new Zotero.Sync.ObjectKeySet; this.uploadKeys.updated = new Zotero.Sync.ObjectKeySet;
this.uploadKeys.deleted = new Zotero.Sync.ObjectKeySet; this.uploadKeys.deleted = new Zotero.Sync.ObjectKeySet;
this.suppressWarnings = false;
} }
@ -2078,7 +2081,7 @@ Zotero.Sync.Server.Data = new function() {
} }
// Mark other types for conflict resolution // Mark other types for conflict resolution
else { else {
var reconcile = false; var skipCR = false;
// Skip item if dateModified is the only modified // Skip item if dateModified is the only modified
// field (and no linked creators changed) // field (and no linked creators changed)
@ -2127,15 +2130,18 @@ Zotero.Sync.Server.Data = new function() {
remoteObj = 'trashed'; remoteObj = 'trashed';
} }
*/ */
reconcile = true;
break; break;
case 'collection': case 'collection':
var changed = _mergeCollection(obj, remoteObj, childItemStore); // TODO: move childItemStore to syncSession
var changed = _mergeCollection(obj, remoteObj, childItemStore, syncSession);
if (!changed) { if (!changed) {
syncSession.removeFromUpdated(obj); syncSession.removeFromUpdated(obj);
continue;
} }
continue; // The merged collection needs to be saved
skipCR = true;
break;
case 'tag': case 'tag':
var changed = _mergeTag(obj, remoteObj); var changed = _mergeTag(obj, remoteObj);
@ -2145,22 +2151,16 @@ Zotero.Sync.Server.Data = new function() {
continue; continue;
} }
if (!reconcile) {
Zotero.debug(obj);
Zotero.debug(remoteObj);
var msg = "Reconciliation unimplemented for " + types;
alert(msg);
throw(msg);
}
// TODO: order reconcile by parent/child? // TODO: order reconcile by parent/child?
toReconcile.push([ if (!skipCR) {
obj, toReconcile.push([
remoteObj obj,
]); remoteObj
]);
continue;
continue;
}
} }
} }
else { else {
@ -2641,7 +2641,7 @@ Zotero.Sync.Server.Data = new function() {
} }
function _mergeCollection(localObj, remoteObj, childItemStore) { function _mergeCollection(localObj, remoteObj, childItemStore, syncSession) {
var diff = localObj.diff(remoteObj, false, true); var diff = localObj.diff(remoteObj, false, true);
if (!diff) { if (!diff) {
return false; return false;
@ -2651,8 +2651,7 @@ Zotero.Sync.Server.Data = new function() {
Zotero.debug(diff); Zotero.debug(diff);
// Local is newer // Local is newer
if (diff[0].primary.dateModified > if (diff[0].primary.dateModified > diff[1].primary.dateModified) {
diff[1].primary.dateModified) {
var remoteIsTarget = false; var remoteIsTarget = false;
var targetObj = localObj; var targetObj = localObj;
var targetDiff = diff[0]; var targetDiff = diff[0];
@ -2667,11 +2666,13 @@ Zotero.Sync.Server.Data = new function() {
} }
if (targetDiff.fields.name) { if (targetDiff.fields.name) {
var msg = _generateAutoChangeMessage( if (!syncSession.suppressWarnings) {
'collection', diff[0].fields.name, diff[1].fields.name, remoteIsTarget var msg = _generateAutoChangeMessage(
); 'collection', diff[0].fields.name, diff[1].fields.name, remoteIsTarget
// TODO: log rather than alert );
alert(msg); // TODO: log rather than alert
alert(msg);
}
} }
// Check for child collections in the other object // Check for child collections in the other object
@ -2692,18 +2693,17 @@ Zotero.Sync.Server.Data = new function() {
targetObj.childItems = otherDiff.childItems; targetObj.childItems = otherDiff.childItems;
} }
var msg = _generateCollectionItemMergeMessage( if (!syncSession.suppressWarnings) {
targetObj.name, var msg = _generateCollectionItemMergeMessage(
otherDiff.childItems, targetObj.name,
remoteIsTarget otherDiff.childItems,
); remoteIsTarget
// TODO: log rather than alert );
alert(msg); // TODO: log rather than alert
alert(msg);
}
} }
_removeChildItemsFromCollection(targetObj, childItemStore);
targetObj.save();
return true; return true;
} }