From: Alexander Ebert Date: Thu, 11 Jul 2013 11:55:26 +0000 (+0200) Subject: Removed wcf1_user_activity_point_event X-Git-Tag: 2.0.0_Beta_5~77 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a16ee1106dcb0b640768921844c3c2ef430969bd;p=GitHub%2FWoltLab%2FWCF.git Removed wcf1_user_activity_point_event --- diff --git a/wcfsetup/install/files/acp/update_b4.php b/wcfsetup/install/files/acp/update_b4.php deleted file mode 100644 index 0810ba5d2a..0000000000 --- a/wcfsetup/install/files/acp/update_b4.php +++ /dev/null @@ -1,20 +0,0 @@ -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 index a62d41ea72..0000000000 --- a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEvent.class.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @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 index 9b12d41f1b..0000000000 --- a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventAction.class.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @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 index 061404734d..0000000000 --- a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventEditor.class.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @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 index 0266e5eb3e..0000000000 --- a/wcfsetup/install/files/lib/data/user/activity/point/event/UserActivityPointEventList.class.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.user.activity.point.event - * @category Community Framework - */ -class UserActivityPointEventList extends DatabaseObjectList { } diff --git a/wcfsetup/install/files/lib/system/like/LikeHandler.class.php b/wcfsetup/install/files/lib/system/like/LikeHandler.class.php index 3ed6e1d1a6..fd1a85a74a 100644 --- a/wcfsetup/install/files/lib/system/like/LikeHandler.class.php +++ b/wcfsetup/install/files/lib/system/like/LikeHandler.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php b/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php index c5814610da..5c08b24eb0 100644 --- a/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/point/UserActivityPointHandler.class.php @@ -1,5 +1,7 @@ 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 $objectIDs + * @param array $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 $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. * diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index b4c080fbc2..c0d9b2e193 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -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;