diff --git a/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php b/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php index 9cab8d5e..4932b41f 100644 --- a/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php +++ b/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php @@ -214,6 +214,7 @@ class ThreadTest extends PHPUnit_Framework_TestCase { 'dtmcreated' => time() - 100, 'dtmmodified' => time() - 90, 'dtmchatstarted' => 0, + 'dtmclosed' => time(), 'agentId' => 0, 'agentName' => '', diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index df15d2b9..8b7a93fa 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -50,6 +50,8 @@ $dbtables = array( "dtmchatstarted" => "int NOT NULL DEFAULT 0", // Unix timestamp of the last thread modification. "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. "lrevision" => "int NOT NULL DEFAULT 0", // State of the thread. It is one of Thread::STATE_* constants. @@ -268,7 +270,7 @@ $dbtables_indexes = array( $memtables = 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}requestbuffer" => array("requestid", "requestkey", "request"), "${mysqlprefix}chatmessage" => array("agentId", "plugin", "data"), diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index 9262ecb4..81056a56 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -109,6 +109,11 @@ if ($act == "silentcreateall") { 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)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link); } diff --git a/src/messenger/webim/libs/classes/thread.php b/src/messenger/webim/libs/classes/thread.php index ecb300f2..3472d1cc 100644 --- a/src/messenger/webim/libs/classes/thread.php +++ b/src/messenger/webim/libs/classes/thread.php @@ -140,6 +140,7 @@ Class Thread { * - 'messageCount': count of user's messages related to the thread * - 'created': unix timestamp of the thread creation * - '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 * - 'agentId': id 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', 'modified' => 'dtmmodified', 'chatStarted' => 'dtmchatstarted', + 'closed' => 'dtmclosed', 'agentId' => 'agentId', 'agentName' => 'agentName', @@ -369,7 +371,7 @@ Class Thread { $db = Database::getInstance(); $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 " . "and ((lastpingagent <> 0 and lastpinguser <> 0 and " . "(ABS(:now - lastpinguser) > :thread_lifetime and " . @@ -920,6 +922,7 @@ Class Thread { // Close thread if it's not already closed if ($this->state != self::STATE_CLOSED) { $this->state = self::STATE_CLOSED; + $this->closed = time(); $this->messageCount = $message_count; $this->save(); } diff --git a/src/messenger/webim/libs/classes/thread_processor.php b/src/messenger/webim/libs/classes/thread_processor.php index c7a60b5b..87592449 100644 --- a/src/messenger/webim/libs/classes/thread_processor.php +++ b/src/messenger/webim/libs/classes/thread_processor.php @@ -606,6 +606,7 @@ class ThreadProcessor extends ClientSideProcessor { $thread->userId = $visitor['id']; $thread->userAgent = $user_browser; $thread->state = Thread::STATE_LEFT; + $thread->closed = time(); $thread->save(); // Send some messages diff --git a/src/messenger/webim/libs/invitation.php b/src/messenger/webim/libs/invitation.php index 64592889..864a473e 100644 --- a/src/messenger/webim/libs/invitation.php +++ b/src/messenger/webim/libs/invitation.php @@ -202,13 +202,15 @@ function invitation_reject($visitor_id) { "UPDATE {chatsitevisitor} v, {chatthread} t SET " . "v.threadid = NULL, " . "t.invitationstate = :invitation_rejected, " . - "t.istate = :state_closed " . + "t.istate = :state_closed, " . + "t.dtmclosed = :now " . "WHERE t.threadid = v.threadid " . "AND visitorid = :visitor_id", array( ':invitation_rejected' => Thread::INVITATION_REJECTED, ':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 " . "t.invitationstate = :invitation_ignored, " . "t.istate = :state_closed, " . + "t.dtmclosed = :now, " . "v.threadid = NULL " . "WHERE t.istate = :state_invited " . "AND t.invitationstate = :invitation_wait " .