From 37c48dc3ee613f6bd407de2c027e6b0cef64fd84 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Mar 2022 17:57:50 -0400 Subject: [PATCH] Remove `Zotero.Items.moveChildItems()` transaction requirement exception Follow-up to 734057ff9b2 This was supposed to allow ZotFile to continue to work but 1) it contained a bug and 2) another transaction messed things up for ZotFile anyway, so we'll just fix this in jlegewie/zotfile#593. --- chrome/content/zotero/xpcom/attachments.js | 4 +++- chrome/content/zotero/xpcom/data/items.js | 20 +++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 196cef2b69..7174ea9186 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2735,7 +2735,9 @@ Zotero.Attachments = new function(){ await newItem.saveTx(); // Move child annotations and embedded-image attachments - await Zotero.Items.moveChildItems(item, newItem); + await Zotero.DB.executeTransaction(async function () { + await Zotero.Items.moveChildItems(item, newItem); + }); // Copy relations pointing to the old item await Zotero.Relations.copyObjectSubjectRelations(item, newItem); diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 87feeabe8b..403bf525eb 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -929,24 +929,14 @@ Zotero.Items = function() { * @return {Promise} */ this.moveChildItems = async function (fromItem, toItem, includeTrashed = false) { - //Zotero.DB.requireTransaction(); + Zotero.DB.requireTransaction(); // Annotations on files if (fromItem.isFileAttachment()) { - let fn = async function () { - let annotations = fromItem.getAnnotations(includeTrashed); - for (let annotation of annotations) { - annotation.parentItemID = toItem.id; - await annotation.save(); - } - }; - - if (!Zotero.DB.inTransaction) { - Zotero.logError("moveChildItems() now requires a transaction -- please update your code"); - await Zotero.DB.executeTransaction(fn); - } - else { - await fn(); + let annotations = fromItem.getAnnotations(includeTrashed); + for (let annotation of annotations) { + annotation.parentItemID = toItem.id; + await annotation.save(); } }