From 6eab41377a8b8937c1b70dbbc31fa784740abf4b Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Mon, 27 Sep 2021 13:16:31 +0200 Subject: [PATCH] Fix removing reactions on guests content Since MySQL 8 the deletion of reactions on contents created by guests might fail. The ReactionHandler tries to update the likesReceived column for a non-existent user, sending the empty string as the userID. Recent versions of MySQL 8 error out with MySQL error 1292. The following MySQL bug appears to be related: https://bugs.mysql.com/bug.php?id=101806 --- .../lib/system/reaction/ReactionHandler.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index c0394173ea..9ec09d24dd 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -687,7 +687,7 @@ class ReactionHandler extends SingletonFactory // reduce count of received users $users = []; foreach ($likeObjects as $likeObject) { - if ($likeObject->likes) { + if ($likeObject->likes && $likeObject->objectUserID) { if (!isset($users[$likeObject->objectUserID])) { $users[$likeObject->objectUserID] = 0; } @@ -699,7 +699,7 @@ class ReactionHandler extends SingletonFactory foreach ($users as $userID => $reactionData) { $userEditor = new UserEditor(new User(null, ['userID' => $userID])); $userEditor->updateCounters([ - 'likesReceived' => $users[$userID], + 'likesReceived' => $reactionData, ]); } @@ -714,10 +714,12 @@ class ReactionHandler extends SingletonFactory foreach ($likeList as $like) { $likeData[$like->likeID] = $like->userID; - if (!isset($activityPoints[$like->objectUserID])) { - $activityPoints[$like->objectUserID] = 0; + if ($like->objectUserID) { + if (!isset($activityPoints[$like->objectUserID])) { + $activityPoints[$like->objectUserID] = 0; + } + $activityPoints[$like->objectUserID]++; } - $activityPoints[$like->objectUserID]++; } // delete like notifications -- 2.20.1