Fix skipNotifier option with DataObject::erase()
This commit is contained in:
parent
26673a30c5
commit
1f643c1baa
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user