commit b3067ac5c04208483801be22fb7934cf15de9b23
parent 0d59bde186f730770b3c6e845dca5ec0dcdf31a3
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 16 Jun 2015 20:28:08 -0400
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
Diffstat:
3 files changed, 44 insertions(+), 15 deletions(-)
diff --git 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
@@ -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
@@ -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;
})
};