c2c2b057767230cd89fbc35255fefc5109315231
[GitHub/WoltLab/woltlab.github.io.git] /
1 <?php
2
3 namespace wcf\system\event\listener;
4
5 use wcf\system\database\util\PreparedStatementConditionBuilder;
6 use wcf\system\user\activity\point\UserActivityPointHandler;
7 use wcf\system\WCF;
8 use wcf\system\worker\UserActivityPointItemsRebuildDataWorker;
9
10 /**
11 * Updates the user activity point items counter for person information.
12 *
13 * @author Matthias Schmidt
14 * @copyright 2001-2021 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Event\Listener
17 */
18 class PersonUserActivityPointItemsRebuildDataWorkerListener extends AbstractEventListener
19 {
20 protected function onExecute(UserActivityPointItemsRebuildDataWorker $worker): void
21 {
22 $objectType = UserActivityPointHandler::getInstance()
23 ->getObjectTypeByName('com.woltlab.wcf.people.information');
24
25 $conditionBuilder = new PreparedStatementConditionBuilder();
26 $conditionBuilder->add('user_activity_point.objectTypeID = ?', [$objectType->objectTypeID]);
27 $conditionBuilder->add('user_activity_point.userID IN (?)', [$worker->getObjectList()->getObjectIDs()]);
28
29 $sql = "UPDATE wcf" . WCF_N . "_user_activity_point user_activity_point
30 SET user_activity_point.items = (
31 SELECT COUNT(*)
32 FROM wcf" . WCF_N . "_person_information person_information
33 WHERE person_information.userID = user_activity_point.userID
34 ),
35 user_activity_point.activityPoints = user_activity_point.items * ?
36 {$conditionBuilder}";
37 $statement = WCF::getDB()->prepareStatement($sql);
38 $statement->execute(\array_merge(
39 [$objectType->points],
40 $conditionBuilder->getParameters()
41 ));
42 }
43 }