mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Update languages.lua
When handling phrases get the specific phrase instead of all of them. Remove the code that tried to build the XML from the file system. Replace it with a 'not found' response so that FreeSWITCH will check the filesystem for the XML of the phrase that was not found.
This commit is contained in:
@@ -27,12 +27,16 @@
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
--general functions
|
||||
require "resources.functions.is_uuid";
|
||||
|
||||
--set the default
|
||||
continue = true;
|
||||
|
||||
--get the action
|
||||
--action = params:getHeader("action");
|
||||
language = params:getHeader("lang");
|
||||
macro_name = params:getHeader("macro_name");
|
||||
|
||||
--additional information
|
||||
--event_calling_function = params:getHeader("Event-Calling-Function");
|
||||
@@ -40,7 +44,7 @@
|
||||
--determine the correction action to perform
|
||||
--get the cache
|
||||
if (trim(api:execute("module_exists", "mod_memcache")) == "true") then
|
||||
XML_STRING = trim(api:execute("memcache", "get languages:" .. language));
|
||||
XML_STRING = trim(api:execute("memcache", "get languages:" .. language..":" .. macro_name));
|
||||
--freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. XML_STRING .. "\n");
|
||||
if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then
|
||||
source = "database";
|
||||
@@ -62,6 +66,7 @@
|
||||
|
||||
--build the XML string from the database
|
||||
if (source == "database") then
|
||||
|
||||
--database connection
|
||||
if (continue) then
|
||||
--connect to the database
|
||||
@@ -94,115 +99,100 @@
|
||||
|
||||
--set the xml array and then concatenate the array to a string
|
||||
if (continue) then
|
||||
--build the xml
|
||||
local xml = {}
|
||||
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
|
||||
table.insert(xml, [[<document type="freeswitch/xml">]]);
|
||||
table.insert(xml, [[ <section name="languages">]]);
|
||||
table.insert(xml, [[ <language name="]]..language..[[" say-module="]]..language..[[" sound-prefix="]]..sounds_dir..[[/]]..language..[[/us/callie" tts-engine="cepstral" tts-voice="callie">]]);
|
||||
table.insert(xml, [[ <phrases>]]);
|
||||
table.insert(xml, [[ <macros>]]);
|
||||
|
||||
sql = "SELECT * FROM v_phrases as p, v_phrase_details as d ";
|
||||
sql = sql .. "WHERE d.domain_uuid = '" .. domain_uuid .. "' ";
|
||||
sql = sql .. "AND p.phrase_language like '".. language .."%' ";
|
||||
sql = sql .. "AND p.phrase_uuid = d.phrase_uuid ";
|
||||
sql = sql .. "AND p.phrase_enabled = 'true' ";
|
||||
sql = sql .. "ORDER BY d.domain_uuid, p.phrase_uuid, d.phrase_detail_order ASC ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
end
|
||||
previous_phrase_uuid = "";
|
||||
match_tag = "open";
|
||||
x = 0;
|
||||
dbh:query(sql, function(row)
|
||||
--phrase_uuid,domain_uuid,phrase_name,phrase_language
|
||||
--phrase_description,phrase_enabled,phrase_detail_uuid
|
||||
--phrase_detail_group,phrase_detail_tag,phrase_detail_pattern
|
||||
--phrase_detail_function,phrase_detail_data,phrase_detail_method
|
||||
--phrase_detail_type,phrase_detail_order
|
||||
if (previous_phrase_uuid ~= row.phrase_uuid) then
|
||||
-- if macro_name is a uuid get from the phrase details
|
||||
if (is_uuid(macro_name)) then
|
||||
--define the xml table
|
||||
local xml = {}
|
||||
|
||||
--get hte xml
|
||||
table.insert(xml, [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>]]);
|
||||
table.insert(xml, [[<document type="freeswitch/xml">]]);
|
||||
table.insert(xml, [[ <section name="languages">]]);
|
||||
table.insert(xml, [[ <language name="]]..language..[[" say-module="]]..language..[[" sound-prefix="]]..sounds_dir..[[/]]..language..[[/us/callie" tts-engine="cepstral" tts-voice="callie">]]);
|
||||
table.insert(xml, [[ <phrases>]]);
|
||||
table.insert(xml, [[ <macros>]]);
|
||||
|
||||
sql = "SELECT * FROM v_phrases as p, v_phrase_details as d ";
|
||||
sql = sql .. "WHERE d.domain_uuid = '" .. domain_uuid .. "' ";
|
||||
sql = sql .. "AND p.phrase_uuid = '".. macro_name .."' ";
|
||||
sql = sql .. "AND p.phrase_language = '".. language .."' ";
|
||||
sql = sql .. "AND p.phrase_uuid = d.phrase_uuid ";
|
||||
sql = sql .. "AND p.phrase_enabled = 'true' ";
|
||||
sql = sql .. "ORDER BY d.domain_uuid, p.phrase_uuid, d.phrase_detail_order ASC ";
|
||||
-- if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n");
|
||||
-- end
|
||||
previous_phrase_uuid = "";
|
||||
match_tag = "open";
|
||||
x = 0;
|
||||
dbh:query(sql, function(row)
|
||||
--phrase_uuid,domain_uuid,phrase_name,phrase_language
|
||||
--phrase_description,phrase_enabled,phrase_detail_uuid
|
||||
--phrase_detail_group,phrase_detail_tag,phrase_detail_pattern
|
||||
--phrase_detail_function,phrase_detail_data,phrase_detail_method
|
||||
--phrase_detail_type,phrase_detail_order
|
||||
if (previous_phrase_uuid ~= row.phrase_uuid) then
|
||||
if (x > 0) then
|
||||
table.insert(xml, [[ </match>]]);
|
||||
table.insert(xml, [[ </input>]]);
|
||||
table.insert(xml, [[ </macro>]]);
|
||||
end
|
||||
table.insert(xml, [[ <macro name="]]..row.phrase_uuid..[[">]]);
|
||||
table.insert(xml, [[ <input pattern=\"(.*)\">]]);
|
||||
table.insert(xml, [[ <match>]]);
|
||||
match_open_tag = true
|
||||
end
|
||||
table.insert(xml, [[ <action function="]]..row.phrase_detail_function..[[" data="]]..row.phrase_detail_data..[["/>]]);
|
||||
previous_phrase_uuid = row.phrase_uuid;
|
||||
x = x + 1;
|
||||
end);
|
||||
if (x > 0) then
|
||||
table.insert(xml, [[ </match>]]);
|
||||
table.insert(xml, [[ </input>]]);
|
||||
table.insert(xml, [[ </macro>]]);
|
||||
end
|
||||
table.insert(xml, [[ <macro name="]]..row.phrase_uuid..[[">]]);
|
||||
table.insert(xml, [[ <input pattern=\"(.*)\">]]);
|
||||
table.insert(xml, [[ <match>]]);
|
||||
match_open_tag = true
|
||||
end
|
||||
table.insert(xml, [[ <action function="]]..row.phrase_detail_function..[[" data="]]..row.phrase_detail_data..[["/>]]);
|
||||
previous_phrase_uuid = row.phrase_uuid;
|
||||
x = x + 1;
|
||||
end);
|
||||
if (x > 0) then
|
||||
table.insert(xml, [[ </match>]]);
|
||||
table.insert(xml, [[ </input>]]);
|
||||
table.insert(xml, [[ </macro>]]);
|
||||
table.insert(xml, [[ </macros>]]);
|
||||
|
||||
--output xml & close previous file
|
||||
table.insert(xml, [[ </phrases>]]);
|
||||
table.insert(xml, [[ </language>]]);
|
||||
table.insert(xml, [[ </section>]]);
|
||||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
end
|
||||
|
||||
--if nil do nt include language xml from the file system the phrases directory is not set in default settings - category: switch name: phrases_dir or its false
|
||||
--it also can be nil if config.lua is not writable so that it can be defined in it
|
||||
if (phrases_dir ~= nil) then
|
||||
--read root xml language file, parse included xml files
|
||||
local xml_file_paths = {}
|
||||
local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r");
|
||||
if (file_handle ~= nil) then
|
||||
for file_line in file_handle:lines() do
|
||||
if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then
|
||||
pos_beg = string.find(file_line, 'cmd="include" data="', 0, true) + 20;
|
||||
pos_end = string.find(file_line, '"/>', 0, true) - 1;
|
||||
xml_file_path = string.sub(file_line, pos_beg, pos_end);
|
||||
table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path);
|
||||
--freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n");
|
||||
end
|
||||
end
|
||||
file_handle:close();
|
||||
end
|
||||
--iterate array of file paths, get contents of other xml macro files
|
||||
for key, xml_file_path in pairs(xml_file_paths) do
|
||||
if (file_exists(xml_file_path)) then
|
||||
xml_file = io.open(xml_file_path, "r");
|
||||
if (xml_file ~= nil) then
|
||||
xml_file_content = xml_file:read("*a");
|
||||
xml_file_content = string.gsub(xml_file_content, "<include>", '');
|
||||
xml_file_content = string.gsub(xml_file_content, "</include>", '');
|
||||
table.insert(xml, xml_file_content);
|
||||
--freeswitch.consoleLog("notice", "file contents...\n\n"..xml_file_content.."\n");
|
||||
end
|
||||
xml_file:close();
|
||||
end
|
||||
end
|
||||
--send not found
|
||||
if (XML_STRING == nil) then
|
||||
XML_STRING = [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="freeswitch/xml">
|
||||
<section name="result">
|
||||
<result status="not found" />
|
||||
</section>
|
||||
</document>]];
|
||||
end
|
||||
|
||||
--output xml & close previous file
|
||||
table.insert(xml, [[ </macros>]]);
|
||||
table.insert(xml, [[ </phrases>]]);
|
||||
table.insert(xml, [[ </language>]]);
|
||||
table.insert(xml, [[ </section>]]);
|
||||
table.insert(xml, [[</document>]]);
|
||||
XML_STRING = table.concat(xml, "\n");
|
||||
--freeswitch.consoleLog("notice", "[xml_handler] language " .. XML_STRING .. " \n")
|
||||
--log to the console
|
||||
--freeswitch.consoleLog("notice", "[xml_handler] language " .. XML_STRING .. " \n");
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--set the cache
|
||||
if (domain_name) then
|
||||
result = trim(api:execute("memcache", "set languages:" .. language .. " '"..XML_STRING:gsub("'", "'").."' "..expire["languages"]));
|
||||
result = trim(api:execute("memcache", "set languages:" .. language .. ":" .. macro_name .." '"..XML_STRING:gsub("'", "'").."' "..expire["languages"]));
|
||||
end
|
||||
|
||||
--send the xml to the console
|
||||
if (debug["xml_string"]) then
|
||||
local file = assert(io.open(temp_dir .. "/xml_handler-" .. language .. ".xml", "w"));
|
||||
local file = assert(io.open(temp_dir .. "/xml_handler-" .. language .. "-" .. macro_name ..".xml", "w"));
|
||||
file:write(XML_STRING);
|
||||
file:close();
|
||||
end
|
||||
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] languages:" .. language .. " source: database\n");
|
||||
freeswitch.consoleLog("notice", "[xml_handler] languages:" .. language .. ":" .. macro_name .." source: database\n");
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -217,7 +207,7 @@
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
if (XML_STRING) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] language:" .. language .. " source: memcache \n");
|
||||
freeswitch.consoleLog("notice", "[xml_handler] language:" .. language .. ":" .. macro_name .." source: memcache \n");
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -236,4 +226,4 @@
|
||||
--send the xml to the console
|
||||
if (debug["xml_string"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] XML_STRING: \n" .. XML_STRING .. "\n");
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user