From bb3de31c53c2d79a7164d308a433c8caddf9915a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 19 Jul 2013 21:53:00 +0200 Subject: [PATCH] Fixed recalculation of points per activity event --- com.woltlab.wcf/objectType.xml | 1 - com.woltlab.wcf/objectTypeDefinition.xml | 1 - ...UserActivityPointObjectProcessor.class.php | 21 ----- ...UserActivityPointObjectProcessor.class.php | 28 ------ ...UserActivityPointObjectProcessor.class.php | 31 ------- ...UserActivityPointObjectProcessor.class.php | 86 ------------------- ...rActivityPointUpdateEventsWorker.class.php | 29 ++++--- 7 files changed, 17 insertions(+), 180 deletions(-) delete mode 100644 wcfsetup/install/files/lib/system/user/activity/point/AbstractUserActivityPointObjectProcessor.class.php delete mode 100644 wcfsetup/install/files/lib/system/user/activity/point/DefaultUserActivityPointObjectProcessor.class.php delete mode 100644 wcfsetup/install/files/lib/system/user/activity/point/IUserActivityPointObjectProcessor.class.php delete mode 100644 wcfsetup/install/files/lib/system/user/activity/point/ReceivedLikesUserActivityPointObjectProcessor.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 0c0a13e81c..d2ea058343 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -145,7 +145,6 @@ com.woltlab.wcf.like.activityPointEvent.receivedLikes com.woltlab.wcf.user.activityPointEvent 1 - diff --git a/com.woltlab.wcf/objectTypeDefinition.xml b/com.woltlab.wcf/objectTypeDefinition.xml index d2c7abb463..8c0aebab70 100644 --- a/com.woltlab.wcf/objectTypeDefinition.xml +++ b/com.woltlab.wcf/objectTypeDefinition.xml @@ -43,7 +43,6 @@ com.woltlab.wcf.user.activityPointEvent - diff --git a/wcfsetup/install/files/lib/system/user/activity/point/AbstractUserActivityPointObjectProcessor.class.php b/wcfsetup/install/files/lib/system/user/activity/point/AbstractUserActivityPointObjectProcessor.class.php deleted file mode 100644 index b3b2cedca3..0000000000 --- a/wcfsetup/install/files/lib/system/user/activity/point/AbstractUserActivityPointObjectProcessor.class.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.user.activity.point - * @category Community Framework - */ -abstract class AbstractUserActivityPointObjectProcessor extends AbstractObjectTypeProcessor implements IUserActivityPointObjectProcessor { - /** - * number of objects processed during one request - * @var integer - */ - public $limit = 500; -} diff --git a/wcfsetup/install/files/lib/system/user/activity/point/DefaultUserActivityPointObjectProcessor.class.php b/wcfsetup/install/files/lib/system/user/activity/point/DefaultUserActivityPointObjectProcessor.class.php deleted file mode 100644 index dfcd5110cb..0000000000 --- a/wcfsetup/install/files/lib/system/user/activity/point/DefaultUserActivityPointObjectProcessor.class.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.user.activity.point - * @category Community Framework - */ -class DefaultUserActivityPointObjectProcessor extends AbstractUserActivityPointObjectProcessor { - /** - * @see wcf\system\user\activity\point\IUserActivityPointObject::countRequests(); - */ - public function countRequests() { - return 0; - } - - /** - * @see wcf\system\user\activity\point\IUserActivityPointObject::updateActivityPointEvents(); - */ - public function updateActivityPointEvents($request) { - return; - } -} diff --git a/wcfsetup/install/files/lib/system/user/activity/point/IUserActivityPointObjectProcessor.class.php b/wcfsetup/install/files/lib/system/user/activity/point/IUserActivityPointObjectProcessor.class.php deleted file mode 100644 index 6ca00bae61..0000000000 --- a/wcfsetup/install/files/lib/system/user/activity/point/IUserActivityPointObjectProcessor.class.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.user.activity.point - * @category Community Framework - */ -interface IUserActivityPointObjectProcessor extends IDatabaseObjectProcessor { - /** - * This method has to return the amount of requests needed to completely - * process this UserActivityPointObject. - * - * @return integer - */ - public function countRequests(); - - /** - * This method updates the activityPointEvents. $request will be an integer - * between 0 (first request) and the number returned by countRequests() minus 1. - * - * @param integer $request - */ - public function updateActivityPointEvents($request); -} diff --git a/wcfsetup/install/files/lib/system/user/activity/point/ReceivedLikesUserActivityPointObjectProcessor.class.php b/wcfsetup/install/files/lib/system/user/activity/point/ReceivedLikesUserActivityPointObjectProcessor.class.php deleted file mode 100644 index 3c99a2a7ca..0000000000 --- a/wcfsetup/install/files/lib/system/user/activity/point/ReceivedLikesUserActivityPointObjectProcessor.class.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.user.activity.point - * @category Community Framework - */ -class ReceivedLikesUserActivityPointObjectProcessor extends AbstractUserActivityPointObjectProcessor { - /** - * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::countRequests(); - */ - public function countRequests() { - $sql = "SELECT COUNT(*) - FROM wcf".WCF_N."_like - WHERE likeValue = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array(Like::LIKE)); - - return ceil($statement->fetchColumn() / $this->limit) + 1; - } - - /** - * @see wcf\system\user\activity\point\IUserActivityPointObjectProcessor::updateActivityPointEvents(); - */ - public function updateActivityPointEvents($request) { - if ($request == 0) { - // first request - $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event - WHERE objectTypeID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->objectTypeID)); - } - else { - $sql = "SELECT likeID - FROM wcf".WCF_N."_like - WHERE likeValue = ? - ORDER BY likeID ASC"; - $statement = WCF::getDB()->prepareStatement($sql, $this->limit, ($this->limit * ($request - 1))); - $statement->execute(array(Like::LIKE)); - $likeIDs = array(); - while ($row = $statement->fetchArray()) { - $likeIDs[] = $row['likeID']; - } - - if (empty($likeIDs)) return; - - $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add("objectTypeID = ?", array($this->objectTypeID)); - $conditionBuilder->add("objectID IN (?)", array($likeIDs)); - - // avoid problems with duplicate keys, as likes may be created in the meantime - $sql = "DELETE FROM wcf".WCF_N."_user_activity_point_event - ".$conditionBuilder; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditionBuilder->getParameters()); - - $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add("likeID IN (?)", array($likeIDs)); - - // use INSERT ... SELECT as this makes bulk updating easier - $sql = "INSERT INTO wcf".WCF_N."_user_activity_point_event - (userID, objectTypeID, objectID, additionalData) - SELECT objectUserID AS userID, - ?, - likeID AS objectID, - ? - FROM wcf".WCF_N."_like - ".$conditionBuilder; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array_merge(array( - $this->objectTypeID, - serialize(array()) - ), $conditionBuilder->getParameters())); - } - } -} diff --git a/wcfsetup/install/files/lib/system/worker/UserActivityPointUpdateEventsWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserActivityPointUpdateEventsWorker.class.php index bd4e1df920..1cd386af93 100644 --- a/wcfsetup/install/files/lib/system/worker/UserActivityPointUpdateEventsWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserActivityPointUpdateEventsWorker.class.php @@ -7,7 +7,7 @@ use wcf\system\WCF; /** * Worker implementation for updating user activity point events. * - * @author Tim Duesterhus + * @author Alexander Ebert * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf @@ -16,7 +16,6 @@ use wcf\system\WCF; */ class UserActivityPointUpdateEventsWorker extends AbstractWorker { /** - * Limiting is dependent on the actual processors. * @see wcf\system\worker\AbstractWorker::$limit */ protected $limit = 1; @@ -27,6 +26,9 @@ class UserActivityPointUpdateEventsWorker extends AbstractWorker { */ public $objectTypes = array(); + /** + * @see wcf\system\worker\IWorker + */ public function __construct(array $parameters) { parent::__construct($parameters); @@ -44,24 +46,27 @@ class UserActivityPointUpdateEventsWorker extends AbstractWorker { * @see wcf\system\worker\IWorker::countObjects() */ public function countObjects() { - $this->count = 0; - foreach ($this->objectTypes as $objectType) { - $objectType->requests = $objectType->getProcessor()->countRequests(); - $this->count += $objectType->requests; - } + $this->count = count($this->objectTypes); } /** * @see wcf\system\worker\IWorker::execute() */ public function execute() { - $loopCount = $this->loopCount; + $i = 0; foreach ($this->objectTypes as $objectType) { - if ($loopCount < $objectType->requests) { - $objectType->getProcessor()->updateActivityPointEvents($loopCount); - return; + if ($i == $this->loopCount) { + $sql = "UPDATE wcf".WCF_N."_user_activity_point + SET activityPoints = items * ? + WHERE objectTypeID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $objectType->points, + $objectType->objectTypeID + )); } - $loopCount -= $objectType->requests; + + $i++; } } -- 2.20.1