summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2017-01-25 20:28:24 +0000
committerTed Trask <ttrask01@yahoo.com>2017-01-25 20:28:24 +0000
commit2f8246dc8b9a0341ca9451f1a20ffe296e76a0be (patch)
treea50dbd8c5039626ca2a2e04d335453e4c694b5cb
parentd749574edabd2f8782a84bc46d953208085fa62f (diff)
downloadacf-provisioning-2f8246dc8b9a0341ca9451f1a20ffe296e76a0be.tar.bz2
acf-provisioning-2f8246dc8b9a0341ca9451f1a20ffe296e76a0be.tar.xz
Prevent deletion of template if in use
-rw-r--r--provisioning-model.lua23
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)