CreateRevisionWhenCommentEdited.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace FootyRoom\Core\Comment;
use FootyRoom\Repositories\CommentRepository;
use DateTime;
class CreateRevisionWhenCommentEdited
{
/**
* @var \FootyRoom\Repositories\CommentRepository
*/
protected $commentRepo;
/**
* Constructor.
*
* @param \FootyRoom\Repositories\CommentRepository $commentRepo
*/
public function __construct(CommentRepository $commentRepo)
{
$this->commentRepo = $commentRepo;
}
/**
* Handler.
*
* @param \FootyRoom\Core\Comment\CommentEdited $event
*/
public function handle(CommentEdited $event)
{
$revision = new Revision($event->comment->getId(), $event->oldHtml, new DateTime());
$this->commentRepo->createRevision($revision);
// Record this change if it's not performed by original author.
if ($event->editor->getUserId() !== $event->comment->getAuthor()->getUserId()) {
$change = new CommentChange(
$event->comment->getId(),
'edited',
$event->editor->getUserId(),
$event->editor->getUsername()
);
$this->commentRepo->createChange($change);
}
}
}