diff mod_bookmarks/mod_bookmarks.lua @ 3290:87769f53fdc8

mod_bookmarks: Delete the node before attempting migration, to make sure its config is correct.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 27 Aug 2018 18:14:28 +0200
parents 9346ed926842
children 947790ec4406
line wrap: on
line diff
--- a/mod_bookmarks/mod_bookmarks.lua	Sat Aug 25 20:10:21 2018 +0200
+++ b/mod_bookmarks/mod_bookmarks.lua	Mon Aug 27 18:14:28 2018 +0200
@@ -83,12 +83,12 @@
 local function on_resource_bind(event)
 	local session = event.session;
 	local username = session.username;
+	local service = mod_pep.get_pep_service(username);
 	local jid = username.."@"..session.host;
 
 	local data, err = private_storage:get(username, "storage:storage:bookmarks");
 	if not data then
 		module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", jid, err);
-		local service = mod_pep.get_pep_service(username);
 		local ok, id = service:get_last_item("storage:bookmarks", session.full_jid);
 		if not ok or not id then
 			module:log("debug", "Additionally, no PEP bookmarks were existing for %s", jid);
@@ -99,6 +99,10 @@
 	local bookmarks = st.deserialize(data);
 	module:log("debug", "Got private bookmarks of %s: %s", jid, bookmarks);
 
+	-- We don’t care if deleting succeeds or not, we only want to start with a non-existent node.
+	module:log("debug", "Deleting possibly existing PEP item for %s", jid);
+	service:delete("storage:bookmarks", jid);
+
 	module:log("debug", "Going to store PEP item for %s", jid);
 	local ok, err = publish_to_pep(session.full_jid, bookmarks);
 	if not ok then