From 34b802a0045aed7f5854a77f2dada9e2de7607e7 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Thu, 2 Nov 2023 12:54:53 +0100 Subject: [PATCH 1/2] Fix error on open old notification --- docs/CHANGELOG.md | 1 + notifications/NewReportAdmin.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c001f58..a10a704 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog 1.0.4 (Unreleased) ---------------------- - Enh #71: Tests for `next` version +- Fix #72: Fix error on open old notification 1.0.3 (July 10, 2023) --------------------- diff --git a/notifications/NewReportAdmin.php b/notifications/NewReportAdmin.php index 156ca00..8911caa 100644 --- a/notifications/NewReportAdmin.php +++ b/notifications/NewReportAdmin.php @@ -62,6 +62,10 @@ public function getUrl() { $reportedRecord = $this->getReportedRecord(); + if ($reportedRecord === null) { + return Url::to([Yii::$app->user->isAdmin() ? '/reportcontent/admin' : '/dashboard']); + } + if (Yii::$app->user->isGuest) { return $reportedRecord->getUrl(); } @@ -90,6 +94,10 @@ private function getReportedRecord() /* @var ReportContent $report */ $report = $this->source; + if (!$report instanceof ReportContent) { + return null; + } + if (empty($report->comment_id)) { $this->_reportedRecord = Content::findOne(['id' => $report->content_id])->getModel(); } else { @@ -98,4 +106,4 @@ private function getReportedRecord() return $this->_reportedRecord; } -} \ No newline at end of file +} From ebe7ce0aa7c1420099692f014fad04e88ba5a8f0 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Mon, 6 Nov 2023 11:38:25 +0100 Subject: [PATCH 2/2] 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 +];