diff options
author | Ted Trask <ttrask01@yahoo.com> | 2013-05-25 02:49:56 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2013-05-25 02:49:56 +0000 |
commit | 760335c35f5b104247e5d825129ee9261a76f0d1 (patch) | |
tree | 2154e2650820e40c5c90b22d6992098e6db14be3 | |
parent | 4912561d5332a96bc1921ca3a76ba74f8d118306 (diff) | |
download | acf-provisioning-760335c35f5b104247e5d825129ee9261a76f0d1.tar.bz2 acf-provisioning-760335c35f5b104247e5d825129ee9261a76f0d1.tar.xz |
Fix creation of param, param group, class, and class group
-rw-r--r-- | provisioning-model.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index 82ea33f..3efba54 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -588,7 +588,9 @@ update_class_group = function(self, group, action, create) sql = "SELECT class_group_id FROM provisioning_class_groups WHERE label='"..escape(group.value.label.value).."'" local tmp = getselectresponse(sql, true) if tmp and #tmp>0 then - group.value.class_group_id.value = tmp[1].class_group_id + group.value.class_group_id = cfe({value=tmp[1].class_group_id, label="Class Group ID", readonly=true, seq=1}) + else + error("Failed to insert class group", 0) end else sql = "UPDATE provisioning_class_groups SET (name, label, seq) = ('"..escape(group.value.name.value).."', '"..escape(group.value.label.value).."', '"..escape(group.value.seq.value).."') WHERE class_group_id='"..escape(group.value.class_group_id.value).."'" @@ -761,7 +763,9 @@ update_class = function(self, class, action, create) sql = "SELECT class_id FROM provisioning_classes WHERE class_group_id='"..escape(class.value.class_group_id.value).."' AND label='"..escape(class.value.label.value).."'" local tmp = getselectresponse(sql, true) if tmp and #tmp>0 then - class.value.class_id.value = tmp[1].class_id + class.value.class_id = cfe({value=tmp[1].class_id, label="Class ID", readonly=true, seq=1}) + else + error("Failed to insert class", 0) end else sql = "UPDATE provisioning_classes SET (class_group_id, label, seq) = ('"..escape(class.value.class_group_id.value).."', '"..escape(class.value.label.value).."', '"..escape(class.value.seq.value).."') WHERE class_id='"..escape(class.value.class_id.value).."'" @@ -972,7 +976,9 @@ update_group = function(self, group, action, create) sql = "SELECT group_id FROM provisioning_groups WHERE name='"..escape(group.value.name.value).."' AND label='"..escape(group.value.label.value).."'" local tmp = getselectresponse(sql, true) if tmp and #tmp>0 then - group.value.group_id.value = tmp[1].group_id + group.value.group_id = cfe({value=tmp[1].group_id, label="Group ID", readonly=true, seq=1}) + else + error("Failed to insert parameter group", 0) end else sql = "UPDATE provisioning_groups SET (name, label, seq) = ('"..escape(group.value.name.value).."', '"..escape(group.value.label.value).."', '"..escape(group.value.seq.value).."') WHERE group_id='"..escape(group.value.group_id.value).."'" @@ -1157,7 +1163,9 @@ update_param = function(self, param, action, create) sql = "SELECT param_id FROM provisioning_params WHERE name='"..escape(param.value.name.value).."' AND label='"..escape(param.value.label.value).."'" local tmp = getselectresponse(sql, true) if tmp and #tmp>0 then - param.value.param_id.value = tmp[1].param_id + param.value.param_id = cfe({value=tmp[1].param_id, label="Param ID", readonly=true, seq=1}) + else + error("Failed to insert parameter", 0); end else sql = "UPDATE provisioning_params SET (name, type, label, descr, value, seq, regexp, validate) = ('"..escape(param.value.name.value).."', '"..escape(param.value.type.value).."', '"..escape(param.value.label.value).."', '"..escape(param.value.descr.value).."', '"..escape(param.value.value.value).."', '"..escape(param.value.seq.value).."', '"..escape(param.value.regexp.value).."', '"..escape(format.dostounix(param.value.validate.value)).."') WHERE param_id='"..escape(param.value.param_id.value).."'" @@ -1556,13 +1564,11 @@ set_device_params = function(params, editable) local res, err = pcall(function() local connected = databaseconnect() success = validateparamcoded(params) - if not create then - local sql = "SELECT * FROM devices_to_classes WHERE device_id='"..escape(params.value.device_id.value).."' LIMIT 1" - local tmp = getselectresponse(sql) - if not tmp or #tmp == 0 then - success = false - errtxt = "Device does not exist" - end + local sql = "SELECT * FROM devices_to_classes WHERE device_id='"..escape(params.value.device_id.value).."' LIMIT 1" + local tmp = getselectresponse(sql) + if not tmp or #tmp == 0 then + success = false + errtxt = "Device does not exist" end if success then if not saved_device_params[params.value.device_id.value] then get_device_params(params.value.device_id.value) end |