commit 1f643c1baae4dbca49277b23c49b4929006b2d37
parent 26673a30c583c7a64076ff3dcd2a256164c406be
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 2 Jun 2015 03:28:46 -0400
Fix skipNotifier option with DataObject::erase()
Diffstat:
4 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js
@@ -611,7 +611,7 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env
this.ObjectsClass.unload(collections);
//return Zotero.Collections.reloadAll();
- if (!env.skipNotifier) {
+ if (!env.options.skipNotifier) {
Zotero.Notifier.queue('delete', 'collection', collections, notifierData);
}
});
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -3762,7 +3762,11 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
let toDelete = yield Zotero.DB.columnQueryAsync(sql, [this.id]);
for (let i=0; i<toDelete.length; i++) {
let obj = yield this.ObjectsClass.getAsync(toDelete[i]);
- yield obj.erase();
+ // Copy all options other than 'tx', which would cause a deadlock
+ let options = {};
+ Object.assign(options, env.options);
+ delete options.tx;
+ yield obj.erase(options);
}
}
@@ -3788,7 +3792,7 @@ Zotero.Item.prototype._erasePreCommit = Zotero.Promise.coroutine(function* (env)
this.ObjectsClass.unload(this.id);
- if (!env.skipNotifier) {
+ if (!env.options.skipNotifier) {
Zotero.Notifier.queue('delete', 'item', this.id, env.deletedItemNotifierData);
}
diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js
@@ -232,7 +232,7 @@ Zotero.Search.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
var sql = "DELETE FROM savedSearches WHERE savedSearchID=?";
yield Zotero.DB.queryAsync(sql, this.id);
- if (!env.skipNotifier) {
+ if (!env.options.skipNotifier) {
Zotero.Notifier.queue('delete', 'search', this.id, notifierData);
}
});
diff --git a/test/tests/dataObjectTest.js b/test/tests/dataObjectTest.js
@@ -126,6 +126,44 @@ describe("Zotero.DataObject", function() {
})
})
+ describe("#erase()", function () {
+ it("shouldn't trigger notifier if skipNotifier is passed", function* () {
+ let observerIDs = [];
+ let promises = [];
+ for (let type of types) {
+ let obj = yield createDataObject(type);
+ // For items, test automatic child item deletion
+ if (type == 'item') {
+ yield createDataObject(type, { itemType: 'note', parentID: obj.id });
+ }
+
+ let deferred = Zotero.Promise.defer();
+ promises.push(deferred.promise);
+ observerIDs.push(Zotero.Notifier.registerObserver(
+ {
+ notify: function (event) {
+ if (event == 'delete') {
+ deferred.reject("Notifier called for erase on " + type);
+ }
+ }
+ },
+ type,
+ 'test'
+ ));
+ yield obj.eraseTx({
+ skipNotifier: true
+ });
+ }
+ yield Zotero.Promise.all(promises)
+ // Give notifier time to trigger
+ .timeout(100).catch(Zotero.Promise.TimeoutError, (e) => {})
+
+ for (let id of observerIDs) {
+ Zotero.Notifier.unregisterObserver(id);
+ }
+ })
+ })
+
describe("#updateVersion()", function() {
it("should update the object version", function* () {
for (let type of types) {