Consolidate object erase methods into DataObjects::erase()
This commit is contained in:
parent
4600318ad7
commit
67f4a467ea
4 changed files with 25 additions and 55 deletions
|
@ -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;
|
||||
|
|
|
@ -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 = {};
|
||||
|
||||
|
|
|
@ -597,29 +597,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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue