From ab4120721f6d51281dbeac59ca1acf7ec36d1da9 Mon Sep 17 00:00:00 2001 From: Alexei Sorokin Date: Tue, 4 Aug 2020 13:23:31 +0300 Subject: [PATCH] [Favorite] Fix "Properly trigger DisfavorNotice on profile deletion" Calling find() inside delete() is probably not a good idea. --- modules/Favorite/FavoriteModule.php | 9 ++++++++- modules/Favorite/classes/Fave.php | 16 ++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/Favorite/FavoriteModule.php b/modules/Favorite/FavoriteModule.php index 4073690d06..ae33ad512f 100644 --- a/modules/Favorite/FavoriteModule.php +++ b/modules/Favorite/FavoriteModule.php @@ -342,7 +342,14 @@ class FavoriteModule extends ActivityVerbHandlerModule { $fave = new Fave(); $fave->user_id = $profile->id; - $fave->delete(); // Will perform a DELETE matching "user_id = {$user->id}" + + // Will perform a DELETE matching "user_id = {$user->id}" + if ($fave->find()) { + while ($fave->fetch()) { + $fave->delete(); + } + } + $fave->free(); Fave::blowCacheForProfileId($profile->id); diff --git a/modules/Favorite/classes/Fave.php b/modules/Favorite/classes/Fave.php index 3a42c21ff4..285f0f684c 100644 --- a/modules/Favorite/classes/Fave.php +++ b/modules/Favorite/classes/Fave.php @@ -137,18 +137,14 @@ class Fave extends Managed_DataObject $result = null; try { - if ($this->find()) { - while ($this->fetch()) { - $profile = $this->getActor(); - $notice = $this->getTarget(); + $profile = $this->getActor(); + $notice = $this->getTarget(); - if (Event::handle('StartDisfavorNotice', [$profile, $notice, &$result])) { - $result = parent::delete($useWhere); + if (Event::handle('StartDisfavorNotice', [$profile, $notice, &$result])) { + $result = parent::delete($useWhere); - if ($result !== false) { - Event::handle('EndDisfavorNotice', [$profile, $notice]); - } - } + if ($result !== false) { + Event::handle('EndDisfavorNotice', [$profile, $notice]); } } } catch (NoResultException $e) {