From 5d9bb1b9d17e373b496b51a96ca514e7ce55fa20 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 23 Sep 2015 20:09:16 -0600 Subject: [PATCH] Allow a device that is logged in already to be replaced with a new alternate device. --- .../install/scripts/app/provision/index.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/resources/install/scripts/app/provision/index.lua b/resources/install/scripts/app/provision/index.lua index 5eba2c844a..0173356e3b 100644 --- a/resources/install/scripts/app/provision/index.lua +++ b/resources/install/scripts/app/provision/index.lua @@ -121,7 +121,22 @@ result = session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-fail_auth.wav"); end ---remove the previous device and send a sync command to it +--this device already has an alternate find the correct device_uuid and then override current one + if (authorized == 'true' and action == "login" and device_uuid_alternate ~= nil) then + sql = [[SELECT * FROM v_devices ]]; + sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid..[[' ]]; + sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]]; + if (debug["sql"]) then + freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n"); + end + dbh:query(sql, function(row) + if (row.device_uuid_alternate ~= nil) then + device_uuid = row.device_uuid; + end + end); + end + +--remove the alternate device from another device so that it can be added to this device if (authorized == 'true' and action == "login") then sql = [[SELECT * FROM v_device_lines ]]; sql = sql .. [[WHERE device_uuid = ']]..device_uuid_alternate..[[' ]]; @@ -135,7 +150,7 @@ sql = sql .. [[WHERE device_uuid_alternate = ']]..device_uuid_alternate..[[' ]]; sql = sql .. [[AND domain_uuid = ']]..domain_uuid..[[' ]]; if (debug["sql"]) then - --freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n"); + freeswitch.consoleLog("NOTICE", "[provision] sql: ".. sql .. "\n"); end dbh:query(sql); --send a sync command to the previous device