From 66cf5bb33ca9d131a7970926c90c36591154da21 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Tue, 3 Jan 2017 19:39:28 +0100 Subject: [PATCH] Add a function to set a object visit by given userIDs (#2159) * Add a function to set a object visit by given userIDs * Add transaction and reformat code * Add whitspaces * fix indentation --- .../visitTracker/VisitTracker.class.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php b/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php index 79b4c8466e..6f895241e7 100644 --- a/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php +++ b/wcfsetup/install/files/lib/system/visitTracker/VisitTracker.class.php @@ -148,6 +148,30 @@ class VisitTracker extends SingletonFactory { } } + /** + * Tracks an object visit for the users with the given ids. + * + * @param string $objectType + * @param integer $objectID + * @param integer[] $userIDs + * @param int $time + */ + public function trackObjectVisitByUserIDs($objectType, $objectID, array $userIDs, $time = TIME_NOW) { + // save visit + $sql = "REPLACE INTO wcf".WCF_N."_tracked_visit + (objectTypeID, objectID, userID, visitTime) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + $objectTypeID = $this->getObjectTypeID($objectType); + WCF::getDB()->beginTransaction(); + + foreach ($userIDs as $userID) { + $statement->execute([$objectTypeID, $objectID, $userID, $time]); + } + + WCF::getDB()->commitTransaction(); + } + /** * Tracks an object visit. * -- 2.20.1