From 1056b84ed3105a27f20f577af5144976e4ffa85f Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Sat, 26 Nov 2016 09:01:18 +0300 Subject: [PATCH] Fix. Store message_intro_base64 in database. (#2197) --- .../resources/functions/forward_add_intro.lua | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/resources/install/scripts/app/voicemail/resources/functions/forward_add_intro.lua b/resources/install/scripts/app/voicemail/resources/functions/forward_add_intro.lua index d05ba0f027..db073a2c97 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/forward_add_intro.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/forward_add_intro.lua @@ -95,21 +95,25 @@ --save the merged file into the database as base64 if (storage_type == "base64") then + local file = require "resources.functions.file" + --get the content of the file - local f = io.open(message_intro_location, "rb"); - local file_content = f:read("*all"); - f:close(); + local file_content = assert(file.read_base64(message_intro_location); --save the merged file as base64 - local sql = {} - sql = [[UPDATE SET v_voicemail_messages - SET message_intro_base64 = ']].. base64.encode(file_content) ..[[' - WHERE domain_uuid = ']] .. domain_uuid ..[[' - AND voicemail_message_uuid = ']].. uuid.. [[' ]]; - sql = table.concat(sql, "\n"); + local sql = [[UPDATE SET v_voicemail_messages + SET message_intro_base64 = :file_content + WHERE domain_uuid = :domain_uuid + AND voicemail_message_uuid = :uuid]]; + local params = {file_content = file_content, domain_uuid = domain_uuid, uuid = uuid}; + if (debug["sql"]) then - freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); + freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n"); end + + local dbh = Database.new('system', 'base64') + dbh:query(sql, params) + dbh:release() end end