diff --git a/chrome/content/zotero/recognizePDF.js b/chrome/content/zotero/recognizePDF.js index 4846282aa..09a81198c 100644 --- a/chrome/content/zotero/recognizePDF.js +++ b/chrome/content/zotero/recognizePDF.js @@ -396,14 +396,16 @@ var Zotero_RecognizePDF = new function() { // put new item in same collections as the old one let itemCollections = item.getCollections(); - for (let i = 0; i < itemCollections.length; i++) { - let collection = yield Zotero.Collections.getAsync(itemCollections[i]); - yield collection.addItem(newItem.id); - } - - // put old item as a child of the new item - item.parentID = newItem.id; - yield item.saveTx(); + yield Zotero.DB.executeTransaction(function* () { + for (let i = 0; i < itemCollections.length; i++) { + let collection = Zotero.Collections.get(itemCollections[i]); + yield collection.addItem(newItem.id); + } + + // put old item as a child of the new item + item.parentID = newItem.id; + yield item.save(); + }); itemTitle.setAttribute("label", newItem.getField("title")); itemIcon.setAttribute("src", SUCCESS_IMAGE); diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 04fefe09a..368c6121a 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -358,8 +358,8 @@ Zotero.Collection.prototype._finalizeSave = Zotero.Promise.coroutine(function* ( * @param {Number} itemID * @return {Promise} */ -Zotero.Collection.prototype.addItem = function (itemID) { - return this.addItems([itemID]); +Zotero.Collection.prototype.addItem = function (itemID, options) { + return this.addItems([itemID], options); } @@ -371,7 +371,9 @@ Zotero.Collection.prototype.addItem = function (itemID) { * @param {Number[]} itemIDs * @return {Promise} */ -Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemIDs) { +Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemIDs, options = {}) { + options.skipDateModifiedUpdate = true; + if (!itemIDs || !itemIDs.length) { return; } @@ -389,9 +391,7 @@ Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemI let item = this.ChildObjects.get(itemID); item.addToCollection(this.id); - yield item.save({ - skipDateModifiedUpdate: true - }); + yield item.save(options); } yield this.loadDataType('childItems'); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 26ed1de4a..d6ab45214 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1396,9 +1396,11 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { let newParentItemNotifierData = {}; //newParentItemNotifierData[newParentItem.id] = {}; - Zotero.Notifier.queue( - 'modify', 'item', parentItemID, newParentItemNotifierData, env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'modify', 'item', parentItemID, newParentItemNotifierData, env.options.notifierQueue + ); + } switch (Zotero.ItemTypes.getName(itemTypeID)) { case 'note': @@ -1422,13 +1424,15 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { let newParentItemNotifierData = {}; //newParentItemNotifierData[newParentItem.id] = {}; - Zotero.Notifier.queue( - 'modify', - 'item', - parentItemID, - newParentItemNotifierData, - env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'modify', + 'item', + parentItemID, + newParentItemNotifierData, + env.options.notifierQueue + ); + } } let oldParentKey = this._previousData.parentKey; @@ -1438,13 +1442,15 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { if (oldParentItemID) { let oldParentItemNotifierData = {}; //oldParentItemNotifierData[oldParentItemID] = {}; - Zotero.Notifier.queue( - 'modify', - 'item', - oldParentItemID, - oldParentItemNotifierData, - env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'modify', + 'item', + oldParentItemID, + oldParentItemNotifierData, + env.options.notifierQueue + ); + } } else { Zotero.debug("Old source item " + oldParentKey @@ -1465,13 +1471,15 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { parentItem.addToCollection(changedCollections[i]); this.removeFromCollection(changedCollections[i]); - Zotero.Notifier.queue( - 'remove', - 'collection-item', - changedCollections[i] + '-' + this.id, - {}, - env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'remove', + 'collection-item', + changedCollections[i] + '-' + this.id, + {}, + env.options.notifierQueue + ); + } } let parentOptions = { skipDateModifiedUpdate: true @@ -1536,9 +1544,11 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { yield Zotero.DB.queryAsync(sql, itemID); // Refresh trash - Zotero.Notifier.queue('refresh', 'trash', this.libraryID, {}, env.options.notifierQueue); - if (this._deleted) { - Zotero.Notifier.queue('trash', 'item', this.id, {}, env.options.notifierQueue); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue('refresh', 'trash', this.libraryID, {}, env.options.notifierQueue); + if (this._deleted) { + Zotero.Notifier.queue('trash', 'item', this.id, {}, env.options.notifierQueue); + } } if (parentItemID) { @@ -1658,9 +1668,11 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { tag: tag.tag, type: tagType }; - Zotero.Notifier.queue( - 'add', 'item-tag', this.id + '-' + tagID, notifierData, env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'add', 'item-tag', this.id + '-' + tagID, notifierData, env.options.notifierQueue + ); + } } if (toRemove.length) { @@ -1674,9 +1686,12 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { libraryID: this.libraryID, tag: tag.tag }; - Zotero.Notifier.queue( - 'remove', 'item-tag', this.id + '-' + tagID, notifierData, env.options.notifierQueue - ); + + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'remove', 'item-tag', this.id + '-' + tagID, notifierData, env.options.notifierQueue + ); + } } Zotero.Prefs.set('purge.tags', true); } @@ -1709,13 +1724,15 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { + "(collectionID, itemID, orderIndex) VALUES (?, ?, ?)"; yield Zotero.DB.queryAsync(sql, [collectionID, this.id, orderIndex]); - Zotero.Notifier.queue( - 'add', - 'collection-item', - collectionID + '-' + this.id, - {}, - env.options.notifierQueue - ); + if (!env.options.skipNotifier) { + Zotero.Notifier.queue( + 'add', + 'collection-item', + collectionID + '-' + this.id, + {}, + env.options.notifierQueue + ); + } } // Add this item to any loaded collections' cached item lists after commit @@ -1735,13 +1752,15 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { for (let i=0; i