Add. Use params in fax/queue/retry.lua (#2148)

This commit is contained in:
Alexey Melnichuk 2016-11-22 21:09:03 +03:00 committed by FusionPBX
parent 7cf5b67d92
commit 043c01579a
1 changed files with 91 additions and 69 deletions

View File

@ -9,6 +9,12 @@
local Tasks = require "app.fax.resources.scripts.queue.tasks" local Tasks = require "app.fax.resources.scripts.queue.tasks"
local send_mail = require "resources.functions.send_mail" local send_mail = require "resources.functions.send_mail"
--include json library
local json
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end
local fax_task_uuid = env:getHeader('fax_task_uuid') local fax_task_uuid = env:getHeader('fax_task_uuid')
if not fax_task_uuid then if not fax_task_uuid then
log.warning("No [fax_task_uuid] channel variable") log.warning("No [fax_task_uuid] channel variable")
@ -204,42 +210,49 @@
"fax_retry_limit"; "fax_retry_limit";
"fax_retry_sleep"; "fax_retry_sleep";
"fax_uri"; "fax_uri";
"fax_date";
"fax_epoch"; "fax_epoch";
} }
local values = { local params = {
"'"..uuid .. "'"; fax_log_uuid = uuid;
"'"..domain_uuid .. "'"; domain_uuid = domain_uuid;
opt(fax_uuid); fax_uuid = fax_uuid or dbh.NULL;
opt(fax_success); fax_success = fax_success or dbh.NULL;
opt(fax_result_code); fax_result_code = fax_result_code or dbh.NULL;
opt(fax_result_text); fax_result_text = fax_result_text or dbh.NULL;
opt(fax_file); fax_file = fax_file or dbh.NULL;
opt(fax_ecm_used); fax_ecm_used = fax_ecm_used or dbh.NULL;
opt(fax_local_station_id); fax_local_station_id = fax_local_station_id or dbh.NULL;
opt(fax_document_transferred_pages, "'0'"); fax_document_transferred_pages = fax_document_transferred_pages or "'0'";
opt(fax_document_total_pages, "'0'"); fax_document_total_pages = fax_document_total_pages or "'0'";
opt(fax_image_resolution); fax_image_resolution = fax_image_resolution or dbh.NULL;
opt(fax_image_size); fax_image_size = fax_image_size or dbh.NULL;
opt(fax_bad_rows); fax_bad_rows = fax_bad_rows or dbh.NULL;
opt(fax_transfer_rate); fax_transfer_rate = fax_transfer_rate or dbh.NULL;
opt(fax_retry_attempts); fax_retry_attempts = fax_retry_attempts or dbh.NULL;
opt(fax_retry_limit); fax_retry_limit = fax_retry_limit or dbh.NULL;
opt(fax_retry_sleep); fax_retry_sleep = fax_retry_sleep or dbh.NULL;
opt(fax_uri); fax_uri = fax_uri or dbh.NULL;
now_sql(); fax_epoch = os.time();
"'"..os.time().."' ";
} }
local sql = "insert into v_fax_logs(" .. table.concat(fields, ",") .. ")" .. local values = ":" .. table.concat(fields, ",:")
"values(" .. table.concat(values, ",") .. ")" fields = table.concat(fields, ",") .. ",fax_date"
if (debug["sql"]) then if database["type"] == "sqlite" then
log.noticef("SQL: %s", sql); params.fax_date = os.date("%Y-%m-%d %X");
values = values .. ",:fax_date"
else
values = values .. ",now()"
end end
dbh:query(sql); local sql = "insert into v_fax_logs(" .. fields .. ")values(" .. values .. ")"
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params, dbh.NULL));
end
dbh:query(sql, params);
end end
-- add the fax files -- add the fax files
@ -259,49 +272,58 @@
-- build SQL -- build SQL
local sql do local sql do
sql = {
"insert into v_fax_files("; local fields = {
"fax_file_uuid"; ","; "fax_file_uuid";
"fax_uuid"; ","; "fax_uuid";
"fax_mode"; ","; "fax_mode";
"fax_destination"; ","; "fax_destination";
"fax_file_type"; ","; "fax_file_type";
"fax_file_path"; ","; "fax_file_path";
"fax_caller_id_name"; ","; "fax_caller_id_name";
"fax_caller_id_number"; ","; "fax_caller_id_number";
"fax_date"; ","; "fax_epoch";
"fax_epoch"; ","; "fax_base64";
"fax_base64"; ","; "domain_uuid";
"domain_uuid"; " ";
") values (";
opt(uuid); ",";
opt(fax_uuid); ",";
"'tx'"; ",";
opt(sip_to_user); ",";
"'tif'"; ",";
opt(fax_file); ",";
opt(origination_caller_id_name); ",";
opt(origination_caller_id_number); ",";
now_sql(); ",";
"'" .. os.time() .. "'"; ",";
opt(fax_base64); ",";
opt(domain_uuid); " ";
")"
} }
sql = table.concat(sql, "\n"); local params = {
if (debug["sql"]) then fax_file_uuid = uuid;
log.noticef("SQL: %s", sql); fax_uuid = fax_uuid or dbh.NULL;
end fax_mode = "tx";
end fax_destination = sip_to_user or dbh.NULL;
fax_file_type = "tif";
fax_file_path = fax_file or dbh.NULL;
fax_caller_id_name = origination_caller_id_name or dbh.NULL;
fax_caller_id_number = origination_caller_id_number or dbh.NULL;
fax_epoch = os.time();
fax_base64 = fax_base64 or dbh.NULL;
domain_uuid = domain_uuid or dbh.NULL;
}
if storage_type == "base64" then local values = ":" .. table.concat(fields, ",:")
local Database = require "resources.functions.database" fields = table.concat(fields, ",") .. ",fax_date"
local dbh = Database.new('system', 'base64');
dbh:query(sql); if database["type"] == "sqlite" then
dbh:release(); params.fax_date = os.date("%Y-%m-%d %X");
else values = values .. ",:fax_date"
result = dbh:query(sql) else
values = values .. ",now()"
end
local sql = "insert into v_fax_files(" .. fields .. ")values(" .. values .. ")"
if (debug["sql"]) then
log.noticef("SQL: %s; params: %s", sql, json.encode(params, dbh.NULL));
end
if storage_type == "base64" then
local dbh = Database.new('system', 'base64');
dbh:query(sql, params);
dbh:release();
else
dbh:query(sql, params)
end
end end
end end
@ -390,7 +412,7 @@
os.remove(fax_file); os.remove(fax_file);
end end
end
end end
end end
end