Changeset

7772:752697d68fda

mod_blocklist: Return early from migration if no valid privacy list data is found
author Kim Alvefur <zash@zash.se>
date Mon, 05 Dec 2016 17:22:12 +0100
parents 7771:2b288dab781a
children 7773:7fd26815fcf6
files plugins/mod_blocklist.lua
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_blocklist.lua	Thu Dec 08 18:13:56 2016 +0100
+++ b/plugins/mod_blocklist.lua	Mon Dec 05 17:22:12 2016 +0100
@@ -54,14 +54,13 @@
 
 -- Migrates from the old mod_privacy storage
 local function migrate_privacy_list(username)
+	local legacy_data = module:open_store("privacy"):get(username);
+	if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end
+	local default_list = legacy_data.lists[legacy_data.default];
+	if not default_list or not default_list.items then return; end
+
 	local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }};
-	local legacy_data = module:open_store("privacy"):get(username);
-	if legacy_data and legacy_data.lists and legacy_data.default then
-		legacy_data = legacy_data.lists[legacy_data.default];
-		legacy_data = legacy_data and legacy_data.items;
-	else
-		return migrated_data;
-	end
+
 	if legacy_data then
 		module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
 		local item, jid;
@@ -94,6 +93,9 @@
 		if not blocklist then
 			blocklist = migrate_privacy_list(username);
 		end
+		if not blocklist then
+			blocklist = { [false] = { created = os.time(); }; };
+		end
 		cache2:set(username, blocklist);
 	end
 	cache[username] = blocklist;