comparison 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
comparison
equal deleted inserted replaced
3289:f2037a754480 3290:87769f53fdc8
81 end 81 end
82 82
83 local function on_resource_bind(event) 83 local function on_resource_bind(event)
84 local session = event.session; 84 local session = event.session;
85 local username = session.username; 85 local username = session.username;
86 local service = mod_pep.get_pep_service(username);
86 local jid = username.."@"..session.host; 87 local jid = username.."@"..session.host;
87 88
88 local data, err = private_storage:get(username, "storage:storage:bookmarks"); 89 local data, err = private_storage:get(username, "storage:storage:bookmarks");
89 if not data then 90 if not data then
90 module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", jid, err); 91 module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", jid, err);
91 local service = mod_pep.get_pep_service(username);
92 local ok, id = service:get_last_item("storage:bookmarks", session.full_jid); 92 local ok, id = service:get_last_item("storage:bookmarks", session.full_jid);
93 if not ok or not id then 93 if not ok or not id then
94 module:log("debug", "Additionally, no PEP bookmarks were existing for %s", jid); 94 module:log("debug", "Additionally, no PEP bookmarks were existing for %s", jid);
95 module:fire_event("bookmarks/empty", { session = session }); 95 module:fire_event("bookmarks/empty", { session = session });
96 end 96 end
97 return; 97 return;
98 end 98 end
99 local bookmarks = st.deserialize(data); 99 local bookmarks = st.deserialize(data);
100 module:log("debug", "Got private bookmarks of %s: %s", jid, bookmarks); 100 module:log("debug", "Got private bookmarks of %s: %s", jid, bookmarks);
101
102 -- We don’t care if deleting succeeds or not, we only want to start with a non-existent node.
103 module:log("debug", "Deleting possibly existing PEP item for %s", jid);
104 service:delete("storage:bookmarks", jid);
101 105
102 module:log("debug", "Going to store PEP item for %s", jid); 106 module:log("debug", "Going to store PEP item for %s", jid);
103 local ok, err = publish_to_pep(session.full_jid, bookmarks); 107 local ok, err = publish_to_pep(session.full_jid, bookmarks);
104 if not ok then 108 if not ok then
105 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err); 109 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err);