Move saveCallback and loadCallback to RequestProcessor class

This commit is contained in:
Dmitriy Simushev 2013-01-15 13:00:03 +00:00
parent 4f199b2f26
commit 95bc033817
3 changed files with 60 additions and 74 deletions

View File

@ -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(),
);

View File

@ -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.
*

View File

@ -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.
*