mirror of
https://github.com/Mibew/design.git
synced 2024-11-15 09:24:12 +03:00
Move saveCallback and loadCallback to RequestProcessor class
This commit is contained in:
parent
4f199b2f26
commit
95bc033817
@ -63,11 +63,11 @@ $dbtables = array(
|
||||
"request" => "text NOT NULL"
|
||||
),
|
||||
|
||||
"${mysqlprefix}chatrequestcallback" => array(
|
||||
"${mysqlprefix}requestcallback" => array(
|
||||
"callbackid" => "int NOT NULL auto_increment PRIMARY KEY",
|
||||
"token" => "varchar(64) NOT NULL DEFAULT ''",
|
||||
"function" => "varchar(64) NOT NULL",
|
||||
"arguments" => "varchar(64)"
|
||||
"arguments" => "varchar(1024)"
|
||||
),
|
||||
|
||||
"${mysqlprefix}chatmessage" => array(
|
||||
@ -170,15 +170,15 @@ $dbtables_indexes = array(
|
||||
"${mysqlprefix}chatrequestbuffer" => array(
|
||||
"threadid" => "threadid"
|
||||
),
|
||||
"${mysqlprefix}chatrequestcallback" => array(
|
||||
"token" => "token"
|
||||
),
|
||||
"${mysqlprefix}chatmessage" => array(
|
||||
"idx_agentid" => "agentid"
|
||||
),
|
||||
"${mysqlprefix}chatsitevisitor" => array(
|
||||
"threadid" => "threadid"
|
||||
),
|
||||
"${mysqlprefix}requestcallback" => array(
|
||||
"token" => "token"
|
||||
),
|
||||
"${mysqlprefix}visitedpage" => array(
|
||||
"visitorid" => "visitorid"
|
||||
)
|
||||
@ -195,7 +195,6 @@ $memtables = array();
|
||||
$dbtables_can_update = array(
|
||||
"${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid", "dtmchatstarted"),
|
||||
"${mysqlprefix}chatrequestbuffer" => array("requestid", "threadid", "request"),
|
||||
"${mysqlprefix}chatrequestcallback" => array("callbackid", "token", "function", "arguments"),
|
||||
"${mysqlprefix}chatmessage" => array("agentId"),
|
||||
"${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "idisabled", "vcemail", "dtmrestore", "vcrestoretoken"),
|
||||
"${mysqlprefix}chatban" => array(),
|
||||
@ -203,6 +202,7 @@ $dbtables_can_update = array(
|
||||
"${mysqlprefix}chatgroupoperator" => array(),
|
||||
"${mysqlprefix}chatresponses" => array("vctitle"),
|
||||
"${mysqlprefix}chatsitevisitor" => array(),
|
||||
"${mysqlprefix}requestcallback" => array("callbackid", "token", "function", "arguments"),
|
||||
"${mysqlprefix}visitedpage" => array(),
|
||||
"${mysqlprefix}visitedpagestatistics" => array(),
|
||||
);
|
||||
|
@ -398,6 +398,60 @@ abstract class RequestProcessor {
|
||||
return empty($results['errorCode']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Request token
|
||||
* @param array $callback Callback function array
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function saveCallback($token, $callback) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"INSERT INTO {requestcallback} ( ".
|
||||
"token, function, arguments ".
|
||||
") VALUES ( " .
|
||||
":token, :function, :arguments" .
|
||||
")",
|
||||
array(
|
||||
':token' => $token,
|
||||
':function' => $callback['function'],
|
||||
':arguments' => serialize($callback['arguments'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Token of the request related to callback function
|
||||
* @return mixed callback function array or null if callback function not exists
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function loadCallback($token) {
|
||||
$db = Database::getInstance();
|
||||
$callback = $db->query(
|
||||
"SELECT * FROM {requestcallback} WHERE token = :token",
|
||||
array(':token' => $token),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if (! $callback) {
|
||||
return null;
|
||||
}
|
||||
return array(
|
||||
'function' => $callback['function'],
|
||||
'arguments' => unserialize($callback['arguments'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends synchronous request
|
||||
*
|
||||
@ -443,30 +497,6 @@ abstract class RequestProcessor {
|
||||
*/
|
||||
protected abstract function getMibewAPIInstance();
|
||||
|
||||
/**
|
||||
* Stores callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Request token
|
||||
* @param array $callback Callback function array
|
||||
*/
|
||||
protected abstract function saveCallback($token, $callback);
|
||||
|
||||
/**
|
||||
* Loads callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Token of the request related to callback function
|
||||
* @return mixed callback function array or null if callback function not exists
|
||||
*/
|
||||
protected abstract function loadCallback($token);
|
||||
|
||||
/**
|
||||
* Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API.
|
||||
*
|
||||
|
@ -122,50 +122,6 @@ class ThreadProcessor extends RequestProcessor {
|
||||
return MibewAPI::getAPI('MibewAPIChatInteraction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores callback function
|
||||
*
|
||||
* @param string $token Request token
|
||||
* @param array $callback Callback function array
|
||||
*/
|
||||
protected function saveCallback($token, $callback) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"INSERT INTO {chatrequestcallback} ( ".
|
||||
"token, function, arguments ".
|
||||
") VALUES ( " .
|
||||
":token, :function, :arguments" .
|
||||
")",
|
||||
array(
|
||||
':token' => $token,
|
||||
':functionname' => $callback['function'],
|
||||
':arguments' => serialize($callback['arguments'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads callback function
|
||||
*
|
||||
* @param string $token Token of the request related to callback function
|
||||
* @return mixed callback function array or null if callback function not exists
|
||||
*/
|
||||
protected function loadCallback($token) {
|
||||
$db = Database::getInstance();
|
||||
$callback = $db->query(
|
||||
"SELECT * FROM {chatrequestcallback} WHERE token = :token",
|
||||
array(':token' => $token),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if (! $callback) {
|
||||
return null;
|
||||
}
|
||||
return array(
|
||||
'function' => $callback['function'],
|
||||
'arguments' => unserialize($callback['arguments'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user