Fixed recalculation of points per activity event
authorAlexander Ebert <ebert@woltlab.com>
Fri, 19 Jul 2013 19:53:00 +0000 (21:53 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 19 Jul 2013 19:53:00 +0000 (21:53 +0200)
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/objectTypeDefinition.xml
wcfsetup/install/files/lib/system/user/activity/point/AbstractUserActivityPointObjectProcessor.class.php [deleted file]
wcfsetup/install/files/lib/system/user/activity/point/DefaultUserActivityPointObjectProcessor.class.php [deleted file]
wcfsetup/install/files/lib/system/user/activity/point/IUserActivityPointObjectProcessor.class.php [deleted file]
wcfsetup/install/files/lib/system/user/activity/point/ReceivedLikesUserActivityPointObjectProcessor.class.php [deleted file]
wcfsetup/install/files/lib/system/worker/UserActivityPointUpdateEventsWorker.class.php

index 0c0a13e81c76ce33642042997173b3eed60b00a6..d2ea058343585b913b53a57a3ef784f07c1e6386 100644 (file)
                        <name>com.woltlab.wcf.like.activityPointEvent.receivedLikes</name>
                        <definitionname>com.woltlab.wcf.user.activityPointEvent</definitionname>
                        <points>1</points>
-                       <classname><![CDATA[wcf\system\user\activity\point\ReceivedLikesUserActivityPointObjectProcessor]]></classname>
                </type>
                <!-- /activity points -->
                
index d2c7abb46324b7113ffeb0b21c1579d83fc56fe7..8c0aebab70680118a8095e43efd1b32e0eddd0e7 100644 (file)
@@ -43,7 +43,6 @@
                
                <definition>
                        <name>com.woltlab.wcf.user.activityPointEvent</name>
-                       <interfacename><![CDATA[wcf\system\user\activity\point\IUserActivityPointObjectProcessor]]></interfacename>
                </definition>
                
                <definition>
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 (file)
index b3b2ced..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-namespace wcf\system\user\activity\point;
-use wcf\data\object\type\AbstractObjectTypeProcessor;
-
-/**
- * Abstract implementation of a user activity point object processor.
- * 
- * @author     Matthias Schmidt
- * @copyright  2001-2013 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index dfcd511..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-namespace wcf\system\user\activity\point;
-
-/**
- * Default implementation of a user activity point object processor.
- * 
- * @author     Tim Duesterhus
- * @copyright  2001-2013 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index 6ca00ba..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-namespace wcf\system\user\activity\point;
-use wcf\data\IDatabaseObjectProcessor;
-
-/**
- * Every UserActivityPointObjectProcessor has to implement this interface.
- * 
- * @author     Tim Duesterhus
- * @copyright  2001-2013 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index 3c99a2a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-namespace wcf\system\user\activity\point;
-use wcf\data\like\Like;
-use wcf\data\object\type\ObjectType;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\WCF;
-
-/**
- * Updates events for received likes.
- * 
- * @author     Tim Duesterhus
- * @copyright  2001-2013 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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()));
-               }
-       }
-}
index bd4e1df92081279bccb87f26bf270d35ca08a0a8..1cd386af937d79129cd937b98e4facd521e5af4a 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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++;
                }
        }