Quantcast

database changes

Steven Jackson [07-03-14 - 18:13]
database changes
Filename
Interface/AddOns/SVUI/system/classes/Database.lua
diff --git a/Interface/AddOns/SVUI/system/classes/Database.lua b/Interface/AddOns/SVUI/system/classes/Database.lua
index bba2148..982050b 100644
--- a/Interface/AddOns/SVUI/system/classes/Database.lua
+++ b/Interface/AddOns/SVUI/system/classes/Database.lua
@@ -3356,14 +3356,16 @@ local function tablecopy(d, s)
 	if type(s) ~= "table" then return end
 	if type(d) == "table" then
 		for k, v in pairs(s) do
-			if type(v) == "table" then
-				if not rawget(d, k) then rawset(d, k, {}) end
-				if type(d[k]) == "table" then
-					tablecopy(d[k], v)
-				end
-			else
-				if rawget(d, k) == nil then
-					rawset(d, k, v)
+			if(k ~= "SAFEDATA") then
+				if type(v) == "table" then
+					if not rawget(d, k) then rawset(d, k, {}) end
+					if type(d[k]) == "table" then
+						tablecopy(d[k], v)
+					end
+				else
+					if rawget(d, k) == nil then
+						rawset(d, k, v)
+					end
 				end
 			end
 		end
@@ -3462,22 +3464,24 @@ local function removeprofile(t, key)
 	if(globals.profileKeys[key]) then globals.profileKeys[key] = nil end
 end

-local function SanitizeDatabase(t)
-	local sv = rawget(t, "profile")
-	local src = rawget(t, "defaults")
-	for k,v in pairs(sv) do
-		if(k ~= "SAFEDATA") then
-			if(rawget(src, k)) then
-				for key in pairs(sv[k]) do
-					if not next(sv[k][key]) then
-						sv[k][key] = nil
+local SanitizeDatabase = function(self, event)
+	if event == "PLAYER_LOGOUT" then
+		local sv = _G["SVUI_Profile"]
+		local src = DatabaseDefaults
+		for k,v in pairs(sv) do
+			if(k ~= "SAFEDATA") then
+				if(rawget(src, k)) then
+					for key in pairs(sv[k]) do
+						if not next(sv[k][key]) then
+							sv[k][key] = nil
+						end
 					end
-				end
-				if not next(sv[k]) then
+					if not next(sv[k]) then
+						sv[k] = nil
+					end
+				else
 					sv[k] = nil
 				end
-			else
-				sv[k] = nil
 			end
 		end
 	end
@@ -3514,11 +3518,7 @@ local METAPROFILE = function(sv, pkey)

 	local logout = CreateFrame("Frame",nil)
 	logout:RegisterEvent("PLAYER_LOGOUT")
-	logout:SetScript("OnEvent", function(self, event)
-		if event == "PLAYER_LOGOUT" then
-			SanitizeDatabase(SuperVillain.db)
-		end
-	end)
+	logout:SetScript("OnEvent", SanitizeDatabase)

 	return db
 end