Fix bug with old threads closing

This commit is contained in:
Dmitriy Simushev 2013-07-15 13:32:05 +00:00
parent ab8a889464
commit a899cc2dff

View File

@ -370,14 +370,43 @@ Class Thread {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "update {chatthread} set lrevision = :next_revision, " . $query = "UPDATE {chatthread} SET " .
"dtmmodified = :now, dtmclosed = :now, istate = :state_closed " . "lrevision = :next_revision, " .
"where istate <> :state_closed and istate <> :state_left " . "dtmmodified = :now, " .
"and ((lastpingagent <> 0 and lastpinguser <> 0 and " . "dtmclosed = :now, " .
"(ABS(:now - lastpinguser) > :thread_lifetime and " . "istate = :state_closed " .
"ABS(:now - lastpingagent) > :thread_lifetime)) or " . "WHERE istate <> :state_closed " .
"(lastpingagent = 0 and lastpinguser <> 0 and " . "AND istate <> :state_left " .
"ABS(:now - lastpinguser) > :thread_lifetime))"; // Check created timestamp
"AND ABS(:now - dtmcreated) > :thread_lifetime " .
// Check pings
"AND ( " .
"( " .
// Both user and operator have no connection problems.
// Check all pings.
"lastpingagent <> 0 " .
"AND lastpinguser <> 0 " .
"AND ABS(:now - lastpinguser) > :thread_lifetime " .
"AND ABS(:now - lastpingagent) > :thread_lifetime " .
") OR ( " .
// Only operator have connection problems.
// Check user's ping.
"lastpingagent = 0 " .
"AND lastpinguser <> 0 " .
"AND ABS(:now - lastpinguser) > :thread_lifetime " .
") OR ( " .
// Only user have connection problems.
// Check operator's ping.
"lastpinguser = 0 " .
"AND lastpingagent <> 0 " .
"AND ABS(:now - lastpingagent) > :thread_lifetime " .
") OR ( " .
// Both user and operator have connection problems.
// Just close thread.
"lastpinguser = 0 " .
"AND lastpingagent = 0 " .
") " .
")";
$db->query( $db->query(
$query, $query,