Fix a potential sync error with child attachments

If a standalone attachment existed in a collection and then was added to
a parent (e.g., via Create Parent Item), and attachment metadata was
also changed at the same time (e.g., due to file syncing), the
'collection item must be top level' trigger could throw on another
syncing computer. To work around this, remove collections first, then
make changes to the parentItemID columns, and then add new collections.
This commit is contained in:
Dan Stillman 2017-07-11 01:22:07 -04:00
parent 3272387afe
commit e683b2be07
2 changed files with 115 additions and 93 deletions

View file

@ -1448,6 +1448,22 @@ describe("Zotero.Item", function () {
assert.strictEqual(item.getField('accessDate'), '');
});
it("should remove child item from collection if 'collections' property not provided", function* () {
var collection = yield createDataObject('collection');
// Create standalone attachment in collection
var attachment = yield importFileAttachment('test.png', { collections: [collection.id] });
var item = yield createDataObject('item', { collections: [collection.id] });
var json = attachment.toJSON();
json.path = 'storage:test2.png';
// Add to parent, which implicitly removes from collection
json.parentItem = item.key;
delete json.collections;
Zotero.debug(json);
attachment.fromJSON(json);
yield attachment.save();
});
it("should ignore unknown fields", function* () {
var json = {
itemType: "journalArticle",