prpw/cmd/entry_backup.lua
2024-08-10 00:35:03 +00:00

36 lines
875 B
Lua

local function cmd(args)
local entries = env.xmlFindTags(env.db,"entries")[1]
for i,entry in pairs(entries.children) do
if entry.attrs.id == args[2] then
local history = env.xmlFindTags(entry,"history")[1]
local hentry = {}
hentry.tag = "entry"
hentry.attrs = {}
for i,v in pairs(entry.attrs) do
hentry.attrs[i] = v
end
hentry.children = {}
hentry.parent = history
for i,field in pairs(env.xmlFindTags(entry,"field")) do
local hfield = {}
hfield.tag = "field"
hfield.attrs = {}
hfield.children = {}
hfield.parent = hfields
for i,v in pairs(field.attrs) do
hfield.attrs[i] = v
end
hfield.children[1] = {}
hfield.children[1].text = field.children[1].text
table.insert(hentry.children,hfield)
end
table.insert(history.children,hentry)
env.changed = true
end
end
end
return cmd