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:
parent
519c9a1f3b
commit
8961ebd5de
|
@ -103,12 +103,12 @@ abstract class Message
|
||||||
{
|
{
|
||||||
return $this->variables;
|
return $this->variables;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public function getActionID()
|
public function getActionID()
|
||||||
{
|
{
|
||||||
return $this->getKey('ActionID');
|
return $this->getKey('ActionID');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public function getKeys()
|
public function getKeys()
|
||||||
{
|
{
|
||||||
return $this->keys;
|
return $this->keys;
|
||||||
|
@ -126,8 +126,10 @@ abstract class Message
|
||||||
$key = strtolower($key);
|
$key = strtolower($key);
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'json':
|
case 'json':
|
||||||
$this->keys['JSONRAW'] = (string) $value;
|
//$this->keys['JSONRAW'] = (string) $value;
|
||||||
|
$this->keys['json'] = (string) $value;
|
||||||
break;
|
break;
|
||||||
|
case 'response':
|
||||||
case 'actionid':
|
case 'actionid':
|
||||||
case 'desc':
|
case 'desc':
|
||||||
$this->keys[$key] = (string) $value;
|
$this->keys[$key] = (string) $value;
|
||||||
|
@ -137,13 +139,14 @@ abstract class Message
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
$_string_key = array('actionid', 'descr', 'json');
|
$_string_key = array('actionid', 'descr');
|
||||||
if (array_search($key, $_string_key) !== false) {
|
if (array_search($key, $_string_key) !== false) {
|
||||||
$this->keys[$key] = (string) $this->sanitizeInput($value, 'string');
|
$this->keys[$key] = (string) $this->sanitizeInput($value, 'string');
|
||||||
} else {
|
} else {
|
||||||
$this->keys[$key] = $this->sanitizeInput($value);
|
$this->keys[$key] = $this->sanitizeInput($value);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sanitizeInput($value, $prefered_type = '')
|
protected function sanitizeInput($value, $prefered_type = '')
|
||||||
|
|
|
@ -70,7 +70,7 @@ abstract class Response extends IncomingMessage
|
||||||
{
|
{
|
||||||
$this->setKey('ActionId', $actionId);
|
$this->setKey('ActionId', $actionId);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public function getVariable(string $_rawContent, array $_fields)
|
public function getVariable(string $_rawContent, array $_fields)
|
||||||
{
|
{
|
||||||
dbug($_rawContent);
|
dbug($_rawContent);
|
||||||
|
@ -85,6 +85,8 @@ abstract class Response extends IncomingMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//****************************************************************************
|
//****************************************************************************
|
||||||
|
@ -117,6 +119,7 @@ class Command_Response extends Generic_Response
|
||||||
private $_temptable;
|
private $_temptable;
|
||||||
public function __construct($rawContent)
|
public function __construct($rawContent)
|
||||||
{
|
{
|
||||||
|
//dbug($rawContent);
|
||||||
$this->_temptable = array();
|
$this->_temptable = array();
|
||||||
parent::__construct($rawContent);
|
parent::__construct($rawContent);
|
||||||
$lines = explode(Message::EOL, $rawContent);
|
$lines = explode(Message::EOL, $rawContent);
|
||||||
|
@ -155,14 +158,15 @@ class SCCPJSON_Response extends Generic_Response
|
||||||
public function __construct($rawContent)
|
public function __construct($rawContent)
|
||||||
{
|
{
|
||||||
parent::__construct($rawContent);
|
parent::__construct($rawContent);
|
||||||
|
//dbug($rawContent);
|
||||||
//$this->getVariable($rawContent, array("DataType" => "DataType:", "JSONRAW" => "JSON:"));
|
//$this->getVariable($rawContent, array("DataType" => "DataType:", "JSONRAW" => "JSON:"));
|
||||||
if (null !== $this->getKey('JSONRAW')) {
|
//if (null !== $this->getKey('JSON')) {
|
||||||
$this->setKey('Response', 'Success');
|
//$this->setKey('Response', 'Success');
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
public function getResult()
|
public function getResult()
|
||||||
{
|
{
|
||||||
if (($json = json_decode($this->getKey('JSON'), true)) != false) {
|
if ($json = json_decode($this->getKey('JSON'), true)) {
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,6 +252,7 @@ class SCCPGeneric_Response extends Response
|
||||||
|
|
||||||
protected function ConvertTableData( $_tablename, array $_fkey, array $_fields)
|
protected function ConvertTableData( $_tablename, array $_fkey, array $_fields)
|
||||||
{
|
{
|
||||||
|
//dbug(debug_backtrace(2));
|
||||||
$result = array();
|
$result = array();
|
||||||
$_rawtable = $this->Table2Array($_tablename);
|
$_rawtable = $this->Table2Array($_tablename);
|
||||||
// Check that there is actually data to be converted
|
// Check that there is actually data to be converted
|
||||||
|
|
|
@ -141,7 +141,7 @@ class aminterface
|
||||||
$messageToSend = $message->serialize();
|
$messageToSend = $message->serialize();
|
||||||
$length = strlen($messageToSend);
|
$length = strlen($messageToSend);
|
||||||
$this->_DumpMessage = '';
|
$this->_DumpMessage = '';
|
||||||
$this->_lastActionId = $message->getActionID();
|
$this->_lastActionId = $message->getKey('ActionID');
|
||||||
$this->_lastRequestedResponseHandler = $message->getResponseHandler();
|
$this->_lastRequestedResponseHandler = $message->getResponseHandler();
|
||||||
$this->_lastActionClass = $message;
|
$this->_lastActionClass = $message;
|
||||||
$this->_incomingRawMessage[$this->_lastActionId] = '';
|
$this->_incomingRawMessage[$this->_lastActionId] = '';
|
||||||
|
@ -281,7 +281,7 @@ class aminterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$response = new $responseClass($message);
|
$response = new $responseClass($message);
|
||||||
$actionId = $response->getActionID();
|
$actionId = $response->getKey('ActionID');
|
||||||
if ($actionId === null) {
|
if ($actionId === null) {
|
||||||
$response->setActionId($this->_lastActionId);
|
$response->setActionId($this->_lastActionId);
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,7 @@ class aminterface
|
||||||
{
|
{
|
||||||
// Initialise array with default values to eliminate testing later
|
// Initialise array with default values to eliminate testing later
|
||||||
$result = array();
|
$result = array();
|
||||||
$cmd_res = array();
|
//$cmd_res = array();
|
||||||
$cmd_res = ['sccp' => ['message' => 'legacy value', 'realm' => '', 'status' => 'ERROR']];
|
$cmd_res = ['sccp' => ['message' => 'legacy value', 'realm' => '', 'status' => 'ERROR']];
|
||||||
if ($this->_connect_state) {
|
if ($this->_connect_state) {
|
||||||
$_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status');
|
$_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status');
|
||||||
|
|
|
@ -15,8 +15,10 @@ trait bmoFunctions {
|
||||||
case 'sccpsettings':
|
case 'sccpsettings':
|
||||||
break;
|
break;
|
||||||
case 'sccp_phone':
|
case 'sccp_phone':
|
||||||
$this->extensionData = json_encode($this->getExtensionGrid('extGrid'));
|
// Get activeDevices once and pass to functions.
|
||||||
$this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp'));
|
$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'));
|
$this->sipPhoneData = json_encode($this->getPhoneGrid('cisco-sip'));
|
||||||
break;
|
break;
|
||||||
case 'sccp_adv':
|
case 'sccp_adv':
|
||||||
|
@ -29,7 +31,7 @@ trait bmoFunctions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPhoneGrid(string $type){
|
function getPhoneGrid(string $type, $activeDevices =array()){
|
||||||
$dbDevices = array();
|
$dbDevices = array();
|
||||||
// Find all devices defined in the database.
|
// Find all devices defined in the database.
|
||||||
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));
|
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));
|
||||||
|
@ -39,7 +41,7 @@ trait bmoFunctions {
|
||||||
return $dbDevices; //this may be empty
|
return $dbDevices; //this may be empty
|
||||||
}
|
}
|
||||||
// Find all devices currently connected
|
// Find all devices currently connected
|
||||||
$activeDevices = $this->aminterface->sccp_get_active_device();
|
//$activeDevices = $this->aminterface->sccp_get_active_device();
|
||||||
|
|
||||||
foreach ($dbDevices as &$dev_id) {
|
foreach ($dbDevices as &$dev_id) {
|
||||||
if (!empty($activeDevices[$dev_id['name']])) {
|
if (!empty($activeDevices[$dev_id['name']])) {
|
||||||
|
@ -87,12 +89,12 @@ trait bmoFunctions {
|
||||||
return $dbDevices;
|
return $dbDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExtensionGrid(string $type) {
|
function getExtensionGrid(string $type, $activeDevices = array()) {
|
||||||
$lineList = $this->dbinterface->getSccpDeviceTableData($type);
|
$lineList = $this->dbinterface->getSccpDeviceTableData($type);
|
||||||
if (empty($lineList)) {
|
if (empty($lineList)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$activeDevices = $this->aminterface->sccp_get_active_device();
|
//$activeDevices = $this->aminterface->sccp_get_active_device();
|
||||||
$uniqueLineList = array();
|
$uniqueLineList = array();
|
||||||
foreach ($lineList as $key => &$lineArr) {
|
foreach ($lineList as $key => &$lineArr) {
|
||||||
if (array_key_exists($lineArr['mac'], $activeDevices)) {
|
if (array_key_exists($lineArr['mac'], $activeDevices)) {
|
||||||
|
|
Loading…
Reference in a new issue