Optimise aminterface, and calls to it

Only get activeDevices once in doConfigPageInits
Delete redundant functions in Aminterface class
Optimise json handling
This commit is contained in:
stevenA 2022-01-16 09:29:53 +01:00
parent 519c9a1f3b
commit 8961ebd5de
4 changed files with 29 additions and 19 deletions

View file

@ -103,12 +103,12 @@ abstract class Message
{
return $this->variables;
}
/*
public function getActionID()
{
return $this->getKey('ActionID');
}
*/
public function getKeys()
{
return $this->keys;
@ -126,8 +126,10 @@ abstract class Message
$key = strtolower($key);
switch ($key) {
case 'json':
$this->keys['JSONRAW'] = (string) $value;
//$this->keys['JSONRAW'] = (string) $value;
$this->keys['json'] = (string) $value;
break;
case 'response':
case 'actionid':
case 'desc':
$this->keys[$key] = (string) $value;
@ -137,13 +139,14 @@ abstract class Message
break;
}
$_string_key = array('actionid', 'descr', 'json');
/*
$_string_key = array('actionid', 'descr');
if (array_search($key, $_string_key) !== false) {
$this->keys[$key] = (string) $this->sanitizeInput($value, 'string');
} else {
$this->keys[$key] = $this->sanitizeInput($value);
}
*/
}
protected function sanitizeInput($value, $prefered_type = '')

View file

@ -70,7 +70,7 @@ abstract class Response extends IncomingMessage
{
$this->setKey('ActionId', $actionId);
}
/*
public function getVariable(string $_rawContent, array $_fields)
{
dbug($_rawContent);
@ -85,6 +85,8 @@ abstract class Response extends IncomingMessage
}
}
}
*/
}
//****************************************************************************
@ -117,6 +119,7 @@ class Command_Response extends Generic_Response
private $_temptable;
public function __construct($rawContent)
{
//dbug($rawContent);
$this->_temptable = array();
parent::__construct($rawContent);
$lines = explode(Message::EOL, $rawContent);
@ -155,14 +158,15 @@ class SCCPJSON_Response extends Generic_Response
public function __construct($rawContent)
{
parent::__construct($rawContent);
//dbug($rawContent);
//$this->getVariable($rawContent, array("DataType" => "DataType:", "JSONRAW" => "JSON:"));
if (null !== $this->getKey('JSONRAW')) {
$this->setKey('Response', 'Success');
}
//if (null !== $this->getKey('JSON')) {
//$this->setKey('Response', 'Success');
//}
}
public function getResult()
{
if (($json = json_decode($this->getKey('JSON'), true)) != false) {
if ($json = json_decode($this->getKey('JSON'), true)) {
return $json;
}
}
@ -248,6 +252,7 @@ class SCCPGeneric_Response extends Response
protected function ConvertTableData( $_tablename, array $_fkey, array $_fields)
{
//dbug(debug_backtrace(2));
$result = array();
$_rawtable = $this->Table2Array($_tablename);
// Check that there is actually data to be converted

View file

@ -141,7 +141,7 @@ class aminterface
$messageToSend = $message->serialize();
$length = strlen($messageToSend);
$this->_DumpMessage = '';
$this->_lastActionId = $message->getActionID();
$this->_lastActionId = $message->getKey('ActionID');
$this->_lastRequestedResponseHandler = $message->getResponseHandler();
$this->_lastActionClass = $message;
$this->_incomingRawMessage[$this->_lastActionId] = '';
@ -281,7 +281,7 @@ class aminterface
}
}
$response = new $responseClass($message);
$actionId = $response->getActionID();
$actionId = $response->getKey('ActionID');
if ($actionId === null) {
$response->setActionId($this->_lastActionId);
}
@ -466,7 +466,7 @@ class aminterface
{
// Initialise array with default values to eliminate testing later
$result = array();
$cmd_res = array();
//$cmd_res = array();
$cmd_res = ['sccp' => ['message' => 'legacy value', 'realm' => '', 'status' => 'ERROR']];
if ($this->_connect_state) {
$_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status');

View file

@ -15,8 +15,10 @@ trait bmoFunctions {
case 'sccpsettings':
break;
case 'sccp_phone':
$this->extensionData = json_encode($this->getExtensionGrid('extGrid'));
$this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp'));
// Get activeDevices once and pass to functions.
$activeDevices = $this->aminterface->sccp_get_active_device();
$this->extensionData = json_encode($this->getExtensionGrid('extGrid', $activeDevices));
$this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp', $activeDevices));
$this->sipPhoneData = json_encode($this->getPhoneGrid('cisco-sip'));
break;
case 'sccp_adv':
@ -29,7 +31,7 @@ trait bmoFunctions {
}
}
function getPhoneGrid(string $type){
function getPhoneGrid(string $type, $activeDevices =array()){
$dbDevices = array();
// Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));
@ -39,7 +41,7 @@ trait bmoFunctions {
return $dbDevices; //this may be empty
}
// Find all devices currently connected
$activeDevices = $this->aminterface->sccp_get_active_device();
//$activeDevices = $this->aminterface->sccp_get_active_device();
foreach ($dbDevices as &$dev_id) {
if (!empty($activeDevices[$dev_id['name']])) {
@ -87,12 +89,12 @@ trait bmoFunctions {
return $dbDevices;
}
function getExtensionGrid(string $type) {
function getExtensionGrid(string $type, $activeDevices = array()) {
$lineList = $this->dbinterface->getSccpDeviceTableData($type);
if (empty($lineList)) {
return array();
}
$activeDevices = $this->aminterface->sccp_get_active_device();
//$activeDevices = $this->aminterface->sccp_get_active_device();
$uniqueLineList = array();
foreach ($lineList as $key => &$lineArr) {
if (array_key_exists($lineArr['mac'], $activeDevices)) {