From 734057ff9b294482dce1e8675299f48df5667aff Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 8 Feb 2022 06:32:57 -0500 Subject: [PATCH] Require DB transaction in `Zotero.Items.moveChildItems()` But make optional with deprecation warning for now, since it's used in ZotFile --- chrome/content/zotero/xpcom/data/items.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 3dc94a5b33..77ca9a37f1 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -915,20 +915,32 @@ Zotero.Items = function() { /** * Move child items from one item to another * + * Requires a transaction + * * @param {Zotero.Item} fromItem * @param {Zotero.Item} toItem * @return {Promise} */ this.moveChildItems = async function (fromItem, toItem) { + //Zotero.DB.requireTransaction(); + // Annotations on files if (fromItem.isFileAttachment()) { - await Zotero.DB.executeTransaction(async function () { + let fn = async function () { let annotations = fromItem.getAnnotations(); for (let annotation of annotations) { annotation.parentItemID = toItem.id; await annotation.save(); - } - }.bind(this)); + }; + }; + + if (!Zotero.DB.inTransaction) { + Zotero.logError("moveChildItems() now requires a transaction -- please update your code"); + await Zotero.DB.executeTransaction(fn); + } + else { + await fn(); + } } // TODO: Other things as necessary