Add. Use params in vm/mwi_subscribe.lua (#2143)

This commit is contained in:
Alexey Melnichuk
2016-11-22 11:12:37 -07:00
committed by FusionPBX
parent 09bdea108f
commit ad542a5db5
@@ -14,7 +14,7 @@ local vm_message_count do
local vm_to_uuid_sql = [[SELECT v.voicemail_uuid local vm_to_uuid_sql = [[SELECT v.voicemail_uuid
FROM v_voicemails as v inner join v_domains as d on v.domain_uuid = d.domain_uuid FROM v_voicemails as v inner join v_domains as d on v.domain_uuid = d.domain_uuid
WHERE v.voicemail_id = '%s' and d.domain_name = '%s']] WHERE v.voicemail_id = :voicemail_id and d.domain_name = :domain_name]]
local vm_messages_sql = [[SELECT local vm_messages_sql = [[SELECT
( SELECT count(*) ( SELECT count(*)
@@ -50,7 +50,9 @@ function vm_message_count(account, use_cache)
local sql = string.format(vm_to_uuid_sql, local sql = string.format(vm_to_uuid_sql,
dbh:escape(id), dbh:escape(domain_name) dbh:escape(id), dbh:escape(domain_name)
) )
uuid = dbh:first_value(sql) uuid = dbh:first_value(vm_to_uuid_sql, {
voicemail_id = id, domain_name = domain_name
})
if uuid and #uuid > 0 then if uuid and #uuid > 0 then
cache.set('voicemail_uuid:' .. account, uuid, 3600) cache.set('voicemail_uuid:' .. account, uuid, 3600)
@@ -58,22 +60,21 @@ function vm_message_count(account, use_cache)
end end
end end
local sql local row
if uuid and #uuid > 0 then if uuid and #uuid > 0 then
sql = string.format(vm_messages_sql, local sql = string.format(vm_messages_sql, ":voicemail_uuid", ":voicemail_uuid")
dbh:quoted(uuid), dbh:quoted(uuid) row = dbh:first_row(sql, {voicemail_uuid = uuid})
)
else else
local uuid_sql = '(' .. string.format(vm_to_uuid_sql, local uuid_sql = '(' .. vm_to_uuid_sql .. ')'
dbh:escape(id), dbh:escape(domain_name)
) .. ')'
sql = string.format(vm_messages_sql, local sql = string.format(vm_messages_sql,
uuid_sql, uuid_sql uuid_sql, uuid_sql
) )
end
local row = sql and dbh:first_row(sql) row = dbh:first_row(sql, {
voicemail_id = id, domain_name = domain_name
})
end
dbh:release() dbh:release()