Require DB transaction in Zotero.Items.moveChildItems()

But make optional with deprecation warning for now, since it's used in
ZotFile
This commit is contained in:
Dan Stillman 2022-02-08 06:32:57 -05:00
parent f684984b07
commit 734057ff9b

View file

@ -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