summaryrefslogtreecommitdiffstats
path: root/provisioning-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r--provisioning-model.lua28
1 files changed, 12 insertions, 16 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index f1b5dd2..3c4dfe7 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -1218,10 +1218,6 @@ mymodule.update_group = function(self, group, action, create)
"FROM (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) JOIN classes_to_param_groups t2g USING (class_id)) "..
"WHERE t2g.group_id='"..provdb.escape(group.value.group_id.value).."'"
devices = getselectresponse(sql)
- -- Make sure the current params are saved for each device
- for i,d in ipairs(devices) do
- if not saved_device_params[d.device_id] then get_device_params(d.device_id) end
- end
end
end
if success then
@@ -1256,15 +1252,17 @@ mymodule.update_group = function(self, group, action, create)
sql = "INSERT INTO param_groups_to_params VALUES('"..provdb.escape(group.value.group_id.value).."', '"..provdb.escape(p).."', "..(reverseoverride[p] or "null")..", '"..provdb.escape(tostring(reverseeditable[p] ~= nil)).."')"
runsqlcommand(sql)
end
+ end
+ if connected then databasedisconnect() end
+ -- Update the devices after databasedisconnect so device failure doesn't rollback the change
+ if success then
-- Notify the devices that their params might have changed
for i,d in ipairs(devices) do
- local tmp = saved_device_params[d.device_id]
- local p = get_device_params(d.device_id)
- callscript(updatedeviceparamsscriptfile, p, tmp)
+ local r = set_device_params(get_device_params(d.device_id, false), false)
+ if r.errtxt then self.logevent("Failed to update params for device "..d.device_id..": "..r.errtxt) end
end
end
- if connected then databasedisconnect() end
end)
if not res and err then
handlesqlexception(connected)
@@ -1421,10 +1419,6 @@ mymodule.update_param = function(self, param, action, create)
"JOIN provisioning_groups g USING(group_id) JOIN param_groups_to_params g2p USING(group_id))"..
"WHERE g2p.param_id='"..provdb.escape(param.value.param_id.value).."'"
devices = getselectresponse(sql)
- -- Make sure the current params are saved for each device
- for i,d in ipairs(devices) do
- if not saved_device_params[d.device_id] then get_device_params(d.device_id) end
- end
end
end
if success then
@@ -1443,15 +1437,17 @@ mymodule.update_param = function(self, param, action, create)
sql = "UPDATE provisioning_params SET (name, type, label, descr, value, seq, regexp, validate) = ('"..provdb.escape(param.value.name.value).."', '"..provdb.escape(param.value.type.value).."', '"..provdb.escape(param.value.label.value).."', '"..provdb.escape(param.value.descr.value).."', '"..provdb.escape(param.value.value.value).."', '"..provdb.escape(param.value.seq.value).."', '"..provdb.escape(param.value.regexp.value).."', '"..provdb.escape(format.dostounix(param.value.validate.value)).."') WHERE param_id='"..provdb.escape(param.value.param_id.value).."'"
runsqlcommand(sql)
end
+ end
+ if connected then databasedisconnect() end
+ -- Update the devices after databasedisconnect so device failure doesn't rollback the change
+ if success then
-- Notify the devices that their params might have changed
for i,d in ipairs(devices) do
- local tmp = saved_device_params[d.device_id]
- local p = get_device_params(d.device_id)
- callscript(updatedeviceparamsscriptfile, p, tmp)
+ local r = set_device_params(get_device_params(d.device_id, false), false)
+ if r.errtxt then self.logevent("Failed to update params for device "..d.device_id..": "..r.errtxt) end
end
end
- if connected then databasedisconnect() end
end)
if not res and err then
handlesqlexception(connected)