Add support for a get_keys() equivalent for lower than 5.7 Minetest versions
This commit is contained in:
parent
4f15c2fe65
commit
89994e0e45
87
migrate.lua
87
migrate.lua
@ -116,55 +116,78 @@ local function are_message_sames(a, b)
|
|||||||
and a.body == b.body
|
and a.body == b.body
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fix_duplicate_uuids(playername, box)
|
local function replace_other_player_message_uuid(p, m, uuid, new_uuid)
|
||||||
|
local er = mail.get_storage_entry(p)
|
||||||
|
for _, r in ipairs(er.inbox) do
|
||||||
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
|
r.id = new_uuid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, r in ipairs(er.outbox) do
|
||||||
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
|
r.id = new_uuid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, r in ipairs(er.drafts) do
|
||||||
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
|
r.id = new_uuid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, r in ipairs(er.trash) do
|
||||||
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
|
r.id = new_uuid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
mail.set_storage_entry(p, er)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function fix_box_duplicate_uuids(playername, box)
|
||||||
local e = mail.get_storage_entry(playername)
|
local e = mail.get_storage_entry(playername)
|
||||||
for _, m in ipairs(e[box]) do
|
for _, m in ipairs(e[box]) do
|
||||||
local uuid = m.id
|
local uuid = m.id
|
||||||
local exists = is_uuid_existing(uuid)
|
local exists = is_uuid_existing(uuid)
|
||||||
if exists and not are_message_sames(exists, m) then
|
if exists and not are_message_sames(exists, m) then
|
||||||
local new_uuid = mail.new_uuid() -- generates a new uuid to replace doublons
|
local new_uuid = mail.new_uuid() -- generates a new uuid to replace doublons
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
if mail.storage:get_keys() then
|
||||||
if string.sub(k,1,5) == "mail/" then
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
local p = string.sub(k, 6)
|
if string.sub(k,1,5) == "mail/" then
|
||||||
local er = mail.get_storage_entry(p)
|
local p = string.sub(k, 6)
|
||||||
for _, r in ipairs(er.inbox) do
|
replace_other_player_message_uuid(p, m, uuid, new_uuid)
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
|
||||||
r.id = new_uuid
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
for _, r in ipairs(er.outbox) do
|
end
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
else
|
||||||
r.id = new_uuid
|
for p, _ in minetest.get_auth_handler().iterate() do
|
||||||
end
|
replace_other_player_message_uuid(p, m, uuid, new_uuid)
|
||||||
end
|
|
||||||
for _, r in ipairs(er.drafts) do
|
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
|
||||||
r.id = new_uuid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for _, r in ipairs(er.trash) do
|
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
|
||||||
r.id = new_uuid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
mail.set_storage_entry(p, er)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function fix_player_duplicate_uuids(playername)
|
||||||
|
fix_box_duplicate_uuids(playername, "inbox")
|
||||||
|
fix_box_duplicate_uuids(playername, "outbox")
|
||||||
|
fix_box_duplicate_uuids(playername, "drafts")
|
||||||
|
fix_box_duplicate_uuids(playername, "trash")
|
||||||
|
end
|
||||||
|
|
||||||
-- repair database for uuid doublons
|
-- repair database for uuid doublons
|
||||||
local function repair_storage()
|
local function repair_storage()
|
||||||
-- iterate through players
|
-- iterate through players
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
-- get_keys() was introduced in 5.7
|
||||||
if string.sub(k,1,5) == "mail/" then
|
if mail.storage:get_keys() then
|
||||||
local p = string.sub(k, 6)
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
fix_duplicate_uuids(p, "inbox")
|
if string.sub(k,1,5) == "mail/" then
|
||||||
fix_duplicate_uuids(p, "outbox")
|
local p = string.sub(k, 6)
|
||||||
fix_duplicate_uuids(p, "drafts")
|
fix_player_duplicate_uuids(p)
|
||||||
fix_duplicate_uuids(p, "trash")
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
minetest.after(0, function()
|
||||||
|
for p, _ in minetest.get_auth_handler().iterate() do
|
||||||
|
fix_player_duplicate_uuids(p)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user