From ebe7ce0aa7c1420099692f014fad04e88ba5a8f0 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Mon, 6 Nov 2023 11:38:25 +0100 Subject: [PATCH] Delete a report content by event on delete a content --- Events.php | 8 ++++++++ config.php | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Events.php b/Events.php index ee5944b..321a799 100644 --- a/Events.php +++ b/Events.php @@ -177,6 +177,14 @@ public static function onCommentAppendRules($event) ]; } + public static function onContentBeforeDelete($event) + { + $reports = ReportContent::find()->where(['content_id' => $event->sender->id]); + foreach ($reports->each() as $report) { + $report->delete(); + } + } + private static function blockFilteredPosts(): bool { /** @var Module $module */ diff --git a/config.php b/config.php index 480df59..22518c8 100755 --- a/config.php +++ b/config.php @@ -5,6 +5,7 @@ use humhub\modules\admin\widgets\AdminMenu; use humhub\modules\comment\models\Comment; use humhub\modules\comment\widgets\CommentControls; +use humhub\modules\content\models\Content; use humhub\modules\content\widgets\WallEntryControls; use humhub\modules\post\models\Post; use humhub\modules\reportcontent\Events; @@ -27,5 +28,6 @@ [Comment::class, ActiveRecord::EVENT_APPEND_RULES, [Events::class, 'onCommentAppendRules']], [Comment::class, ActiveRecord::EVENT_AFTER_INSERT, [Events::class, 'onCommentAfterSave']], [Comment::class, ActiveRecord::EVENT_AFTER_UPDATE, [Events::class, 'onCommentAfterSave']], + [Content::class, Content::EVENT_BEFORE_DELETE, [Events::class, 'onContentBeforeDelete']], ] -]; \ No newline at end of file +];