Add field with close timestamp to the Thread class

This commit is contained in:
Dmitriy Simushev 2013-06-24 11:21:46 +00:00
parent fb6517dc9f
commit 48ecf35f1a
6 changed files with 19 additions and 4 deletions

View File

@ -214,6 +214,7 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
'dtmcreated' => time() - 100, 'dtmcreated' => time() - 100,
'dtmmodified' => time() - 90, 'dtmmodified' => time() - 90,
'dtmchatstarted' => 0, 'dtmchatstarted' => 0,
'dtmclosed' => time(),
'agentId' => 0, 'agentId' => 0,
'agentName' => '', 'agentName' => '',

View File

@ -50,6 +50,8 @@ $dbtables = array(
"dtmchatstarted" => "int NOT NULL DEFAULT 0", "dtmchatstarted" => "int NOT NULL DEFAULT 0",
// Unix timestamp of the last thread modification. // Unix timestamp of the last thread modification.
"dtmmodified" => "int NOT NULL DEFAULT 0", "dtmmodified" => "int NOT NULL DEFAULT 0",
// Unix timestamp of the moment when the thread was closed.
"dtmclosed" => "int NOT NULL DEFAULT 0",
// ID of the last thread revision. // ID of the last thread revision.
"lrevision" => "int NOT NULL DEFAULT 0", "lrevision" => "int NOT NULL DEFAULT 0",
// State of the thread. It is one of Thread::STATE_* constants. // State of the thread. It is one of Thread::STATE_* constants.
@ -268,7 +270,7 @@ $dbtables_indexes = array(
$memtables = array(); $memtables = array();
$dbtables_can_update = array( $dbtables_can_update = array(
"${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid", "dtmchatstarted", "invitationstate"), "${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid", "dtmchatstarted", "dtmclosed", "invitationstate"),
"${mysqlprefix}chatthreadstatistics" => array("missedthreads", "sentinvitations", "acceptedinvitations", "rejectedinvitations", "ignoredinvitations"), "${mysqlprefix}chatthreadstatistics" => array("missedthreads", "sentinvitations", "acceptedinvitations", "rejectedinvitations", "ignoredinvitations"),
"${mysqlprefix}requestbuffer" => array("requestid", "requestkey", "request"), "${mysqlprefix}requestbuffer" => array("requestid", "requestkey", "request"),
"${mysqlprefix}chatmessage" => array("agentId", "plugin", "data"), "${mysqlprefix}chatmessage" => array("agentId", "plugin", "data"),

View File

@ -109,6 +109,11 @@ if ($act == "silentcreateall") {
runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link); runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link);
} }
if (in_array("${mysqlprefix}chatthread.dtmclosed", $absent_columns)) {
runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmclosed int NOT NULL DEFAULT 0 AFTER dtmmodified", $link);
runsql("update ${mysqlprefix}chatthread set dtmclosed = dtmmodified", $link);
}
if (in_array("${mysqlprefix}chatthread.agentTyping", $absent_columns)) { if (in_array("${mysqlprefix}chatthread.agentTyping", $absent_columns)) {
runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link); runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link);
} }

View File

@ -140,6 +140,7 @@ Class Thread {
* - 'messageCount': count of user's messages related to the thread * - 'messageCount': count of user's messages related to the thread
* - 'created': unix timestamp of the thread creation * - 'created': unix timestamp of the thread creation
* - 'modified': unix timestamp of the thread's last modification * - 'modified': unix timestamp of the thread's last modification
* - 'closed': unix timestamp of the moment when the thread was closed
* - 'chatStarted': unix timestamp of related to thread chat started * - 'chatStarted': unix timestamp of related to thread chat started
* - 'agentId': id of an operator who take part in the chat * - 'agentId': id of an operator who take part in the chat
* - 'agentName': name of an operator who take part in the chat * - 'agentName': name of an operator who take part in the chat
@ -177,6 +178,7 @@ Class Thread {
'created' => 'dtmcreated', 'created' => 'dtmcreated',
'modified' => 'dtmmodified', 'modified' => 'dtmmodified',
'chatStarted' => 'dtmchatstarted', 'chatStarted' => 'dtmchatstarted',
'closed' => 'dtmclosed',
'agentId' => 'agentId', 'agentId' => 'agentId',
'agentName' => 'agentName', 'agentName' => 'agentName',
@ -369,7 +371,7 @@ Class Thread {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "update {chatthread} set lrevision = :next_revision, " . $query = "update {chatthread} set lrevision = :next_revision, " .
"dtmmodified = :now, istate = :state_closed " . "dtmmodified = :now, dtmclosed = :now, istate = :state_closed " .
"where istate <> :state_closed and istate <> :state_left " . "where istate <> :state_closed and istate <> :state_left " .
"and ((lastpingagent <> 0 and lastpinguser <> 0 and " . "and ((lastpingagent <> 0 and lastpinguser <> 0 and " .
"(ABS(:now - lastpinguser) > :thread_lifetime and " . "(ABS(:now - lastpinguser) > :thread_lifetime and " .
@ -920,6 +922,7 @@ Class Thread {
// Close thread if it's not already closed // Close thread if it's not already closed
if ($this->state != self::STATE_CLOSED) { if ($this->state != self::STATE_CLOSED) {
$this->state = self::STATE_CLOSED; $this->state = self::STATE_CLOSED;
$this->closed = time();
$this->messageCount = $message_count; $this->messageCount = $message_count;
$this->save(); $this->save();
} }

View File

@ -606,6 +606,7 @@ class ThreadProcessor extends ClientSideProcessor {
$thread->userId = $visitor['id']; $thread->userId = $visitor['id'];
$thread->userAgent = $user_browser; $thread->userAgent = $user_browser;
$thread->state = Thread::STATE_LEFT; $thread->state = Thread::STATE_LEFT;
$thread->closed = time();
$thread->save(); $thread->save();
// Send some messages // Send some messages

View File

@ -202,13 +202,15 @@ function invitation_reject($visitor_id) {
"UPDATE {chatsitevisitor} v, {chatthread} t SET " . "UPDATE {chatsitevisitor} v, {chatthread} t SET " .
"v.threadid = NULL, " . "v.threadid = NULL, " .
"t.invitationstate = :invitation_rejected, " . "t.invitationstate = :invitation_rejected, " .
"t.istate = :state_closed " . "t.istate = :state_closed, " .
"t.dtmclosed = :now " .
"WHERE t.threadid = v.threadid " . "WHERE t.threadid = v.threadid " .
"AND visitorid = :visitor_id", "AND visitorid = :visitor_id",
array( array(
':invitation_rejected' => Thread::INVITATION_REJECTED, ':invitation_rejected' => Thread::INVITATION_REJECTED,
':state_closed' => Thread::STATE_CLOSED, ':state_closed' => Thread::STATE_CLOSED,
':visitor_id' => $visitor_id ':visitor_id' => $visitor_id,
':now' => time()
) )
); );
} }
@ -239,6 +241,7 @@ function invitation_close_old() {
"UPDATE {chatsitevisitor} v, {chatthread} t SET " . "UPDATE {chatsitevisitor} v, {chatthread} t SET " .
"t.invitationstate = :invitation_ignored, " . "t.invitationstate = :invitation_ignored, " .
"t.istate = :state_closed, " . "t.istate = :state_closed, " .
"t.dtmclosed = :now, " .
"v.threadid = NULL " . "v.threadid = NULL " .
"WHERE t.istate = :state_invited " . "WHERE t.istate = :state_invited " .
"AND t.invitationstate = :invitation_wait " . "AND t.invitationstate = :invitation_wait " .