Move remove invitations and visitors functionality to corresponding libs

This commit is contained in:
Dmitriy Simushev 2013-02-04 09:45:18 +00:00
parent 0cdd55cdf8
commit 37de991028
4 changed files with 72 additions and 46 deletions

View File

@ -342,54 +342,15 @@ class UsersProcessor extends ClientSideProcessor {
// Check access // Check access
self::checkOperator($args['agentId']); self::checkOperator($args['agentId']);
// Close old invitations
invitation_close_old();
// Remove old visitors and visitors tracks
track_remove_old_visitors();
track_remove_old_tracks();
$db = Database::getInstance(); $db = Database::getInstance();
// Remove old visitors
$db->query(
"DELETE FROM {chatsitevisitor} " .
"WHERE (:now - lasttime) > :lifetime ".
"AND (threadid IS NULL OR " .
"(SELECT count(*) FROM {chatthread} " .
"WHERE threadid = {chatsitevisitor}.threadid " .
"AND istate <> " . Thread::STATE_CLOSED . " " .
"AND istate <> " . Thread::STATE_LEFT . ") = 0)",
array(
':lifetime' => Settings::get('tracking_lifetime'),
':now' => time()
)
);
// Remove old invitations
$db->query(
"UPDATE {chatsitevisitor} SET invited = 0, " .
"invitationtime = NULL, invitedby = NULL".
" WHERE threadid IS NULL AND (:now - invitationtime) > :lifetime",
array(
':lifetime' => Settings::get('invitation_lifetime'),
':now' => time()
)
);
// Remove associations of visitors with closed threads
$db->query(
"UPDATE {chatsitevisitor} SET threadid = NULL " .
"WHERE threadid IS NOT NULL AND " .
" (SELECT count(*) FROM {chatthread} " .
"WHERE threadid = {chatsitevisitor}.threadid" .
" AND istate <> " . Thread::STATE_CLOSED . " " .
" AND istate <> " . Thread::STATE_LEFT . ") = 0"
);
// Remove old visitors' tracks
$db->query(
"DELETE FROM {visitedpage} WHERE (:now - visittime) > :lifetime " .
" AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor})",
array(
':lifetime' => Settings::get('tracking_lifetime'),
':now' => time()
)
);
// Load visitors // Load visitors
$query = "SELECT visitorid, userid, username, firsttime, lasttime, " . $query = "SELECT visitorid, userid, username, firsttime, lasttime, " .
"entry, details, invited, invitationtime, invitedby, " . "entry, details, invited, invitationtime, invitedby, " .

View File

@ -82,4 +82,22 @@ function invitation_accept($visitorid, $threadid)
} }
} }
/**
* Close old invitations
*/
function invitation_close_old() {
$db = Database::getInstance();
// Remove old invitations
$db->query(
"UPDATE {chatsitevisitor} SET invited = 0, " .
"invitationtime = NULL, invitedby = NULL".
" WHERE threadid IS NULL AND (:now - invitationtime) > :lifetime",
array(
':lifetime' => Settings::get('invitation_lifetime'),
':now' => time()
)
);
}
?> ?>

View File

@ -151,4 +151,50 @@ function track_retrieve_details($visitor)
return unserialize($visitor['details']); return unserialize($visitor['details']);
} }
/**
* Remove old visitors
*/
function track_remove_old_visitors() {
$db = Database::getInstance();
// Remove associations of visitors with closed threads
$db->query(
"UPDATE {chatsitevisitor} SET threadid = NULL " .
"WHERE threadid IS NOT NULL AND " .
" (SELECT count(*) FROM {chatthread} " .
"WHERE threadid = {chatsitevisitor}.threadid" .
" AND istate <> " . Thread::STATE_CLOSED . " " .
" AND istate <> " . Thread::STATE_LEFT . ") = 0"
);
// Remove old visitors
$db->query(
"DELETE FROM {chatsitevisitor} " .
"WHERE (:now - lasttime) > :lifetime ".
"AND threadid IS NULL",
array(
':lifetime' => Settings::get('tracking_lifetime'),
':now' => time()
)
);
}
/**
* Remove old tracks
*/
function track_remove_old_tracks() {
$db = Database::getInstance();
// Remove old visitors' tracks
$db->query(
"DELETE FROM {visitedpage} WHERE (:now - visittime) > :lifetime " .
" AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor})",
array(
':lifetime' => Settings::get('tracking_lifetime'),
':now' => time()
)
);
}
?> ?>

View File

@ -20,6 +20,7 @@ require_once('../libs/chat.php');
require_once('../libs/userinfo.php'); require_once('../libs/userinfo.php');
require_once('../libs/operator.php'); require_once('../libs/operator.php');
require_once('../libs/groups.php'); require_once('../libs/groups.php');
require_once('../libs/invitation.php');
require_once('../libs/track.php'); require_once('../libs/track.php');
require_once('../libs/classes/thread.php'); require_once('../libs/classes/thread.php');
require_once('../libs/classes/mibew_api.php'); require_once('../libs/classes/mibew_api.php');