Commit a7ebda83 authored by Ted Trask's avatar Ted Trask

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.
parent cbe10cfa
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment