diff options
author | Ted Trask <ttrask01@yahoo.com> | 2017-11-30 14:56:10 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2017-11-30 14:56:10 +0000 |
commit | 5babbc852f4f5a6b602704c6aaf862287d893c63 (patch) | |
tree | b459fef40d7eb4a3fbf1ef8ceaaa740fc5590510 /provisioning-model.lua | |
parent | ed6cd04b89f247ef0d1ff227b5b50a6136639b8f (diff) | |
download | acf-provisioning-5babbc852f4f5a6b602704c6aaf862287d893c63.tar.bz2 acf-provisioning-5babbc852f4f5a6b602704c6aaf862287d893c63.tar.xz |
Add history log entries for calls that modify data
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r-- | provisioning-model.lua | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index c46e058..24862aa 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -35,34 +35,6 @@ local functions -- ################################################################################ -- LOCAL FUNCTIONS -local logme = function(message) - local userid = "-" - if mymodule.sessiondata and mymodule.sessiondata.userinfo and mymodule.sessiondata.userinfo.userid then - userid = tostring(mymodule.sessiondata.userinfo.userid) - end - if provdb.isconnected() then - local sql = string.format("INSERT INTO dbhistlog VALUES ('now', '%s', '%s')", provdb.escape(message), provdb.escape(userid)) - provdb.runsqlcommand(sql, true) - end -end - --- Delete history log information from more than a month ago -local groomdbhistlog = function() - if provdb.isconnected() then - local sql = "DELETE FROM dbhistlog WHERE logdatetime < (now() - INTERVAL '1 month')" - provdb.runsqlcommand(sql, true) - logme("removed " .. res .. " old dbhistlog lines") - end -end - -local function logcall(fn) - if mymodule.sessiondata and mymodule.sessiondata.userinfo and mymodule.sessiondata.userinfo.userid then - mymodule.logevent("acf-provisioning: "..tostring(fn).." by "..tostring(mymodule.sessiondata.userinfo.userid)) - else - mymodule.logevent("acf-provisioning: "..tostring(fn)) - end -end - -- This function is used by scripts, do not change prototype local runsqlcommand = function(sql) mymodule.logevent(sql) @@ -190,6 +162,42 @@ local handlesqlexception = function(connected, err) end end +-- Delete history log information from more than a month ago +local groomdbhistlog = function() + if provdb.isconnected() then + local sql = "DELETE FROM dbhistlog WHERE logdatetime < (now() - INTERVAL '1 month')" + provdb.runsqlcommand(sql, true) + end +end + +local logme = function(message) + local userid = "-" + if mymodule.sessiondata and mymodule.sessiondata.userinfo and mymodule.sessiondata.userinfo.userid then + userid = tostring(mymodule.sessiondata.userinfo.userid) + end + + local connected + local res, err = pcall(function() + connected = databaseconnect() + local sql = string.format("INSERT INTO dbhistlog VALUES ('now', '%s', '%s')", provdb.escape(message), provdb.escape(userid)) + provdb.runsqlcommand(sql, true) + groomdbhistlog() + if connected then databasedisconnect() end + end) + if not res and err then + handlesqlexception(connected, err) + end +end + +local function logcall(fn) + if mymodule.sessiondata and mymodule.sessiondata.userinfo and mymodule.sessiondata.userinfo.userid then + mymodule.logevent("acf-provisioning: "..tostring(fn).." by "..tostring(mymodule.sessiondata.userinfo.userid)) + else + mymodule.logevent("acf-provisioning: "..tostring(fn)) + end + logme(fn) +end + local validateparam validateparam = function(p, allowdefault) if p.type == "group" then |