mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +02:00
65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Core\Command;
|
|
|
|
use Flarum\User\AssertPermissionTrait;
|
|
use Flarum\User\Exception\PermissionDeniedException;
|
|
use Flarum\Discussion\DiscussionRepository;
|
|
use Flarum\Foundation\DispatchEventsTrait;
|
|
use Flarum\Discussion\Event\Deleting;
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
|
|
|
class DeleteDiscussionHandler
|
|
{
|
|
use DispatchEventsTrait;
|
|
use AssertPermissionTrait;
|
|
|
|
/**
|
|
* @var \Flarum\Discussion\DiscussionRepository
|
|
*/
|
|
protected $discussions;
|
|
|
|
/**
|
|
* @param Dispatcher $events
|
|
* @param DiscussionRepository $discussions
|
|
*/
|
|
public function __construct(Dispatcher $events, DiscussionRepository $discussions)
|
|
{
|
|
$this->events = $events;
|
|
$this->discussions = $discussions;
|
|
}
|
|
|
|
/**
|
|
* @param DeleteDiscussion $command
|
|
* @return \Flarum\Discussion\Discussion
|
|
* @throws PermissionDeniedException
|
|
*/
|
|
public function handle(DeleteDiscussion $command)
|
|
{
|
|
$actor = $command->actor;
|
|
|
|
$discussion = $this->discussions->findOrFail($command->discussionId, $actor);
|
|
|
|
$this->assertCan($actor, 'delete', $discussion);
|
|
|
|
$this->events->fire(
|
|
new Deleting($discussion, $actor, $command->data)
|
|
);
|
|
|
|
$discussion->delete();
|
|
|
|
$this->dispatchEventsFor($discussion, $actor);
|
|
|
|
return $discussion;
|
|
}
|
|
}
|