From 6d5b00e94cafb5b273fd83a274f029f484ae0b2a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 6 May 2021 03:29:50 -0400 Subject: [PATCH] Fix descendant collections not skipping delete log If a collection was deleted with `skipDeleteLog: true`, descendant collections still ended up in the delete log, which could cause constant "Reset Group and Sync" prompts. https://forums.zotero.org/discussion/89485/warning-when-syncing-group-library --- chrome/content/zotero/xpcom/data/collection.js | 5 +++++ test/tests/collectionTest.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index a6664bf5d0..438713baff 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -607,6 +607,11 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env libraryID: c.libraryID, key: c.key }; + // skipDeleteLog is normally added to notifierData in DataObject::_finalizeErase(), + // so we have to do it manually here + if (env.options && env.options.skipDeleteLog) { + env.notifierData[c.id].skipDeleteLog = true; + } } } // Descendent items diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js index 6304d8a41c..a9b19869f1 100644 --- a/test/tests/collectionTest.js +++ b/test/tests/collectionTest.js @@ -61,6 +61,21 @@ describe("Zotero.Collection", function() { yield collection.eraseTx({ deleteItems: true }); assert.lengthOf(item.getCollections(), 0); }); + + it("should apply 'skipDeleteLog: true' to subcollections", async function () { + var collection1 = await createDataObject('collection'); + var collection2 = await createDataObject('collection', { parentID: collection1.id }); + var collection3 = await createDataObject('collection', { parentID: collection2.id }); + + await collection1.eraseTx({ skipDeleteLog: true }); + + var deleted = await Zotero.Sync.Data.Local.getDeleted('collection', collection1.libraryID); + + // No collections should be in the delete log + assert.notInclude(deleted, collection1.key); + assert.notInclude(deleted, collection2.key); + assert.notInclude(deleted, collection3.key); + }); }) describe("#version", function () {