diff options
author | Ted Trask <ttrask01@yahoo.com> | 2017-01-25 20:28:24 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2017-02-22 22:46:11 +0000 |
commit | 1709d27afda0c4d7aa5a9330701d080d5a2260e1 (patch) | |
tree | 7c9b52f99d731aaaa9bfdb6ea77862d781b59e05 | |
parent | 8a5e6ab7b1945650832b5667e76a4a3d00be7e65 (diff) | |
download | acf-provisioning-1709d27afda0c4d7aa5a9330701d080d5a2260e1.tar.bz2 acf-provisioning-1709d27afda0c4d7aa5a9330701d080d5a2260e1.tar.xz |
Prevent deletion of template if in use
(cherry picked from commit 2f8246dc8b9a0341ca9451f1a20ffe296e76a0be)
-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 cd9e68a..09b276b 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) |