From 95bc0338176935e024ad0a104035fbb569724fb9 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 15 Jan 2013 13:00:03 +0000 Subject: [PATCH] Move saveCallback and loadCallback to RequestProcessor class --- src/messenger/webim/install/dbinfo.php | 12 +-- .../webim/libs/classes/request_processor.php | 78 +++++++++++++------ .../webim/libs/classes/thread_processor.php | 44 ----------- 3 files changed, 60 insertions(+), 74 deletions(-) diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 8aaacfae..bf007ffb 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -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(), ); diff --git a/src/messenger/webim/libs/classes/request_processor.php b/src/messenger/webim/libs/classes/request_processor.php index 5433bcdf..f335cc95 100644 --- a/src/messenger/webim/libs/classes/request_processor.php +++ b/src/messenger/webim/libs/classes/request_processor.php @@ -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. * diff --git a/src/messenger/webim/libs/classes/thread_processor.php b/src/messenger/webim/libs/classes/thread_processor.php index a2929249..ef61417f 100644 --- a/src/messenger/webim/libs/classes/thread_processor.php +++ b/src/messenger/webim/libs/classes/thread_processor.php @@ -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. *