Fix deleted item fields reappearing on sync
This was a regression from 4b60c6ca27
. The original plan for introducing
new fields was to have them save to the sync cache even if they weren't
supported by the current Zotero version and process them on upgrade, and
so I changed `DataObjectUtilities.patch()` to omit fields that didn't
exist locally when patching the sync cache JSON so they wouldn't be
wiped on the server. That caused this bug where locally deleted fields
were restored on every sync. It's also no longer necessary now that
we decided to just reject unknown fields from saving, so we can just
revert to the previous behavior of blanking out locally missing fields
(with the tweak that fields that are already false or empty in the base
version can be omitted).
This commit is contained in:
parent
513f7d6555
commit
52fd91950d
2 changed files with 15 additions and 9 deletions
|
@ -133,21 +133,24 @@ Zotero.DataObjectUtilities = {
|
|||
else {
|
||||
switch (i) {
|
||||
// When changing an item from top-level to child, the collections property is
|
||||
// no valid, so it doesn't need to be cleared
|
||||
// no longer valid, so it doesn't need to be cleared
|
||||
case 'collections':
|
||||
break;
|
||||
|
||||
// Set known boolean fields to false
|
||||
// Set known boolean fields to false if not already
|
||||
case 'deleted':
|
||||
case 'parentItem':
|
||||
case 'inPublications':
|
||||
target[i] = false;
|
||||
if (base[i]) {
|
||||
target[i] = false;
|
||||
}
|
||||
break;
|
||||
|
||||
// Skip other fields. This prevents us from clearing fields in the pristine JSON
|
||||
// that aren't handled here.
|
||||
default:
|
||||
delete target[i];
|
||||
// If base field isn't already empty, blank it out
|
||||
if (base[i] !== '') {
|
||||
target[i] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,13 +48,16 @@ describe("Zotero.DataObjectUtilities", function() {
|
|||
assert.equal(obj.conditions[1].value, 'en');
|
||||
})
|
||||
|
||||
it("should omit unknown base properties", function () {
|
||||
it("should blank out deleted properties", function () {
|
||||
var patchBase = {
|
||||
unknownField: 'Foo'
|
||||
title: 'Test',
|
||||
place: ''
|
||||
};
|
||||
var obj = {};
|
||||
obj = Zotero.DataObjectUtilities.patch(patchBase, obj);
|
||||
assert.notProperty(obj, 'unknownField');
|
||||
assert.propertyVal(obj, 'title', '');
|
||||
// place was already empty, so it shouldn't be included
|
||||
assert.notProperty(obj, 'place');
|
||||
});
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue