summaryrefslogtreecommitdiffstats
path: root/provisioning-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r--provisioning-model.lua64
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