Fixed Extending NotifierService::notifyCreate is complicated

Kirby

Well-known member
Affected version
2.3.3
\XF\Service\Report\NotifierService::notifyCreate is currently kinda monolithic which makes it somewhat difficult to extend.

Could this be made more modular, eg. smth. like

PHP:
protected function getCreateNotificationEmailParams(User $user): array
{
    $report = $this->report;
    $comment = $this->comment;

    return [
        'receiver' => $user,
        'reporter' => $comment->User,
        'comment' => $comment,
        'report' => $report,
        'message' => $report->getContentMessage(),
    ];
}

protected function sendCreateNotification(Moderator $moderator): void
{
    $user = $moderator->User;

    if (empty($this->usersEmailed[$user->user_id]) && $moderator->notify_report)
    {
        $params = $this->getCreateNotificationEmailParams($user);
        
        $mailer = $this->app->mailer();
        $mailer->newMail()
            ->setToUser($user)
            ->setTemplate('report_create', $params)
            ->queue();

        $this->usersEmailed[$user->user_id] = true;
    }
}

public function notifyCreate()
{
    $moderatorsToEmail = $this->getUsersForCreatedNotification();

    foreach ($moderatorsToEmail AS $moderator)
    {
        $this->sendCreateNotification($moderator);
    }
}

This would allow to easily modify the notification process.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.4).

Change log:
Make report creation notifications easier to extend
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom