aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-07-01 04:27:09 +0200
committerKim Alvefur <zash@zash.se>2018-07-01 04:27:09 +0200
commitdcd5ebba7d00969b5673a49a5aaec56970508c27 (patch)
tree2e6201515fdf893eb2ea2b9cf0fa300375793c09
parent6d3f13818b03c19b4cc721bd83a23bab2423cb01 (diff)
downloadprosody-dcd5ebba7d00969b5673a49a5aaec56970508c27.tar.gz
prosody-dcd5ebba7d00969b5673a49a5aaec56970508c27.zip
util.pubsub: Persist nodes on configuration change
-rw-r--r--util/pubsub.lua19
1 files changed, 14 insertions, 5 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 0bcae258..a24b04f2 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -487,13 +487,22 @@ function service:set_node_config(node, actor, new_config)
return false, "item-not-found";
end
- if new_config["persist_items"] ~= node_obj.config["persist_items"] then
- self.data[node] = self.config.itemstore(self.nodes[node].config, node);
- elseif new_config["max_items"] ~= node_obj.config["max_items"] then
- self.data[node]:resize(new_config["max_items"]);
+ local old_config = node_obj.config;
+ node_obj.config = setmetatable(new_config, {__index=self.node_defaults});
+
+ if self.config.nodestore then
+ local ok, err = save_node_to_store(self, node_obj);
+ if not ok then
+ node_obj.config = old_config;
+ return ok, "internal-server-error";
+ end
end
- node_obj.config = setmetatable(new_config, {__index=self.node_defaults});
+ if old_config["persist_items"] ~= node_obj.config["persist_items"] then
+ self.data[node] = self.config.itemstore(self.nodes[node].config, node);
+ elseif old_config["max_items"] ~= node_obj.config["max_items"] then
+ self.data[node]:resize(self.nodes[node].config["max_items"]);
+ end
return true;
end