Add update script to delete all likeable recent activities
authorJoshua Rüsweg <ruesweg@woltlab.com>
Mon, 16 Dec 2019 17:18:10 +0000 (18:18 +0100)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Mon, 16 Dec 2019 17:18:10 +0000 (18:18 +0100)
com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.2_deleteRecentActivity.php [new file with mode: 0644]

index c2b2e3b9c51210c0b58deb68b7c93fd1f5bee773..be91906a810655957c5082ebdb783bbe2f0479df 100644 (file)
@@ -66,6 +66,9 @@
                <!-- Convert likes to reactions. -->
                <instruction type="script" flushCache="false">acp/update_com.woltlab.wcf_5.2_reactionUpdate.php</instruction>
                
+               <!-- Delete all likeable recent activity events, because they don't have the reactionType stored. -->
+               <instruction type="script" flushCache="false">acp/update_com.woltlab.wcf_5.2_deleteRecentActivity.php</instruction>
+               
                <instruction type="sql">update_5.2.sql</instruction>
                
                <instruction type="option" />
                <instruction type="style" run="standalone">defaultStyle.tar</instruction>
        </instructions>
        
+       <!-- @TODO Add script to delete the likeable recent activities.  -->
        <instructions type="update" fromversion="5.2.0 Beta 4">
                <instruction type="acpTemplate">acptemplates_update.tar</instruction>
                <instruction type="file">files_update.tar</instruction>
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.2_deleteRecentActivity.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.2_deleteRecentActivity.php
new file mode 100644 (file)
index 0000000..5e3df84
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+/**
+ * This script deletes all recent activity events for likes. Running this script is necessary after an update to version 5.2,
+ * because with this version the reaction system was introduced and the events there were changed so that they contain the
+ * reaction type, which is not present in previous fired events. Older events will otherwise throw an error.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core
+ */
+
+$definitionList = new \wcf\data\object\type\definition\ObjectTypeDefinitionList();
+$definitionList->getConditionBuilder()->add('definitionName = ?', ['com.woltlab.wcf.user.recentActivityEvent']);
+$definitionList->readObjects();
+$definition = $definitionList->current();
+
+$recentActivityList = new \wcf\data\user\activity\event\UserActivityEventList();
+$recentActivityList->getConditionBuilder()->add("objectTypeID IN (SELECT objectTypeID FROM wcf". WCF_N ."_object_type WHERE objectType LIKE '%likeable%' AND definitionID = ?)", [$definition->definitionID]);
+$recentActivityList->readObjectIDs();
+
+if (count($recentActivityList->getObjectIDs())) {
+       \wcf\data\user\activity\event\UserActivityEventEditor::deleteAll($recentActivityList->getObjectIDs());
+}