From 79cd7197ff9635dd080e2643da20e961da49381d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 21 Feb 2014 19:02:02 -0500 Subject: [PATCH] Fix a rare cause of sync conflicts Sometime in the past SQL datetimes saved to the server could be interpreted as multipart dates, causing the date portion to be stripped from the visible field. I fixed this previously on the server, but a full sync could result in conflicts for any such values that synced down. Instead, overwrite the local version (keeping Date Modified the same) if there are no other changes. --- chrome/content/zotero/xpcom/sync.js | 38 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index 502d87b17..3eb0699ef 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -2858,6 +2858,7 @@ Zotero.Sync.Server.Data = new function() { var toSave = []; var toDelete = []; var toReconcile = []; + var skipDateModifiedUpdateItems = {}; // Display a warning once for each object type syncSession.suppressWarnings = false; @@ -2977,9 +2978,36 @@ Zotero.Sync.Server.Data = new function() { case 'item': var diff = obj.diff(remoteObj, false, ["dateAdded", "dateModified"]); - Zotero.debug('Diff:'); - Zotero.debug(diff); - if (!diff) { + if (diff) { + Zotero.debug('Diff:'); + Zotero.debug(diff); + + try { + let dateField; + if (!Object.keys(diff[0].primary).length + && !Object.keys(diff[1].primary).length + && !diff[0].creators.length + && !diff[1].creators.length + && Object.keys(diff[0].fields).length == 1 + && (dateField = Object.keys(diff[0].fields)[0]) + && Zotero.ItemFields.isFieldOfBase(dateField, 'date') + && /[0-9]{2}:[0-9]{2}:[0-9]{2}/.test(diff[0].fields[dateField]) + && Zotero.Date.isSQLDateTime(diff[1].fields[dateField]) + && diff[1].fields[dateField].substr(11).indexOf(diff[0].fields[dateField]) == 0) { + Zotero.debug("Marking local item with corrupted SQL date for overwriting", 2); + obj.setField(dateField, diff[1].fields[dateField]); + skipDateModifiedUpdateItems[obj.id] = true; + syncSession.removeFromUpdated(obj); + skipCR = true; + break; + } + } + catch (e) { + Components.utils.reportError(e); + Zotero.debug(e, 1); + } + } + else { // Check if creators changed var creatorsChanged = false; @@ -3390,7 +3418,9 @@ Zotero.Sync.Server.Data = new function() { // Save parent items first for (var i=0; i