www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 67f4a467eac1247613f2657314bcceae97e10689
parent 4600318ad70b3ba699ac76f1a4f533e7d11de3dd
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun,  2 Aug 2015 03:40:14 -0400

Consolidate object erase methods into DataObjects::erase()

Diffstat:
Mchrome/content/zotero/xpcom/data/collections.js | 17-----------------
Mchrome/content/zotero/xpcom/data/dataObjects.js | 25+++++++++++++++++++++++++
Mchrome/content/zotero/xpcom/data/items.js | 23-----------------------
Mchrome/content/zotero/xpcom/search.js | 15---------------
4 files changed, 25 insertions(+), 55 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/collections.js b/chrome/content/zotero/xpcom/data/collections.js @@ -182,23 +182,6 @@ Zotero.Collections = function() { } } - - this.erase = function(ids) { - ids = Zotero.flattenArguments(ids); - - return Zotero.DB.executeTransaction(function* () { - for each(var id in ids) { - var collection = yield this.getAsync(id); - if (collection) { - yield collection.erase(); - } - collection = undefined; - } - - this.unload(ids); - }.bind(this)); - }; - Zotero.DataObjects.call(this); return this; diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -518,6 +518,31 @@ Zotero.DataObjects.prototype.getPrimaryDataSQLPart = function (part) { } +/** + * Delete one or more objects from the database and caches + * + * @param {Integer|Integer[]} ids - Object ids + * @param {Object} [options] - See Zotero.DataObject.prototype.erase + * @return {Promise} + */ +Zotero.DataObjects.prototype.erase = Zotero.Promise.coroutine(function* (ids, options = {}) { + ids = Zotero.flattenArguments(ids); + yield Zotero.DB.executeTransaction(function* () { + for (let i = 0; i < ids.length; i++) { + let obj = yield this.getAsync(ids[i]); + if (!obj) { + continue; + } + yield obj.erase(options); + } + this.unload(ids); + }.bind(this)); +}); + + + + + Zotero.DataObjects.prototype._load = Zotero.Promise.coroutine(function* (libraryID, ids, options) { var loaded = {}; diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js @@ -598,29 +598,6 @@ Zotero.Items = function() { /** - * Delete item(s) from database and clear from internal array - * - * @param {Integer|Integer[]} ids - Item ids - * @return {Promise} - */ - this.erase = function (ids) { - return Zotero.DB.executeTransaction(function* () { - ids = Zotero.flattenArguments(ids); - - for (let i=0; i<ids.length; i++) { - let id = ids[i]; - let item = yield this.getAsync(id); - if (!item) { - Zotero.debug('Item ' + id + ' does not exist in Items.erase()!', 1); - continue; - } - yield item.erase(); // calls unload() - } - }.bind(this)); - }; - - - /** * Purge unused data values */ this.purge = Zotero.Promise.coroutine(function* () { diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js @@ -1689,21 +1689,6 @@ Zotero.Searches = function() { }); - /* - * Delete a given saved search from the DB - */ - this.erase = Zotero.Promise.coroutine(function* (ids) { - ids = Zotero.flattenArguments(ids); - - yield Zotero.DB.executeTransaction(function* () { - for (let i=0; i<ids.length; i++) { - let search = yield Zotero.Searches.getAsync(ids[i]); - yield search.erase(); - } - }.bind(this)); - }); - - this.getPrimaryDataSQL = function () { // This should be the same as the query in Zotero.Search.loadPrimaryData(), // just without a specific savedSearchID