diff options
author | Peter Kozak <spag@golwen.net> | 2013-07-24 09:41:39 +0200 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-07-24 09:41:39 +0200 |
commit | 331bb9d4c3ed1a52f849b1fb47dd6f8e586784c9 (patch) | |
tree | ce02cfbb9751fa0533b189cff2bc1c88b8d84dcc /misc/freeswitch | |
parent | f8b94f329a89fe06428bcf417b2ad7e09b1f95c6 (diff) |
resync_extension_modules method added
Diffstat (limited to 'misc/freeswitch')
-rw-r--r-- | misc/freeswitch/scripts/phones/phone.lua | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua index 57997ba..a256b12 100644 --- a/misc/freeswitch/scripts/phones/phone.lua +++ b/misc/freeswitch/scripts/phones/phone.lua @@ -114,15 +114,38 @@ function Phone.login(self, account_id, owner_id, owner_type) end function Phone.resync(self, arg) - if not self.model then - self.log:notice('PHONE_RESYNC phone model not found - trying Snom resync'); - require 'phones.snom' - return phones.snom.Snom:new{ log = self.log }:resync(arg); - end - + local result = nil; arg.ip_address = arg.ip_address or self.record.ip_address; arg.http_user = arg.http_user or self.record.http_user; arg.http_password = arg.http_password or self.record.http_password; + + if self.model then + result = self.model:resync(arg); + else + self.log:notice('PHONE_RESYNC phone model not found - trying Snom resync'); + require 'phones.snom'; + result = phones.snom.Snom:new{ log = self.log }:resync(arg); + end + + self:resync_extension_modules(arg); + + return result; +end + + +function Phone.resync_extension_modules(self, arg) + require('common.object'); + local object_class = common.object.Object:new{ log = self.log }; + + local sql_query = 'SELECT * FROM `extension_modules` WHERE `active` IS TRUE AND `phone_id` = ' .. common.str.to_i(self.record.id); + self.database:query(sql_query, function(extension_module) + local extension_module_class, error_message = object_class:load_one('phones.' .. extension_module.model); + if not extension_module_class then + self.log:error('RESYNC_EXTENSION_MODULE - unsupported model: ', extension_module.model, ', error: ', error_message); + end - return self.model:resync(arg); + arg.ip_address = extension_module.ip_address; + local result = extension_module_class:new{log = self.log}:resync(arg); + self.log:debug('RESYNC_EXTENSION_MODULE - ', extension_module_class.class, '=', extension_module.id, ', mac_address: ', extension_module.mac_address, ', ip_address: ', extension_module.ip_address, ', executed: ', tostring(result)); + end); end |