Use SQL to cast to boolean

This commit is contained in:
FusionPBX
2025-09-21 14:43:17 -06:00
committed by GitHub
parent 6df7fdd616
commit 573903147a
6 changed files with 98 additions and 55 deletions

View File

@@ -543,7 +543,26 @@
pin_number = get_pin_number(domain_uuid, conference_center_greeting);
end
if (pin_number ~= nil) then
local sql = [[SELECT * FROM v_conference_rooms
local sql = [[SELECT
conference_room_uuid,
conference_room_name,
cast(record as text),
profile,
max_members,
cast(wait_mod as text),
cast(moderator_endconf as text),
moderator_pin,
participant_pin,
cast(announce_name as text),
cast(announce_count as text),
cast(announce_recording as text),
cast(mute as text),
cast(sounds as text),
created,
created_by,
cast(enabled as text),
description
FROM v_conference_rooms
WHERE domain_uuid = :domain_uuid
AND conference_center_uuid = :conference_center_uuid
AND (moderator_pin = :pin_number or participant_pin = :pin_number)
@@ -560,7 +579,6 @@
dbh:query(sql, params, function(row)
conference_room_uuid = string.lower(row["conference_room_uuid"]);
conference_room_name = string.lower(row["conference_room_name"]);
--meeting_uuid = string.lower(row["meeting_uuid"]);
record = row["record"];
profile = string.lower(row["profile"]);
max_members = row["max_members"];
@@ -582,18 +600,6 @@
freeswitch.consoleLog("INFO","conference_room_uuid: " .. conference_room_uuid .. "\n");
end
--set the boolean settings to a true or false string
record = record and "true" or "false";
wait_mod = wait_mod and "true" or "false";
sounds = sounds and "true" or "false";
mute = mute and "true" or "false";
enabled = enabled and "true" or "false";
announce_name = announce_name and "true" or "false";
announce_count = announce_count and "true" or "false";
announce_recording = announce_recording and "true" or "false";
moderator_endconf = moderator_endconf and "true" or "false";
--set the member type
if (pin_number == moderator_pin) then
member_type = "moderator";

View File

@@ -16,15 +16,31 @@ function feature_event_notify.get_db_values(user, domain_name)
end);
--get extension information
local sql = "select * from v_extensions ";
local sql = "select ";
sql = sql .. " extension_uuid, ";
sql = sql .. " extension, ";
sql = sql .. " number_alias, ";
sql = sql .. " accountcode, ";
sql = sql .. " follow_me_uuid, ";
sql = sql .. " cast(do_not_disturb as text), ";
sql = sql .. " cast(forward_all_enabled as text), ";
sql = sql .. " forward_all_destination, ";
sql = sql .. " cast(forward_busy_enabled as text), ";
sql = sql .. " forward_busy_destination, ";
sql = sql .. " cast(forward_no_answer_enabled as text), ";
sql = sql .. " forward_no_answer_destination, ";
sql = sql .. " cast(forward_user_not_registered_enabled as text), ";
sql = sql .. " forward_user_not_registered_destination, ";
sql = sql .. " toll_allow, ";
sql = sql .. " call_timeout ";
sql = sql .. "from v_extensions ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and (extension = :extension or number_alias = :extension) ";
sql = sql .. "and enabled true ";
local params = {domain_uuid = domain_uuid, extension = user};
-- if (debug["sql"]) then
-- freeswitch.consoleLog("notice", "[feature_event] " .. sql .. "; params:" .. json.encode(params) .. "\n");
-- end
-- if (debug["sql"]) then
-- freeswitch.consoleLog("notice", "[feature_event] " .. sql .. "; params:" .. json.encode(params) .. "\n");
-- end
dbh:query(sql, params, function(row)
extension_uuid = row.extension_uuid;
extension = row.extension;
@@ -47,12 +63,6 @@ function feature_event_notify.get_db_values(user, domain_name)
end);
--set some defaults if values in database are NULL
forward_all_enabled = forward_all_enabled and "true" or "false";
forward_busy_enabled = forward_busy_enabled and "true" or "false";
forward_no_answer_enabled = forward_no_answer_enabled and "true" or "false";
forward_user_not_registered_enabled = forward_user_not_registered_enabled and "true" or "false";
follow_me_enabled = follow_me_enabled and "true" or "false";
do_not_disturb = do_not_disturb and "true" or "false";
if (call_timeout == "") then call_timeout = "30"; end
return do_not_disturb, forward_all_enabled, forward_all_destination, forward_busy_enabled, forward_busy_destination, forward_no_answer_enabled, forward_no_answer_destination, call_timeout

View File

@@ -288,9 +288,20 @@
if (voicemail_id ~= nil) then
if (session ~= nil and session:ready()) then
--get the information from the database
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
local sql = [[SELECT
voicemail_uuid,
voicemail_password,
greeting_id,
voicemail_alternate_greet_id,
voicemail_mail_to,
cast(voicemail_attach_file as text),
cast(voicemail_local_after_email as text),
cast(voicemail_local_after_forward as text),
cast(voicemail_transcription_enabled as text),
cast(voicemail_tutorial as text)
FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = true ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
@@ -309,12 +320,6 @@
voicemail_tutorial = row["voicemail_tutorial"];
end);
--set boolean values as a string
voicemail_attach_file = voicemail_attach_file and "true" or "false";
voicemail_local_after_email = voicemail_local_after_email and "true" or "false";
voicemail_local_after_forward = voicemail_local_after_forward and "true" or "false";
voicemail_tutorial = voicemail_tutorial and "true" or "false";
--valid voicemail
if (voicemail_uuid ~= nil and string.len(voicemail_uuid) > 0) then
--answer the session
@@ -400,9 +405,16 @@
--get voicemail message details
if (voicemail_id) then
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id]]
local sql = "SELECT ";
sql = sql .. " cast(voicemail_local_after_email as text), ";
sql = sql .. " cast(voicemail_local_after_forward as text), ";
sql = sql .. " cast(voicemail_attach_file as text), ";
sql = sql .. " voicemail_password, ";
sql = sql .. " voicemail_mail_to, ";
sql = sql .. " cast(voicemail_enabled as text) ";
sql = sql .. "FROM v_voicemails ";
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
sql = sql .. "AND voicemail_id = :voicemail_id ";
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
@@ -412,11 +424,6 @@
voicemail_local_after_forward = row["voicemail_local_after_forward"];
end);
--set the boolean values as a string
voicemail_local_after_email = voicemail_local_after_email and "true" or "false";
voicemail_local_after_forward = voicemail_local_after_forward and "true" or "false";
voicemail_local_after_forward = voicemail_local_after_forward and "true" or "false";
--get the message count and send the mwi event
if (voicemail_local_after_email == 'true' or voicemail_local_after_forward == 'true') then
message_waiting(voicemail_id, domain_uuid);

View File

@@ -38,7 +38,14 @@ function send_email(id, uuid)
local email_queue_enabled = "true";
--get voicemail message details
local sql = [[SELECT * FROM v_voicemails
local sql = [[SELECT
voicemail_uuid,
voicemail_mail_to,
cast(voicemail_transcription_enabled as text),
voicemail_file,
cast(voicemail_local_after_email as text),
voicemail_description
FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id]]
local params = {domain_uuid = domain_uuid, voicemail_id = id};
@@ -61,9 +68,6 @@ function send_email(id, uuid)
voicemail_file = "listen";
end
--set the boolean values as a string
voicemail_local_after_email = voicemail_local_after_email and "true" or "false";
--require the email address to send the email
if (string.len(voicemail_mail_to) > 2) then
--include languages file
@@ -204,9 +208,6 @@ function send_email(id, uuid)
--get the link_address
link_address = http_protocol.."://"..domain_name..project_path;
--set the boolean values as a string
voicemail_local_after_email = voicemail_local_after_email and "true" or "false";
--set proper delete status
local local_after_email = '';
if (voicemail_local_after_email == "false") then

View File

@@ -123,7 +123,17 @@
--determine whether to update the dial string
if not session:ready() then return end
local sql = "select * from v_extensions ";
local sql = "select ";
sql = sql .. " extension_uuid, ";
sql = sql .. " extension, ";
sql = sql .. " number_alias, ";
sql = sql .. " accountcode, ";
sql = sql .. " cast(forward_all_enabled as text), ";
sql = sql .. " forward_all_destination, ";
sql = sql .. " toll_allow, ";
sql = sql .. " outbound_caller_id_name, ";
sql = sql .. " outbound_caller_id_number ";
sql = sql .. "from v_extensions ";
sql = sql .. "where domain_uuid = :domain_uuid ";
local params = {domain_uuid = domain_uuid};
if (extension_uuid ~= nil) then
@@ -143,7 +153,7 @@
extension = row.extension;
local number_alias = row.number_alias or '';
local accountcode = row.accountcode;
local forward_all_enabled = row.forward_all_enabled and "true" or "false";
local forward_all_enabled = row.forward_all_enabled;
local last_forward_all_destination = row.forward_all_destination;
local toll_allow = row.toll_allow or '';

View File

@@ -89,7 +89,19 @@
end
--determine whether to update the dial string
local sql = "select * from v_extensions ";
local sql = "select ";
sql = sql .. " extension_uuid, ";
sql = sql .. " extension, ";
sql = sql .. " number_alias, ";
sql = sql .. " accountcode, ";
sql = sql .. " cast(do_not_disturb as text), ";
sql = sql .. " cast(forward_all_enabled as text), ";
sql = sql .. " forward_all_destination, ";
sql = sql .. " toll_allow, ";
sql = sql .. " context, ";
sql = sql .. " outbound_caller_id_name, ";
sql = sql .. " outbound_caller_id_number ";
sql = sql .. "from v_extensions ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid};
@@ -106,9 +118,6 @@
context = row.user_context;
end);
forward_all_enabled = forward_all_enabled and "true" or "false";
do_not_disturb = do_not_disturb and "true" or "false";
--send information to the console
if (session:ready()) then
freeswitch.consoleLog("NOTICE", "[do_not_disturb] do_not_disturb "..do_not_disturb.."\n");