Diff

util/pubsub.lua @ 8951:9baac001fccb

util.pubsub: Persist nodes on configuration change
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2018 04:27:09 +0200
parent 8950:03ba5b4f131a
child 8952:15bb54f96dd1
line wrap: on
line diff
--- a/util/pubsub.lua	Sun Jul 01 04:17:36 2018 +0200
+++ b/util/pubsub.lua	Sun Jul 01 04:27:09 2018 +0200
@@ -487,13 +487,22 @@
 		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