Update languages.lua
This commit is contained in:
parent
1085ef9093
commit
85e8f8cd83
|
|
@ -1,6 +1,6 @@
|
|||
-- xml_handler.lua
|
||||
-- Part of FusionPBX
|
||||
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
|
||||
-- Copyright (C) 2013-2018 Mark J Crane <markjcrane@fusionpbx.com>
|
||||
-- All rights reserved.
|
||||
--
|
||||
-- Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
-- notice, this list of conditions and the following disclaimer in the
|
||||
-- documentation and/or other materials provided with the distribution.
|
||||
--
|
||||
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
|
|
@ -33,39 +33,26 @@
|
|||
--set the default
|
||||
continue = true;
|
||||
|
||||
--additional information
|
||||
--event_calling_function = params:getHeader("Event-Calling-Function");
|
||||
|
||||
--show the params in the console
|
||||
--if (params:serialize() ~= nil) then
|
||||
-- freeswitch.consoleLog("notice", "[xml_handler-languages.lua] Params:\n" .. params:serialize() .. "\n");
|
||||
--end
|
||||
|
||||
--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");
|
||||
--get the cache
|
||||
local cache = require "resources.functions.cache"
|
||||
local language_cache_key = "languages:" .. language..":" .. macro_name;
|
||||
XML_STRING, err = cache.get(language_cache_key)
|
||||
|
||||
--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..":" .. 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";
|
||||
continue = true;
|
||||
else
|
||||
source = "cache";
|
||||
continue = true;
|
||||
end
|
||||
else
|
||||
XML_STRING = "";
|
||||
source = "database";
|
||||
continue = true;
|
||||
end
|
||||
|
||||
--show the params in the console
|
||||
--if (params:serialize() ~= nil) then
|
||||
-- freeswitch.consoleLog("notice", "[xml_handler-languages.lua] Params:\n" .. params:serialize() .. "\n");
|
||||
--end
|
||||
|
||||
--build the XML string from the database
|
||||
if (source == "database") then
|
||||
--build the XML string from the database
|
||||
if not XML_STRING then
|
||||
|
||||
--connect to the database
|
||||
local Database = require "resources.functions.database";
|
||||
|
|
@ -174,41 +161,36 @@
|
|||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
end
|
||||
|
||||
--set the cache
|
||||
if (domain_name) then
|
||||
result = trim(api:execute("memcache", "set languages:" .. language .. ":" .. macro_name .." '"..XML_STRING:gsub("'", "'").."' "..expire["languages"]));
|
||||
local ok, err = cache.set(language_cache_key, XML_STRING, expire["acl"]);
|
||||
if debug["cache"] then
|
||||
if ok then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] " .. language_cache_key .. " stored in the cache\n");
|
||||
else
|
||||
freeswitch.consoleLog("warning", "[xml_handler] " .. language_cache_key .. " can not be stored in the cache: " .. tostring(err) .. "\n");
|
||||
end
|
||||
end
|
||||
|
||||
--send the xml to the console
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] " .. language_cache_key .. " source: database\n");
|
||||
end
|
||||
else
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] " .. language_cache_key .. " source: cache\n");
|
||||
end
|
||||
end --if XML_STRING
|
||||
|
||||
--send the xml to the console
|
||||
if (debug["xml_string"]) then
|
||||
local file = assert(io.open(temp_dir .. "/xml_handler-" .. language .. "-" .. macro_name ..".xml", "w"));
|
||||
local file = assert(io.open(temp_dir .. "/acl.conf.xml", "w"));
|
||||
file:write(XML_STRING);
|
||||
file:close();
|
||||
end
|
||||
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] languages:" .. language .. ":" .. macro_name .." source: database\n");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--get the XML string from the cache
|
||||
if (source == "cache") then
|
||||
--replace the ' back to a single quote
|
||||
if (XML_STRING) then
|
||||
XML_STRING = XML_STRING:gsub("'", "'");
|
||||
end
|
||||
|
||||
--send to the console
|
||||
if (debug["cache"]) then
|
||||
if (XML_STRING) then
|
||||
freeswitch.consoleLog("notice", "[xml_handler] language:" .. language .. ":" .. macro_name .." source: memcache \n");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--if the macro does not exist send "not found", don't cache the not found
|
||||
if (XML_STRING == nil or trim(XML_STRING) == "-ERR NOT FOUND") then
|
||||
XML_STRING = [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue