From 37de9910287f26cd2d55a8d22db53d9d0a619292 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 4 Feb 2013 09:45:18 +0000 Subject: [PATCH] Move remove invitations and visitors functionality to corresponding libs --- .../webim/libs/classes/users_processor.php | 53 +++---------------- src/messenger/webim/libs/invitation.php | 18 +++++++ src/messenger/webim/libs/track.php | 46 ++++++++++++++++ src/messenger/webim/operator/update.php | 1 + 4 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/messenger/webim/libs/classes/users_processor.php b/src/messenger/webim/libs/classes/users_processor.php index ae41a08b..19f38f86 100644 --- a/src/messenger/webim/libs/classes/users_processor.php +++ b/src/messenger/webim/libs/classes/users_processor.php @@ -342,54 +342,15 @@ class UsersProcessor extends ClientSideProcessor { // Check access 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(); - // 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 $query = "SELECT visitorid, userid, username, firsttime, lasttime, " . "entry, details, invited, invitationtime, invitedby, " . diff --git a/src/messenger/webim/libs/invitation.php b/src/messenger/webim/libs/invitation.php index ae9058c2..2faf0772 100644 --- a/src/messenger/webim/libs/invitation.php +++ b/src/messenger/webim/libs/invitation.php @@ -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() + ) + ); +} + ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/track.php b/src/messenger/webim/libs/track.php index 1c61b6f2..678ecdad 100644 --- a/src/messenger/webim/libs/track.php +++ b/src/messenger/webim/libs/track.php @@ -151,4 +151,50 @@ function track_retrieve_details($visitor) 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() + ) + ); +} + + ?> \ No newline at end of file diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php index b47a7a97..79383ab3 100644 --- a/src/messenger/webim/operator/update.php +++ b/src/messenger/webim/operator/update.php @@ -20,6 +20,7 @@ require_once('../libs/chat.php'); require_once('../libs/userinfo.php'); require_once('../libs/operator.php'); require_once('../libs/groups.php'); +require_once('../libs/invitation.php'); require_once('../libs/track.php'); require_once('../libs/classes/thread.php'); require_once('../libs/classes/mibew_api.php');