diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index e5639ff27e..29109416ac 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -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) { diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 34244b8df3..a176dc8d3e 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -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'); } }); diff --git a/chrome/content/zotero/xpcom/syncedSettings.js b/chrome/content/zotero/xpcom/syncedSettings.js index 7d10a042d3..fcb6383879 100644 --- a/chrome/content/zotero/xpcom/syncedSettings.js +++ b/chrome/content/zotero/xpcom/syncedSettings.js @@ -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; }) };