This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Create Schedule by Script
#4
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)
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')
Reply


Messages In This Thread
Create Schedule by Script - by DGrandes - 04.01.2022, 11:36
RE: Create Schedule by Script - by admin - 04.01.2022, 16:21
RE: Create Schedule by Script - by DGrandes - 05.01.2022, 07:51
RE: Create Schedule by Script - by admin - 05.01.2022, 08:41

Forum Jump: