Fix. Fetch correct arrays from settings. (#2162)
* Fix. Fetch correct arrays from settings. Add. Use params in `settings.lua` * Fix. array from domain settings overwrite entire array from default settings instead of appends it.
This commit is contained in:
committed by
FusionPBX
parent
928b1afb72
commit
915c5dea48
@@ -1,21 +1,25 @@
|
|||||||
|
|
||||||
--debug
|
|
||||||
debug["sql"] = false;
|
|
||||||
|
|
||||||
--define the trim function
|
--define the trim function
|
||||||
require "resources.functions.trim";
|
require "resources.functions.trim";
|
||||||
|
|
||||||
|
--include json library
|
||||||
|
local json
|
||||||
|
if (debug["sql"]) then
|
||||||
|
json = require "resources.functions.lunajson"
|
||||||
|
end
|
||||||
|
|
||||||
--get the domain_uuid
|
--get the domain_uuid
|
||||||
if (domain_uuid == nil) then
|
if (domain_uuid == nil) then
|
||||||
if (domain_name ~= nil) then
|
if (domain_name ~= nil) then
|
||||||
sql = "SELECT domain_uuid FROM v_domains ";
|
local sql = "SELECT domain_uuid FROM v_domains ";
|
||||||
sql = sql .. "WHERE domain_name = '" .. domain_name .."' ";
|
sql = sql .. "WHERE domain_name = :domain_name";
|
||||||
|
local params = {domain_name = domain_name};
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[conference] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[settings] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(rows)
|
dbh:query(sql, params, function(rows)
|
||||||
domain_uuid = string.lower(rows["domain_uuid"]);
|
domain_uuid = string.lower(rows["domain_uuid"]);
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,28 +49,28 @@
|
|||||||
function settings(domain_uuid)
|
function settings(domain_uuid)
|
||||||
|
|
||||||
--define the table
|
--define the table
|
||||||
array = {}
|
local array = {}
|
||||||
|
|
||||||
--get the default settings
|
--get the default settings
|
||||||
sql = "SELECT * FROM v_default_settings ";
|
local sql = "SELECT * FROM v_default_settings ";
|
||||||
sql = sql .. "WHERE default_setting_enabled = 'true' ";
|
sql = sql .. "WHERE default_setting_enabled = 'true' ";
|
||||||
sql = sql .. "AND default_setting_category is not null ";
|
sql = sql .. "AND default_setting_category is not null ";
|
||||||
sql = sql .. "AND default_setting_subcategory is not null ";
|
sql = sql .. "AND default_setting_subcategory is not null ";
|
||||||
sql = sql .. "AND default_setting_name is not null ";
|
sql = sql .. "AND default_setting_name is not null ";
|
||||||
sql = sql .. "AND default_setting_value is not null ";
|
sql = sql .. "AND default_setting_value is not null ";
|
||||||
sql = sql .. "ORDER BY default_setting_category, default_setting_subcategory ASC";
|
sql = sql .. "ORDER BY default_setting_category, default_setting_subcategory ASC";
|
||||||
|
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[settings] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
x = 1;
|
|
||||||
previous_category = '';
|
|
||||||
dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
--variables
|
--variables
|
||||||
setting_uuid = row.default_setting_uuid
|
local setting_uuid = row.default_setting_uuid
|
||||||
category = row.default_setting_category;
|
local category = row.default_setting_category;
|
||||||
subcategory = row.default_setting_subcategory;
|
local subcategory = row.default_setting_subcategory;
|
||||||
name = row.default_setting_name;
|
local name = row.default_setting_name;
|
||||||
value = row.default_setting_value;
|
local value = row.default_setting_value;
|
||||||
|
|
||||||
--add the category array
|
--add the category array
|
||||||
if (array[category] == nil) then
|
if (array[category] == nil) then
|
||||||
@@ -76,54 +80,41 @@
|
|||||||
--add the subcategory array
|
--add the subcategory array
|
||||||
if (array[category][subcategory] == nil) then
|
if (array[category][subcategory] == nil) then
|
||||||
array[category][subcategory] = {}
|
array[category][subcategory] = {}
|
||||||
x = 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
--add the subcategory array
|
|
||||||
if (array[category][subcategory][name] == nil) then
|
|
||||||
array[category][subcategory][name] = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the name and value
|
--set the name and value
|
||||||
if (name == "array") then
|
if (name == "array") then
|
||||||
array[category][subcategory][x] = {}
|
local t = array[category][subcategory]
|
||||||
array[category][subcategory][x] = value;
|
t[#t + 1] = value
|
||||||
else
|
else
|
||||||
if (value ~= nil) then
|
if (value ~= nil) then
|
||||||
array[category][subcategory][name] = value;
|
array[category][subcategory][name] = value;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the previous category
|
|
||||||
previous_category = category;
|
|
||||||
|
|
||||||
--set the previous subcategory
|
|
||||||
previous_subcategory = subcategory;
|
|
||||||
|
|
||||||
--increment the value of x
|
|
||||||
x = x + 1;
|
|
||||||
end);
|
end);
|
||||||
|
|
||||||
--get the domain settings
|
--get the domain settings
|
||||||
if (domain_uuid ~= nil) then
|
if (domain_uuid ~= nil) then
|
||||||
sql = "SELECT * FROM v_domain_settings ";
|
local sql = "SELECT * FROM v_domain_settings ";
|
||||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .. "' ";
|
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
|
||||||
sql = sql .. "AND domain_setting_enabled = 'true' ";
|
sql = sql .. "AND domain_setting_enabled = 'true' ";
|
||||||
sql = sql .. "AND domain_setting_category is not null ";
|
sql = sql .. "AND domain_setting_category is not null ";
|
||||||
sql = sql .. "AND domain_setting_subcategory is not null ";
|
sql = sql .. "AND domain_setting_subcategory is not null ";
|
||||||
sql = sql .. "AND domain_setting_name is not null ";
|
sql = sql .. "AND domain_setting_name is not null ";
|
||||||
sql = sql .. "AND domain_setting_value is not null ";
|
sql = sql .. "AND domain_setting_value is not null ";
|
||||||
sql = sql .. "ORDER BY domain_setting_category, domain_setting_subcategory ASC ";
|
sql = sql .. "ORDER BY domain_setting_category, domain_setting_subcategory ASC ";
|
||||||
|
local params = {domain_uuid = domain_uuid};
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[directory] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[settings] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
|
||||||
end
|
end
|
||||||
dbh:query(sql, function(row)
|
local last_category, last_subcategory
|
||||||
|
dbh:query(sql, params, function(row)
|
||||||
--variables
|
--variables
|
||||||
setting_uuid = row.domain_setting_uuid
|
local setting_uuid = row.domain_setting_uuid
|
||||||
category = row.domain_setting_category;
|
local category = row.domain_setting_category;
|
||||||
subcategory = row.domain_setting_subcategory;
|
local subcategory = row.domain_setting_subcategory;
|
||||||
name = row.domain_setting_name;
|
local name = row.domain_setting_name;
|
||||||
value = row.domain_setting_value;
|
local value = row.domain_setting_value;
|
||||||
|
|
||||||
--add the category array
|
--add the category array
|
||||||
if (array[category] == nil) then
|
if (array[category] == nil) then
|
||||||
@@ -133,30 +124,25 @@
|
|||||||
--add the subcategory array
|
--add the subcategory array
|
||||||
if (array[category][subcategory] == nil) then
|
if (array[category][subcategory] == nil) then
|
||||||
array[category][subcategory] = {}
|
array[category][subcategory] = {}
|
||||||
x = 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
--add the subcategory array
|
|
||||||
if (array[category][subcategory][name] == nil) then
|
|
||||||
array[category][subcategory][name] = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the name and value
|
--set the name and value
|
||||||
if (name == "array") then
|
if (name == "array") then
|
||||||
array[category][subcategory][x] = {}
|
local t = array[category][subcategory]
|
||||||
array[category][subcategory][x] = value;
|
-- overwrite entire array from default settings if needed
|
||||||
|
if last_category ~= category and last_subcategory ~= subcategory and t[1] then
|
||||||
|
t = {}
|
||||||
|
array[category][subcategory] = t
|
||||||
|
end
|
||||||
|
t[#t + 1] = value
|
||||||
else
|
else
|
||||||
if (value ~= nil) then
|
if (value ~= nil) then
|
||||||
array[category][subcategory][name] = value;
|
array[category][subcategory][name] = value;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the previous category
|
-- set last category
|
||||||
previous_category = category;
|
last_category, last_subcategory = category, subcategory
|
||||||
|
|
||||||
--set the previous subcategory
|
|
||||||
previous_subcategory = subcategory;
|
|
||||||
|
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -168,3 +154,6 @@
|
|||||||
--array = settings(domain_uuid);
|
--array = settings(domain_uuid);
|
||||||
--result = array['domain']['template']['name'];
|
--result = array['domain']['template']['name'];
|
||||||
--freeswitch.consoleLog("notice", result .. "\n");
|
--freeswitch.consoleLog("notice", result .. "\n");
|
||||||
|
--for i, ext in ipairs(array.fax.allowed_extension) do
|
||||||
|
-- freeswitch.consoleLog("notice", "allowed_extension #" .. i .. ": " .. ext .. "\n");
|
||||||
|
--end
|
||||||
|
|||||||
Reference in New Issue
Block a user