summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/phones
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-28 20:27:04 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-28 20:27:04 +0100
commitf3c3e77eaa2b82567f02601b6f66177208674181 (patch)
tree1946390f7f697e80fcdab4164ad620d507b6a1fe /misc/freeswitch/scripts/phones
parent3e76142566ad8f55a64a88fe5c19e7d0ec7c11c0 (diff)
parent8d20201910b1915cffa495e6474d50f9c8e8331d (diff)
Merge branch 'develop'5.0.1
Diffstat (limited to 'misc/freeswitch/scripts/phones')
-rw-r--r--misc/freeswitch/scripts/phones/phone.lua72
1 files changed, 41 insertions, 31 deletions
diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua
index 5cd210b..bc2aa3d 100644
--- a/misc/freeswitch/scripts/phones/phone.lua
+++ b/misc/freeswitch/scripts/phones/phone.lua
@@ -18,6 +18,26 @@ function Phone.new(self, arg)
end
+function Phone.list_by_sql(self, sql_query)
+ local account_phones = {};
+
+ self.database:query(sql_query, function(account_entry)
+ local phone = Phone:new(self, {object = parent_class});
+ phone.record = account_entry;
+ phone.record.ieee_name = common.str.downcase(account_entry.ieee_name);
+
+ if phone.record.ieee_name == 'snom technology ag' then
+ require 'phones.snom'
+ phone.model = phones.snom.Snom:new();
+ elseif account_entry.ieee_name == 'siemens enterprise communicationsgmbh & co. kg' then
+ require 'phones.siemens'
+ phone.model = phones.siemens.Siemens:new();
+ end
+ table.insert(account_phones, phone);
+ end)
+
+ return account_phones;
+end
-- Find a hot-deskable phone by sip-account
function Phone.find_all_hot_deskable_by_account(self, account_id)
@@ -25,7 +45,7 @@ function Phone.find_all_hot_deskable_by_account(self, account_id)
local sql_query = 'SELECT \
`b`.`id`, `b`.`mac_address`, `b`.`ip_address`, `b`.`http_user`, `b`.`http_password`, `b`.`phoneable_type`, `b`.`phoneable_id`, \
- `d`.`ieee_name` \
+ `b`.`tenant_id`, `b`.`fallback_sip_account_id`, `d`.`ieee_name` \
FROM `phone_sip_accounts` `a` \
JOIN `phones` `b` ON `a`.`phone_id` = `b`.`id` \
JOIN `phone_models` `c` ON `b`.`phone_model_id` = `c`.`id` \
@@ -35,22 +55,21 @@ function Phone.find_all_hot_deskable_by_account(self, account_id)
AND `d`.`state` = "active" \
AND `a`.`sip_account_id` = ' .. tonumber(account_id);
- local account_phones = {};
+ local account_phones = self:list_by_sql(sql_query);
- self.database:query(sql_query, function(account_entry)
- local phone = Phone:new(self, {object = parent_class});
- phone.record = account_entry;
- phone.record.ieee_name = common.str.downcase(account_entry.ieee_name);
+ if #account_phones == 0 then
+ sql_query = 'SELECT `b`.`id`, `b`.`mac_address`, `b`.`ip_address`, `b`.`http_user`, `b`.`http_password`, `b`.`phoneable_type`, `b`.`phoneable_id`, \
+ `b`.`tenant_id`, `b`.`fallback_sip_account_id`, `d`.`ieee_name` \
+ FROM `phones` `b` \
+ JOIN `phone_models` `c` ON `b`.`phone_model_id` = `c`.`id` \
+ JOIN `manufacturers` `d` ON `c`.`manufacturer_id` = `d`.`id` \
+ WHERE `b`.`hot_deskable` IS TRUE \
+ AND `c`.`state` = "active" \
+ AND `d`.`state` = "active" \
+ AND `b`.`fallback_sip_account_id` = ' .. tonumber(account_id);
- if phone.record.ieee_name == 'snom technology ag' then
- require 'phones.snom'
- phone.model = phones.snom.Snom:new();
- elseif account_entry.ieee_name == 'siemens enterprise communicationsgmbh & co. kg' then
- require 'phones.siemens'
- phone.model = phones.siemens.Siemens:new();
- end
- table.insert(account_phones, phone);
- end)
+ account_phones = self:list_by_sql(sql_query);
+ end
return account_phones;
end
@@ -61,20 +80,6 @@ function Phone.find_hot_deskable_by_account(self, account_id)
end
-function Phone.tenant_id_get(self)
- local sql_query = 'SELECT `c`.`sip_accountable_id` \
- FROM `phones` `a` LEFT JOIN `phone_sip_accounts` `b` ON `a`.`id` = `b`.`phone_id` \
- JOIN `sip_accounts` `c` ON `b`.`sip_account_id` = `c`.`id` AND `sip_accountable_type` = "Tenant" \
- WHERE `a`.`id` = ' .. tonumber(self.record.id) .. ' LIMIT 1';
-
- local tenant_id = nil;
- self.database:query(sql_query, function(tenant_entry)
- tenant_id = tenant_entry.sip_accountable_id;
- end)
-
- return tenant_id;
-end
-
function Phone.phoneable_set(self, phoneable_id, phoneable_type)
sql_query = 'UPDATE `phones` SET `phoneable_type` = "' .. phoneable_type ..'", `phoneable_id` = ' .. phoneable_id .. ' \
WHERE `id` = ' .. tonumber(self.record.id);
@@ -82,7 +87,7 @@ function Phone.phoneable_set(self, phoneable_id, phoneable_type)
end
function Phone.logout(self, account_id)
- local tenant_id = self:tenant_id_get();
+ local tenant_id = tonumber(self.record.tenant_id);
if not tenant_id then
self.log:info('PHONE_LOGOUT - tenant not found');
@@ -91,7 +96,12 @@ function Phone.logout(self, account_id)
self:phoneable_set(tenant_id, 'Tenant');
- sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `sip_account_id` = ' .. tonumber(account_id);
+ if account_id then
+ sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `sip_account_id` = ' .. tonumber(account_id);
+ self.database:query(sql_query);
+ end
+
+ sql_query = 'DELETE FROM `phone_sip_accounts` WHERE `phone_id` = ' .. self.record.id;
return self.database:query(sql_query);
end