Skip to content

Commit 702f5dc

Browse files
Cyperghostdtdesign
andauthored
Implement a command to register user profile visitors (#6434)
* Implement a command to register user profile visitors * Rename the command and unify the parameters --------- Co-authored-by: Alexander Ebert <ebert@woltlab.com>
1 parent f328e68 commit 702f5dc

3 files changed

Lines changed: 54 additions & 17 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace wcf\command\user\profile;
4+
5+
use wcf\data\user\User;
6+
use wcf\system\WCF;
7+
8+
/**
9+
* Tracks a visit to a user profile, updating the time if the visitor is already
10+
* known.
11+
*
12+
* @author Olaf Braun
13+
* @copyright 2001-2025 WoltLab GmbH
14+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @since 6.3
16+
*/
17+
final class TrackUserProfileVisitor
18+
{
19+
public function __construct(
20+
private readonly User $user,
21+
private readonly User $target,
22+
private readonly int $time
23+
) {}
24+
25+
public function __invoke(): void
26+
{
27+
$sql = "INSERT INTO wcf1_user_profile_visitor
28+
(ownerID, userID, time)
29+
VALUES (?, ?, ?)
30+
ON DUPLICATE KEY UPDATE time = VALUES(time)";
31+
$statement = WCF::getDB()->prepare($sql);
32+
$statement->execute([
33+
$this->target->userID,
34+
$this->user->userID,
35+
$this->time,
36+
]);
37+
}
38+
}

wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace wcf\data\user\profile\visitor;
44

5+
use wcf\command\user\profile\TrackUserProfileVisitor;
56
use wcf\data\AbstractDatabaseObjectAction;
67
use wcf\data\IGroupedUserListAction;
78
use wcf\data\user\UserProfile;
@@ -95,18 +96,21 @@ public function getGroupedUserList()
9596
* Inserts a new visitor if it does not already exist, or updates it if it does.
9697
* @return void
9798
* @since 5.2
99+
*
100+
* @deprecated 6.3 use the `RegisterUserProfileVisitor` command instead.
98101
*/
99102
public function registerVisitor()
100103
{
101-
$sql = "INSERT INTO wcf1_user_profile_visitor
102-
(ownerID, userID, time)
103-
VALUES (?, ?, ?)
104-
ON DUPLICATE KEY UPDATE time = VALUES(time)";
105-
$statement = WCF::getDB()->prepare($sql);
106-
$statement->execute([
107-
$this->parameters['data']['ownerID'],
108-
$this->parameters['data']['userID'],
109-
$this->parameters['data']['time'] ?? TIME_NOW,
110-
]);
104+
$user = UserProfileRuntimeCache::getInstance()->getObject($this->parameters['data']['userID']);
105+
\assert($user !== null);
106+
107+
$target = UserProfileRuntimeCache::getInstance()->getObject($this->parameters['data']['ownerID']);
108+
\assert($target !== null);
109+
110+
(new TrackUserProfileVisitor(
111+
$user->getDecoratedObject(),
112+
$target->getDecoratedObject(),
113+
$this->parameters['data']['time'] ?? TIME_NOW
114+
))();
111115
}
112116
}

wcfsetup/install/files/lib/page/UserPage.class.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace wcf\page;
44

5+
use wcf\command\user\profile\TrackUserProfileVisitor;
56
use wcf\data\object\type\ObjectType;
67
use wcf\data\object\type\ObjectTypeCache;
78
use wcf\data\user\cover\photo\UserCoverPhoto;
89
use wcf\data\user\follow\UserFollowerList;
910
use wcf\data\user\follow\UserFollowingList;
1011
use wcf\data\user\group\UserGroup;
11-
use wcf\data\user\profile\visitor\UserProfileVisitorAction;
1212
use wcf\data\user\profile\visitor\UserProfileVisitorList;
1313
use wcf\data\user\UserEditor;
1414
use wcf\data\user\UserProfile;
@@ -207,12 +207,7 @@ public function show()
207207
// save visitor
208208
/** @noinspection PhpUndefinedFieldInspection */
209209
if (PROFILE_ENABLE_VISITORS && WCF::getUser()->userID && !WCF::getUser()->canViewOnlineStatus) {
210-
(new UserProfileVisitorAction([], 'registerVisitor', [
211-
'data' => [
212-
'ownerID' => $this->user->userID,
213-
'userID' => WCF::getUser()->userID,
214-
],
215-
]))->executeAction();
210+
(new TrackUserProfileVisitor(WCF::getUser(), $this->user->getDecoratedObject(), \TIME_NOW))();
216211
}
217212
}
218213

0 commit comments

Comments
 (0)