05.01.2022, 08:41
Use this function to duplicate a scheduler.
Arguments:
1. id - source scheduler ID
2. address - object to map the new scheduler to
3. name - new scheduler name (optional)
Arguments:
1. id - source scheduler ID
2. address - object to map the new scheduler to
3. name - new scheduler name (optional)
Code:
function copyscheduler(id, address, name)
local scheduler = db:getrow('SELECT * FROM schedulers WHERE id=?', id)
local events = db:getall('SELECT * FROM scheduler_events WHERE scheduler=?', id)
if scheduler then
scheduler.id = nil
scheduler.name = name or (scheduler.name .. ' copy')
scheduler.object = buslib.encodega(address)
db:insert('schedulers', scheduler)
local newid = db:getlastautoid()
for _, event in ipairs(events) do
event.id = nil
event.scheduler = newid
db:insert('scheduler_events', event)
end
end
io.writefile('/tmp/lm-scheduler-clear', '')
end
-- duplicate scheduler ID 1, map it to 1/1/1 and set name to 'test2'
copyscheduler(1, '1/1/1', 'test2')