Add rebuild data worker for activity point `items` counter
authorMatthias Schmidt <gravatronics@live.com>
Sun, 23 Jun 2019 09:40:03 +0000 (11:40 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 23 Jun 2019 09:40:03 +0000 (11:40 +0200)
Close #2949

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/worker/UserActivityPointItemsRebuildDataWorker.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 3d0f0921dfb04dabd0c2bc2a3c53419dfe408b96..d6bc997d97ee111e3099b2248b85e89735c90538 100644 (file)
                        <classname>wcf\system\worker\UserRebuildDataWorker</classname>
                        <nicevalue>70</nicevalue>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.activityPointItems</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname>wcf\system\worker\UserActivityPointItemsRebuildDataWorker</classname>
+                       <nicevalue>75</nicevalue>
+               </type>
                <type>
                        <name>com.woltlab.wcf.attachment</name>
                        <definitionname>com.woltlab.wcf.rebuildData</definitionname>
diff --git a/wcfsetup/install/files/lib/system/worker/UserActivityPointItemsRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserActivityPointItemsRebuildDataWorker.class.php
new file mode 100644 (file)
index 0000000..21da3d3
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+namespace wcf\system\worker;
+use wcf\data\user\UserList;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\user\activity\point\UserActivityPointHandler;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for update the user activity point database table's `items` column
+ * and afterwards also the `activityPoints`
+ * 
+ * This worker is intended to run after the `UserRebuildDataWorker` so that the object counters
+ * in the `wcf1_user` table are updated.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Worker
+ * @since      5.2
+ * 
+ * @method     UserList        getObjectList()
+ */
+class UserActivityPointItemsRebuildDataWorker extends AbstractRebuildDataWorker {
+       /**
+        * @inheritDoc
+        */
+       protected $objectListClassName = UserList::class;
+       
+       /**
+        * @inheritDoc
+        */
+       protected $limit = 50;
+       
+       /**
+        * @inheritDoc
+        */
+       public function execute() {
+               parent::execute();
+               
+               if (count($this->getObjectList()) === 0) {
+                       return;
+               }
+               
+               // update activity points for positive reactions
+               $reactionObjectType = UserActivityPointHandler::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
+               
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add('user_activity_point.objectTypeID = ?', [$reactionObjectType->objectTypeID]);
+               $conditionBuilder->add('user_activity_point.userID IN (?)', [$this->getObjectList()->getObjectIDs()]);
+               
+               $sql = "UPDATE          wcf" . WCF_N . "_user_activity_point user_activity_point
+                       LEFT JOIN       wcf" . WCF_N . "_user user_table
+                       ON              (user_table.userID = user_activity_point.userID)
+                       SET             user_activity_point.items = user_table.positiveReactionsReceived,
+                                       user_activity_point.activityPoints = user_activity_point.items * ?
+                       " . $conditionBuilder;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array_merge(
+                       [$reactionObjectType->points],
+                       $conditionBuilder->getParameters()
+               ));
+               
+               // update activity points
+               UserActivityPointHandler::getInstance()->updateUsers($this->getObjectList()->getObjectIDs());
+       }
+}
index 7b38c7e9a56be7449eda6bbe08e4c63fbc02b484..d319285edbba05983e4e2feb6046a52eda3511cf 100644 (file)
@@ -14,7 +14,6 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\image\ImageHandler;
-use wcf\system\user\activity\point\UserActivityPointHandler;
 use wcf\system\WCF;
 
 /**
@@ -68,9 +67,6 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker {
                }
                
                if (!empty($userIDs)) {
-                       // update activity points
-                       UserActivityPointHandler::getInstance()->updateUsers($userIDs);
-                       
                        // update article counter
                        $conditionBuilder = new PreparedStatementConditionBuilder();
                        $conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
index 51f51e24f65f51d27ed4e88ee46979bfe8667a4e..42c82e02eda90ef7d2c175ccd979b7752478b053 100644 (file)
@@ -2605,6 +2605,8 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.sitemap.description"><![CDATA[Erstellt die Sitemap neu.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointEvent"><![CDATA[Punkte pro Aktivität aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointEvent.description"><![CDATA[Berechnet Punkte pro Aktivität neu]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointItems"><![CDATA[Punkte-Aktivitäten aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointItems.description"><![CDATA[Berechnet Anzahl an Aktivitäten neu, für die Benutzer Punkte erhalten]]></item>
        </category>
        <category name="wcf.acp.rescueMode">
                <item name="wcf.acp.rescueMode"><![CDATA[Systemwiederherstellung]]></item>
index 074d676f5bccc1410116e44ff235b85b00ecd126..a0a0281b5faea2cbb314393536e0e38045d3a662 100644 (file)
@@ -2532,7 +2532,9 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.sitemap"><![CDATA[Rebuild Sitemap]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.sitemap.description"><![CDATA[Rebuilds the sitemap.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointEvent"><![CDATA[Rebuilds Points per Activity]]></item>
-               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointEvent.description"><![CDATA[Recalculates points per activity]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointEvent.description"><![CDATA[Recalculates points per activity.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointItems"><![CDATA[Rebuilds Point Activities]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.activityPointItems.description"><![CDATA[Recalculates the number of activities for which users get points.]]></item>
        </category>
        <category name="wcf.acp.rescueMode">
                <item name="wcf.acp.rescueMode"><![CDATA[Rescue Mode]]></item>