Removed wcf1_user_activity_point_event
authorAlexander Ebert <ebert@woltlab.com>
Thu, 11 Jul 2013 11:55:26 +0000 (13:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 11 Jul 2013 11:55:26 +0000 (13:55 +0200)
wcfsetup/install/files/acp/update_b4.php [deleted file]
wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEvent.class.php [deleted file]
wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventAction.class.php [deleted file]
wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventEditor.class.php [deleted file]
wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventList.class.php [deleted file]
wcfsetup/install/files/lib/system/like/LikeHandler.class.php
wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php
wcfsetup/setup/db/install.sql

diff --git a/wcfsetup/install/files/acp/update_b4.php b/wcfsetup/install/files/acp/update_b4.php
deleted file mode 100644 (file)
index 0810ba5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-use wcf\system\WCF;
-
-$removeFiles = array(
-       'style/like.less',
-       'style/recaptcha.less',
-       'style/search.less'
-);
-
-$sql = "DELETE FROM    wcf".WCF_N."_package_installation_file_log
-       WHERE           packageID = ?
-                       AND filename = ?";
-$statement = WCF::getDB()->prepareStatement($sql);
-foreach ($removeFiles as $file) {
-       if (file_exists(WCF_DIR.$file)) {
-               @unlink(WCF_DIR.$file);
-               
-               $statement->execute(array(1, $file));
-       }
-}
diff --git a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEvent.class.php b/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEvent.class.php
deleted file mode 100644 (file)
index a62d41e..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-namespace wcf\data\user\activity\point\event;
-use wcf\data\DatabaseObject;
-
-/**
- * Represents a user activity point event.
- * 
- * @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 data.user.activity.point.event
- * @category   Community Framework
- */
-class UserActivityPointEvent extends DatabaseObject {
-       /**
-        * @see wcf\data\DatabaseObject::$databaseTableName
-        */
-       protected static $databaseTableName = 'user_activity_point_event';
-       
-       /**
-        * @see wcf\data\DatabaseObject::$databaseTableIndexName
-        */
-       protected static $databaseTableIndexName = 'eventID';
-       
-       /**
-        * @see wcf\data\IStorableObject::__get()
-        */
-       public function __get($name) {
-               $value = parent::__get($name);
-               
-               // treat additional data as data variables if it is an array
-               if ($value === null && isset($this->data['additionalData'][$name])) {
-                       $value = $this->data['additionalData'][$name];
-               }
-               
-               return $value;
-       }
-       
-       /**
-        * @see wcf\data\DatabaseObject::handleData()
-        */
-       protected function handleData($data) {
-               parent::handleData($data);
-               
-               $this->data['additionalData'] = @unserialize($this->data['additionalData']);
-               if (!is_array($this->data['additionalData'])) {
-                       $this->data['additionalData'] = array();
-               }
-       }
-}
diff --git a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventAction.class.php b/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventAction.class.php
deleted file mode 100644 (file)
index 9b12d41..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-namespace wcf\data\user\activity\point\event;
-use wcf\data\AbstractDatabaseObjectAction;
-
-/**
- * Executes user activity point event-related actions.
- * 
- * @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 data.user.activity.point.event
- * @category   Community Framework
- */
-class UserActivityPointEventAction extends AbstractDatabaseObjectAction { }
diff --git a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventEditor.class.php b/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventEditor.class.php
deleted file mode 100644 (file)
index 0614047..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-namespace wcf\data\user\activity\point\event;
-use wcf\data\DatabaseObjectEditor;
-
-/**
- * Provides functions to edit user activity point events.
- * 
- * @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 data.user.activity.point.event
- * @category   Community Framework
- */
-class UserActivityPointEventEditor extends DatabaseObjectEditor {
-       /**
-        * @see wcf\data\DatabaseObjectDecorator::$baseClass
-        */
-       protected static $baseClass = 'wcf\data\user\activity\point\event\UserActivityPointEvent';
-}
diff --git a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventList.class.php b/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventList.class.php
deleted file mode 100644 (file)
index 0266e5e..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-namespace wcf\data\user\activity\point\event;
-use wcf\data\DatabaseObjectList;
-
-/**
- * Represents a list of user activity point events.
- * 
- * @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 data.user.activity.point.event
- * @category   Community Framework
- */
-class UserActivityPointEventList extends DatabaseObjectList { }
index 3ed6e1d1a60d85536c4eb94a2660f05a10c3ed7e..fd1a85a74af63b21eeb8d62ebfcf561fbf12c8a3 100644 (file)
@@ -290,7 +290,7 @@ class LikeHandler extends SingletonFactory {
                                        'likeValue' => $likeValue
                                ));
                                
-                               if ($likeValue == Like::DISLIKE) UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($like->likeID));
+                               if ($likeValue == Like::DISLIKE) UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($user->userID => 1));
                        }
                        
                        // update object's like counter
@@ -379,7 +379,7 @@ class LikeHandler extends SingletonFactory {
                                        ));
                                }
                                
-                               UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($like->likeID));
+                               UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($likeable->getUserID() => 1));
                        }
                        
                        // update object's like counter
@@ -435,15 +435,19 @@ class LikeHandler extends SingletonFactory {
                $likeList = new LikeList();
                $likeList->getConditionBuilder()->add('like_table.objectTypeID = ?', array($objectTypeObj->objectTypeID));
                $likeList->getConditionBuilder()->add('like_table.objectID IN (?)', array($objectIDs));
-               $likeList->readObjectIDs();
-               $likeIDs = $likeList->getObjectIDs();
+               $likeList->readObjects();
                
-               if (!empty($likeIDs)) {
+               if (count($likeList)) {
+                       $likeData = array();
+                       foreach ($likeList as $like) {
+                               $likeData[$like->likeID] = $like->userID;
+                       }
+                       
                        // revoke activity points
-                       UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeIDs);
+                       UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeData);
                        
                        // delete likes
-                       LikeEditor::deleteAll($likeIDs);
+                       LikeEditor::deleteAll(array_keys($likeData));
                }
                
                // delete like objects
index c5814610dae1c4ab9a7047b39a72c6c56cbdf12b..5c08b24eb0e7554d07bfbaf08dfe55cecf5bf0a6 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\user\activity\point;
+use wcf\data\object\type\ObjectType;
+
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\user\activity\point\event\UserActivityPointEventAction;
 use wcf\data\user\UserProfileAction;
@@ -59,20 +61,31 @@ class UserActivityPointHandler extends SingletonFactory {
                if ($userID === null) $userID = WCF::getUser()->userID;
                if (!$userID) throw new SystemException("Cannot fire user activity point events for guests");
                
-               $objectAction = new UserActivityPointEventAction(array(), 'create', array(
-                       'data' => array(
-                               'objectTypeID' => $objectTypeObj->objectTypeID,
-                               'objectID' => $objectID,
-                               'userID' => $userID,
-                               'additionalData' => serialize($additionalData)
-                       )
+               // update user_activity_point
+               $sql = "INSERT INTO             wcf".WCF_N."_user_activity_point
+                                               (userID, objectTypeID, activityPoints, items)
+                       VALUES                  (?, ?, ?, 1)
+                       ON DUPLICATE KEY
+                       UPDATE                  activityPoints = activityPoints + VALUES(activityPoints),
+                                               items = items + 1";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $userID,
+                       $objectType->objectTypeID,
+                       $objectType->points
                ));
-               $returnValues = $objectAction->executeAction();
-               $event = $returnValues['returnValues'];
                
-               $this->updateUser($userID, $objectType);
+               $sql = "UPDATE  wcf".WCF_N."_user
+                       SET     activityPoints = activityPoints + ?
+                       WHERE   userID = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $objectType->points,
+                       $userID
+               ));
                
-               return $event;
+               // update user ranks
+               $this->updateUserRanks(array($userID));
        }
        
        /**
@@ -95,37 +108,61 @@ class UserActivityPointHandler extends SingletonFactory {
                        throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
                }
                
-               $sql = "INSERT INTO     wcf".WCF_N."_user_activity_point_event
-                                       (objectTypeID, objectID, userID, additionalData)
-                       VALUES          (?, ?, ?, ?)";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               
-               WCF::getDB()->beginTransaction();
-               $userIDs = array();
-               foreach ($data as $objectID => $objectData) {
-                       $statement->execute(array(
-                               $objectTypeObj->objectTypeID,
-                               $objectID,
-                               $objectData['userID'],
-                               (isset($objectData['additionalData']) ? serialize($objectData['additionalData']) : '')
-                       ));
+               // update user_activity_point
+               $values = '';
+               $parameters = $userIDs = array();
+               foreach ($data as $event) {
+                       if (!empty($values)) $values .= ',';
+                       $values .= '(?, ?, ?)';
+                       $parameters[] = $event['userID'];
+                       $parameters[] = $objectTypeObj->objectTypeID;
+                       $parameters[] = $objectTypeObj->points;
                        
-                       $userIDs[] = $objectData['userID'];
+                       $userIDs[] = $event['userID'];
                }
-               WCF::getDB()->commitTransaction();
                
+               $sql = "INSERT INTO             wcf".WCF_N."_user_activity_point
+                                               (userID, objectTypeID, activityPoints, items)
+                       VALUES                  ".$values."
+                       ON DUPLICATE KEY
+                       UPDATE                  activityPoints = activityPoints + VALUES(activityPoints),
+                                               items = items + 1";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($parameters);
+               
+               // update activity points for given user ids
                $userIDs = array_unique($userIDs);
-               $this->updateUsers($userIDs, $objectType);
+               $conditions = new PreparedStatementConditionBuilder();
+               $conditions->add("userID IN (?)", array($userIDs));
+               
+               $sql = "UPDATE  wcf".WCF_N."_user user_table
+                       SET     activityPoints = COALESCE((
+                                       SELECT          SUM(activityPoints) AS activityPoints
+                                       FROM            wcf".WCF_N."_user_activity_point
+                                       WHERE           userID = user_table.userID
+                                       GROUP BY        userID
+                               ), 0)
+                       ".$conditions;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($conditions->getParameters());
+               
+               // update user ranks
+               $this->updateUserRanks($userIDs);
        }
        
        /**
         * Removes activity point events.
         * 
         * @param       string                  $objectType
-        * @param       array<integer>          $objectIDs
+        * @param       array<integer>          $userToItems
         */
-       public function removeEvents($objectType, array $objectIDs) {
-               if (empty($objectIDs)) return;
+       public function removeEvents($objectType, array $userToItems) {
+               // ignore values for guests
+               if (isset($userToItems[0])) {
+                       unset($userToItems[0]);
+               }
+               
+               if (empty($userToItems)) return;
                
                // get and validate object type
                $objectTypeObj = $this->getObjectTypeByName($objectType);
@@ -133,30 +170,37 @@ class UserActivityPointHandler extends SingletonFactory {
                        throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
                }
                
-               // get user ids
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("objectTypeID = ?", array($objectTypeObj->objectTypeID));
-               $conditions->add("objectID IN (?)", array($objectIDs));
-               $sql = "SELECT  DISTINCT userID
-                       FROM    wcf".WCF_N."_user_activity_point_event
-                       ".$conditions;
+               // remove activity points
+               $sql = "UPDATE  wcf".WCF_N."_user_activity_point
+                       SET     activityPoints = activityPoints - ?,
+                               items = items - ?
+                       WHERE   objectTypeID = ?
+                               AND userID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditions->getParameters());
-               
-               $userIDs = array();
-               while ($row = $statement->fetchArray()) {
-                       $userIDs[] = $row['userID'];
+               foreach ($userToItems as $userID => $items) {
+                       $statement->execute(array(
+                               ($items * $objectTypeObj->points),
+                               $items,
+                               $objectTypeObj->objectTypeID,
+                               $userID
+                       ));
                }
                
-               // delete events
-               $sql = "DELETE FROM     wcf".WCF_N."_user_activity_point_event
+               // update total activity points per user
+               $userIDs = array_keys($userIDs);
+               $conditions = new PreparedStatementConditionBuilder();
+               $conditions->add("userID IN (?)", array($userIDs));
+               
+               $sql = "UPDATE  wcf".WCF_N."_user user_table
+                       SET     activityPoints = COALESCE((
+                                       SELECT          SUM(activityPoints) AS activityPoints
+                                       FROM            wcf".WCF_N."_user_activity_point
+                                       WHERE           userID = user_table.userID
+                                       GROUP BY        userID
+                               ), 0)
                        ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditions->getParameters());
-               
-               if (!empty($userIDs)) {
-                       $this->updateUsers($userIDs, $objectType);
-               }
        }
        
        /**
@@ -189,139 +233,6 @@ class UserActivityPointHandler extends SingletonFactory {
                return null;
        }
        
-       /**
-        * Updates the caches for the given user.
-        * 
-        * @param       integer         $userID
-        * @param       string          $objectType
-        */
-       public function updateUser($userID, $objectType) {
-               $objectType = $this->getObjectTypeByName($objectType);
-               
-               // update user_activity_point
-               $sql = "SELECT  COUNT(*) AS count
-                       FROM    wcf".WCF_N."_user_activity_point
-                       WHERE   userID = ?
-                               AND objectTypeID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(
-                       $userID,
-                       $objectType->objectTypeID
-               ));
-               $row = $statement->fetchArray();
-               
-               // update existing entry
-               if ($row['count']) {
-                       $sql = "UPDATE  wcf".WCF_N."_user_activity_point
-                               SET     activityPoints = activityPoints + ?
-                               WHERE   userID = ?
-                                       AND objectTypeID = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $objectType->points,
-                               $userID,
-                               $objectType->objectTypeID
-                       ));
-               }
-               else {
-                       // create new entry
-                       $sql = "INSERT INTO     wcf".WCF_N."_user_activity_point
-                                               (userID, objectTypeID, activityPoints)
-                               VALUES          (?, ?, ?)";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array(
-                               $userID,
-                               $objectType->objectTypeID,
-                               $objectType->points
-                       ));
-               }
-               
-               $sql = "UPDATE  wcf".WCF_N."_user
-                       SET     activityPoints = activityPoints + ?
-                       WHERE   userID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(
-                       $objectType->points,
-                       $userID
-               ));
-               
-               // update user ranks
-               $this->updateUserRanks(array($userID));
-       }
-       
-       /**
-        * Updates activity points for given user ids and object type.
-        * 
-        * @param       array<integer>          $userIDs
-        * @param       string                  $objectType
-        */
-       public function updateUsers(array $userIDs, $objectType = null) {
-               $objectTypes = array();
-               if ($objectType === null) {
-                       $objectTypes = $this->objectTypes;
-               }
-               else {
-                       $objectTypeObj = $this->getObjectTypeByName($objectType);
-                       if ($objectTypeObj === null) {
-                               throw new SystemException("Object type '".$objectType."' is not valid for object type definition 'com.woltlab.wcf.user.activityPointEvent'");
-                       }
-                       $objectTypes[] = $objectTypeObj;
-               }
-               
-               $objectTypeIDs = array();
-               foreach ($objectTypes as $objectType) {
-                       $objectTypeIDs[] = $objectType->objectTypeID;
-               }
-               
-               // remove cached values first
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($userIDs));
-               $conditions->add("objectTypeID IN (?)", array($objectTypeIDs));
-               $sql = "DELETE FROM     wcf".WCF_N."_user_activity_point
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditions->getParameters());
-               
-               // update users for every given object type
-               WCF::getDB()->beginTransaction();
-               foreach ($objectTypes as $objectType) {
-                       $conditions = new PreparedStatementConditionBuilder();
-                       $conditions->add("userID IN (?)", array($userIDs));
-                       $conditions->add("objectTypeID = ?", array($objectType->objectTypeID));
-                       
-                       $parameters = $conditions->getParameters();
-                       array_unshift($parameters, $objectType->points);
-                       
-                       $sql = "INSERT INTO     wcf".WCF_N."_user_activity_point
-                                               (userID, objectTypeID, activityPoints)
-                               SELECT          userID, objectTypeID, (COUNT(*) * ?) AS activityPoints
-                               FROM            wcf".WCF_N."_user_activity_point_event
-                               ".$conditions."
-                               GROUP BY        userID, objectTypeID";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute($parameters);
-               }
-               WCF::getDB()->commitTransaction();
-               
-               // update activity points for given user ids
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($userIDs));
-               
-               $sql = "UPDATE  wcf".WCF_N."_user user_table
-                       SET     activityPoints = COALESCE((
-                                       SELECT          SUM(activityPoints) AS activityPoints
-                                       FROM            wcf".WCF_N."_user_activity_point
-                                       WHERE           userID = user_table.userID
-                                       GROUP BY        userID
-                               ), 0)
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditions->getParameters());
-               
-               // update user ranks
-               $this->updateUserRanks($userIDs);
-       }
-       
        /**
         * Updates the user ranks for the given users.
         * 
index b4c080fbc24b64ef0387cc2726a11a6246551560..c0d9b2e193c0616ccc52c163a10d948526415257 100644 (file)
@@ -1011,20 +1011,11 @@ CREATE TABLE wcf1_user_activity_point (
        userID INT(10) NOT NULL,
        objectTypeID INT(10) NOT NULL,
        activityPoints INT(10) NOT NULL DEFAULT 0,
+       items INT(10) NOT NULL DEFAULT 0,
        PRIMARY KEY (userID, objectTypeID),
        KEY (objectTypeID)
 );
 
-DROP TABLE IF EXISTS wcf1_user_activity_point_event;
-CREATE TABLE wcf1_user_activity_point_event (
-       eventID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-       objectTypeID INT(10) NOT NULL,
-       objectID INT(10) NOT NULL,
-       userID INT(10) NOT NULL,
-       additionalData TEXT,
-       UNIQUE KEY (objectTypeID, userID, objectID)
-);
-
 DROP TABLE IF EXISTS wcf1_user_avatar;
 CREATE TABLE wcf1_user_avatar (
        avatarID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -1488,9 +1479,6 @@ ALTER TABLE wcf1_user_activity_event ADD FOREIGN KEY (languageID) REFERENCES wcf
 ALTER TABLE wcf1_user_activity_point ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
 ALTER TABLE wcf1_user_activity_point ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
 
-ALTER TABLE wcf1_user_activity_point_event ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
-ALTER TABLE wcf1_user_activity_point_event ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
-
 ALTER TABLE wcf1_user_profile_visitor ADD FOREIGN KEY (ownerID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
 ALTER TABLE wcf1_user_profile_visitor ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;