mirror of
				https://github.com/Mibew/java.git
				synced 2025-10-31 10:31:07 +03:00 
			
		
		
		
	Move remove invitations and visitors functionality to corresponding libs
This commit is contained in:
		
							parent
							
								
									0cdd55cdf8
								
							
						
					
					
						commit
						37de991028
					
				| @ -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, " . | ||||
|  | ||||
| @ -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() | ||||
| 		) | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
| @ -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() | ||||
| 		) | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| ?>
 | ||||
| @ -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'); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user