Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on open old notification #73

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']],
]
];
];
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
---------------------
Expand Down
10 changes: 9 additions & 1 deletion notifications/NewReportAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand All @@ -98,4 +106,4 @@ private function getReportedRecord()

return $this->_reportedRecord;
}
}
}