diff options
author | Ted Trask <ttrask01@yahoo.com> | 2016-07-13 19:09:03 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2016-07-13 19:09:03 +0000 |
commit | a7ebda831d92420c3fbe9505b6032007bfae5df9 (patch) | |
tree | 7ab304fab9f5c5775cb01052641ad3df790b216d /vmail-model.lua | |
parent | cbe10cfad001621e7b29ba69900292492b63794d (diff) | |
download | acf-freeswitch-vmail-a7ebda831d92420c3fbe9505b6032007bfae5df9.tar.bz2 acf-freeswitch-vmail-a7ebda831d92420c3fbe9505b6032007bfae5df9.tar.xz |
Fix delete_user to properly delete messages and greetings
Removed hardcoded recording_path.
Recording directory will not be deleted if there are no recordings in it.
Diffstat (limited to 'vmail-model.lua')
-rw-r--r-- | vmail-model.lua | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/vmail-model.lua b/vmail-model.lua index d9fd31c..4b1b885 100644 --- a/vmail-model.lua +++ b/vmail-model.lua @@ -12,7 +12,6 @@ socket = require("socket") -- Set variables local configfile = "/etc/freeswitchvmail.conf" -local recording_path = "/var/lib/freeswitch/voicemail/" local db_path = "/var/lib/freeswitch/db/" local configcontent = fs.read_file(configfile) or "" local config = format.parse_ini_file(configcontent, "") or {} @@ -372,12 +371,32 @@ local delete_user = function(username) if #users == 0 then return false, "User does not exist" else + local recording_path + -- Delete all of the user's voicemails local messages = mymodule.list_messages(username) - if #messages.value then + if #messages.value > 0 then + recording_path = posix.dirname(messages.value[1].file_path) + local uuids = {} for i,m in ipairs(messages.value) do - delete_message(m.uuid) + uuids[#uuids+1] = m.uuid end + delete_message(uuids) + end + -- Remove the greetings + if not recording_path then + local sql = "SELECT * FROM voicemail_prefs"..generatewhereclause(username) + local prefs = vmaildb.getselectresponse(sql) + if prefs and prefs[1] then + if prefs[1].greeting_path then + recording_path = posix.dirname(prefs[1].greeting_path) + elseif prefs[1].name_path then + recording_path = posix.dirname(prefs[1].name_path) + end + end + end + if recording_path then + fs.remove_directory(recording_path) end -- Remove the user parameters local sql = "DELETE FROM voicemail_values " .. generatewhereclause(nil, nil, nil, users[1].uid) @@ -389,8 +408,6 @@ local delete_user = function(username) sql = "DELETE FROM voicemail_users " .. generatewhereclause(nil, nil, nil, users[1].uid) vmaildb.runsqlcommand(sql) result = "Voicemail User Deleted" - -- Remove the greetings - fs.remove_directory(recording_path..(users[1].domain or config.domain).."/"..username) end return true end |