From b63a6bb42b4ed680fbca8c91b0ce1ccd96265007 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 30 Jan 2017 20:35:27 -0700 Subject: [PATCH] Update index.lua Prevent a nil error when using voicemail has reached its quota. --- .../install/scripts/app/voicemail/index.lua | 68 ++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/resources/install/scripts/app/voicemail/index.lua b/resources/install/scripts/app/voicemail/index.lua index 0a5b5054e4..996084bd70 100644 --- a/resources/install/scripts/app/voicemail/index.lua +++ b/resources/install/scripts/app/voicemail/index.lua @@ -1,5 +1,5 @@ -- Part of FusionPBX --- Copyright (C) 2013-2016 Mark J Crane +-- Copyright (C) 2013-2017 Mark J Crane -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without @@ -12,7 +12,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, @@ -37,8 +37,8 @@ direct_dial["max_digits"] = 4; --debug - debug["info"] = false; - debug["sql"] = false; + debug["info"] = true; + debug["sql"] = true; --get the argv values script_name = argv[1]; @@ -320,30 +320,32 @@ --leave a message if (voicemail_action == "save") then + --check the voicemail quota + if (vm_disk_quota) then + --get voicemail message seconds + local sql = [[SELECT coalesce(sum(message_length), 0) as message_sum FROM v_voicemail_messages + WHERE domain_uuid = :domain_uuid + AND voicemail_uuid = :voicemail_uuid]] + local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid}; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n"); + end + dbh:query(sql, params, function(row) + message_sum = row["message_sum"]; + end); + if (tonumber(vm_disk_quota) <= tonumber(message_sum)) then + --play message mailbox full + session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-mailbox_full.wav") + --hangup + session:hangup("NORMAL_CLEARING"); + --set the voicemail_uuid to nil to prevent saving the voicemail + voicemail_uuid = nil; + end + end + --valid voicemail if (voicemail_uuid ~= nil) then - --check the voicemail quota - if (vm_disk_quota) then - --get voicemail message seconds - local sql = [[SELECT coalesce(sum(message_length), 0) as message_sum FROM v_voicemail_messages - WHERE domain_uuid = :domain_uuid - AND voicemail_uuid = :voicemail_uuid]] - local params = {domain_uuid = domain_uuid, voicemail_uuid = voicemail_uuid}; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n"); - end - dbh:query(sql, params, function(row) - message_sum = row["message_sum"]; - end); - if (tonumber(vm_disk_quota) <= tonumber(message_sum)) then - --play message mailbox full - session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-mailbox_full.wav") - --set the voicemail_uuid to nil to prevent saving the voicemail - voicemail_uuid = nil; - end - end - --play the greeting timeouts = 0; play_greeting(); @@ -529,13 +531,15 @@ else --voicemail not enabled or does not exist - referred_by = session:getVariable("sip_h_Referred-By"); - if (referred_by) then - referred_by = referred_by:match('[%d]+'); - session:transfer(referred_by, "XML", context); - else - session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-no_answer_no_vm.wav"); - session:hangup("NO_ANSWER"); + if (session:ready()) then + referred_by = session:getVariable("sip_h_Referred-By"); + if (referred_by) then + referred_by = referred_by:match('[%d]+'); + session:transfer(referred_by, "XML", context); + else + session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-no_answer_no_vm.wav"); + session:hangup("NO_ANSWER"); + end end end end