diff options
-rw-r--r-- | provisioning-model.lua | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index af96546..5787daa 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -720,13 +720,22 @@ mymodule.delete_template = function(self, delreq) if #tmp == 0 then delreq.value.filename.errtxt = "Template does not exist" else - logcall("delete_template "..filename) - -- Remove the template - sql = "DELETE FROM provisioning_options WHERE param_id=(SELECT param_id FROM provisioning_params WHERE name = 'template') AND value='"..provdb.escape(filename).."'" - runsqlcommand(sql) - -- Delete the template file - os.remove(filename) - delreq.errtxt = nil + -- Verify the template is not in use + sql = "SELECT group_id FROM param_groups_to_params WHERE param_id = (SELECT param_id FROM provisioning_params WHERE name='template') AND value='"..provdb.escape(filename).."'" + tmp = getselectresponse(sql) + sql = "SELECT device_id FROM provisioning_values WHERE param_id = (SELECT param_id FROM provisioning_params WHERE name='template') AND value='"..provdb.escape(filename).."'" + local tmp2 = getselectresponse(sql) + if #tmp>0 or #tmp2>0 then + delreq.value.filename.errtxt = "Template in use" + else + logcall("delete_template "..filename) + -- Remove the template + sql = "DELETE FROM provisioning_options WHERE param_id=(SELECT param_id FROM provisioning_params WHERE name = 'template') AND value='"..provdb.escape(filename).."'" + runsqlcommand(sql) + -- Delete the template file + os.remove(filename) + delreq.errtxt = nil + end end if connected then databasedisconnect() end end) |