mirror of
https://github.com/flarum/core.git
synced 2025-10-18 18:26:07 +02:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* For detailed copyright and license information, please view the
|
|
* LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Discussion;
|
|
|
|
use Flarum\Discussion\Event\Renamed;
|
|
use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint;
|
|
use Flarum\Notification\NotificationSyncer;
|
|
use Flarum\Post\DiscussionRenamedPost;
|
|
|
|
class DiscussionRenamedLogger
|
|
{
|
|
/**
|
|
* @var NotificationSyncer
|
|
*/
|
|
protected $notifications;
|
|
|
|
public function __construct(NotificationSyncer $notifications)
|
|
{
|
|
$this->notifications = $notifications;
|
|
}
|
|
|
|
public function handle(Renamed $event)
|
|
{
|
|
$post = DiscussionRenamedPost::reply(
|
|
$event->discussion->id,
|
|
$event->actor->id,
|
|
$event->oldTitle,
|
|
$event->discussion->title
|
|
);
|
|
|
|
$post = $event->discussion->mergePost($post);
|
|
|
|
if ($event->discussion->user_id !== $event->actor->id) {
|
|
$blueprint = new DiscussionRenamedBlueprint($post);
|
|
|
|
if ($post->exists) {
|
|
$this->notifications->sync($blueprint, [$event->discussion->user]);
|
|
} else {
|
|
$this->notifications->delete($blueprint);
|
|
}
|
|
}
|
|
}
|
|
}
|