Skip to content

Commit

Permalink
Delete a report content by event on delete a content
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Nov 6, 2023
1 parent 34b802a commit ebe7ce0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']],
]
];
];

0 comments on commit ebe7ce0

Please sign in to comment.