Commit | Line | Data |
---|---|---|
e3667539 MW |
1 | <?php |
2 | namespace wcf\system\worker; | |
3 | use wcf\data\like\Like; | |
4 | use wcf\data\user\UserEditor; | |
5 | use wcf\data\user\UserProfileAction; | |
6 | use wcf\system\database\util\PreparedStatementConditionBuilder; | |
7 | use wcf\system\user\activity\point\UserActivityPointHandler; | |
8 | use wcf\system\WCF; | |
9 | ||
10 | /** | |
11 | * Worker implementation for updating users. | |
12 | * | |
13 | * @author Marcel Werk | |
2b6cb5c2 | 14 | * @copyright 2001-2015 WoltLab GmbH |
e3667539 MW |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
16 | * @package com.woltlab.wcf | |
17 | * @subpackage system.worker | |
18 | * @category Community Framework | |
19 | */ | |
20 | class UserRebuildDataWorker extends AbstractRebuildDataWorker { | |
21 | /** | |
0ad90fc3 | 22 | * @see \wcf\system\worker\AbstractRebuildDataWorker::$objectListClassName |
e3667539 MW |
23 | */ |
24 | protected $objectListClassName = 'wcf\data\user\UserList'; | |
25 | ||
26 | /** | |
0ad90fc3 | 27 | * @see \wcf\system\worker\AbstractWorker::$limit |
e3667539 MW |
28 | */ |
29 | protected $limit = 50; | |
30 | ||
31 | /** | |
0ad90fc3 | 32 | * @see \wcf\system\worker\AbstractRebuildDataWorker::initObjectList |
e3667539 MW |
33 | */ |
34 | protected function initObjectList() { | |
35 | parent::initObjectList(); | |
36 | ||
37 | $this->objectList->sqlOrderBy = 'user_table.userID'; | |
38 | } | |
39 | ||
40 | /** | |
0ad90fc3 | 41 | * @see \wcf\system\worker\IWorker::execute() |
e3667539 MW |
42 | */ |
43 | public function execute() { | |
44 | parent::execute(); | |
45 | ||
46 | $users = $userIDs = array(); | |
47 | foreach ($this->getObjectList() as $user) { | |
48 | $users[] = new UserEditor($user); | |
49 | $userIDs[] = $user->userID; | |
50 | } | |
51 | ||
52 | // update user ranks | |
53 | if (!empty($users)) { | |
54 | $action = new UserProfileAction($users, 'updateUserOnlineMarking'); | |
55 | $action->executeAction(); | |
56 | } | |
57 | ||
58 | if (!empty($userIDs)) { | |
59 | // update activity points | |
60 | UserActivityPointHandler::getInstance()->updateUsers($userIDs); | |
61 | ||
62 | // update like counter | |
63 | if (MODULE_LIKE) { | |
64 | $conditionBuilder = new PreparedStatementConditionBuilder(); | |
65 | $conditionBuilder->add('user_table.userID IN (?)', array($userIDs)); | |
66 | $sql = "UPDATE wcf".WCF_N."_user user_table | |
67 | SET likesReceived = ( | |
68 | SELECT COUNT(*) | |
69 | FROM wcf".WCF_N."_like | |
70 | WHERE objectUserID = user_table.userID | |
1e5b71d4 | 71 | AND likeValue = ".Like::LIKE." |
e3667539 MW |
72 | ) |
73 | ".$conditionBuilder; | |
74 | $statement = WCF::getDB()->prepareStatement($sql); | |
75 | $statement->execute($conditionBuilder->getParameters()); | |
76 | } | |
77 | } | |
78 | } | |
79 | } |