Add skipDeleteLog option when erasing objects
To be used by updated deletion listener in new sync code Also adds explicit Zotero.SyncedSettings.clear() in place of Zotero.SyncSettings.set() without a value
This commit is contained in:
parent
0d59bde186
commit
b3067ac5c0
3 changed files with 44 additions and 15 deletions
|
@ -1113,6 +1113,9 @@ Zotero.DataObject.prototype.updateSynced = Zotero.Promise.coroutine(function* (s
|
|||
|
||||
/**
|
||||
* Delete object from database
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.skipDeleteLog] - Don't add to sync delete log
|
||||
*/
|
||||
Zotero.DataObject.prototype.erase = Zotero.Promise.coroutine(function* (options) {
|
||||
options = options || {};
|
||||
|
@ -1156,6 +1159,10 @@ Zotero.DataObject.prototype._initErase = function (env) {
|
|||
libraryID: this.libraryID,
|
||||
key: this.key
|
||||
};
|
||||
|
||||
if (env.options.skipDeleteLog) {
|
||||
env.notifierData[this.id].skipDeleteLog = true;
|
||||
}
|
||||
};
|
||||
|
||||
Zotero.DataObject.prototype._finalizeErase = function (env) {
|
||||
|
|
|
@ -561,7 +561,7 @@ Zotero.Tags = new function() {
|
|||
return Zotero.SyncedSettings.set(libraryID, 'tagColors', tagColors);
|
||||
}
|
||||
else {
|
||||
return Zotero.SyncedSettings.set(libraryID, 'tagColors');
|
||||
return Zotero.SyncedSettings.clear(libraryID, 'tagColors');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -40,8 +40,11 @@ Zotero.SyncedSettings = (function () {
|
|||
return JSON.parse(json);
|
||||
}),
|
||||
|
||||
|
||||
set: Zotero.Promise.coroutine(function* (libraryID, setting, value, version, synced) {
|
||||
if (typeof value == undefined) {
|
||||
throw new Error("Value not provided");
|
||||
}
|
||||
|
||||
// TODO: get rid of this once we have proper affected rows handling
|
||||
var sql = "SELECT value FROM syncedSettings WHERE setting=? AND libraryID=?";
|
||||
var currentValue = yield Zotero.DB.valueQueryAsync(sql, [setting, libraryID]);
|
||||
|
@ -50,11 +53,11 @@ Zotero.SyncedSettings = (function () {
|
|||
// missing setting (FALSE as returned by valueQuery())
|
||||
// and a FALSE setting (FALSE as returned by JSON.parse())
|
||||
var hasCurrentValue = currentValue !== false;
|
||||
var hasValue = typeof value != 'undefined';
|
||||
|
||||
currentValue = JSON.parse(currentValue);
|
||||
|
||||
if ((!hasCurrentValue && !hasValue) || value === currentValue) {
|
||||
// Value hasn't changed
|
||||
if (value === currentValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -70,17 +73,6 @@ Zotero.SyncedSettings = (function () {
|
|||
};
|
||||
}
|
||||
|
||||
// Clear
|
||||
if (typeof value == 'undefined') {
|
||||
var sql = "DELETE FROM syncedSettings WHERE setting=? AND libraryID=?";
|
||||
yield Zotero.DB.queryAsync(sql, [setting, libraryID]);
|
||||
|
||||
yield Zotero.Notifier.trigger('delete', 'setting', [id], extraData);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set/update
|
||||
|
||||
if (currentValue === false) {
|
||||
var event = 'add';
|
||||
var extraData = {};
|
||||
|
@ -102,6 +94,36 @@ Zotero.SyncedSettings = (function () {
|
|||
}
|
||||
yield Zotero.Notifier.trigger(event, 'setting', [id], extraData);
|
||||
return true;
|
||||
}),
|
||||
|
||||
clear: Zotero.Promise.coroutine(function* (libraryID, setting, options) {
|
||||
options = options || {};
|
||||
|
||||
// TODO: get rid of this once we have proper affected rows handling
|
||||
var sql = "SELECT value FROM syncedSettings WHERE setting=? AND libraryID=?";
|
||||
var currentValue = yield Zotero.DB.valueQueryAsync(sql, [setting, libraryID]);
|
||||
if (currentValue === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var id = libraryID + '/' + setting;
|
||||
|
||||
var extraData = {};
|
||||
extraData[id] = {
|
||||
changed: {}
|
||||
};
|
||||
extraData[id].changed = {
|
||||
value: currentValue
|
||||
};
|
||||
if (options.skipDeleteLog) {
|
||||
extraData[id].skipDeleteLog = true;
|
||||
}
|
||||
|
||||
var sql = "DELETE FROM syncedSettings WHERE setting=? AND libraryID=?";
|
||||
yield Zotero.DB.queryAsync(sql, [setting, libraryID]);
|
||||
|
||||
yield Zotero.Notifier.trigger('delete', 'setting', [id], extraData);
|
||||
return true;
|
||||
})
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue