|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\NewsBundle\Action; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\NewsBundle\Model\BlogInterface; |
|
15
|
|
|
use Sonata\NewsBundle\Model\CommentManagerInterface; |
|
16
|
|
|
use Sonata\NewsBundle\Util\HashGeneratorInterface; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
18
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
19
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
20
|
|
|
|
|
21
|
|
|
final class ModerateCommentAction |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var RouterInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $router; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var BlogInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $blog; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var CommentManagerInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $commentManager; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var HashGeneratorInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $hashGenerator; |
|
42
|
|
|
|
|
43
|
|
|
public function __construct( |
|
44
|
|
|
RouterInterface $router, |
|
45
|
|
|
BlogInterface $blog, |
|
46
|
|
|
CommentManagerInterface $commentManager, |
|
47
|
|
|
HashGeneratorInterface $hashGenerator |
|
48
|
|
|
) { |
|
49
|
|
|
$this->router = $router; |
|
50
|
|
|
$this->blog = $blog; |
|
51
|
|
|
$this->commentManager = $commentManager; |
|
52
|
|
|
$this->hashGenerator = $hashGenerator; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $commentId |
|
57
|
|
|
* @param string $hash |
|
58
|
|
|
* @param string $status |
|
59
|
|
|
* |
|
60
|
|
|
* @throws AccessDeniedException |
|
61
|
|
|
* |
|
62
|
|
|
* @return RedirectResponse |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __invoke($commentId, $hash, $status) |
|
65
|
|
|
{ |
|
66
|
|
|
$comment = $this->commentManager->findOneBy(['id' => $commentId]); |
|
67
|
|
|
|
|
68
|
|
|
if (!$comment) { |
|
69
|
|
|
throw new AccessDeniedException(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$computedHash = $this->hashGenerator->generate($comment); |
|
73
|
|
|
|
|
74
|
|
|
if ($computedHash != $hash) { |
|
75
|
|
|
throw new AccessDeniedException(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$comment->setStatus($status); |
|
79
|
|
|
|
|
80
|
|
|
$this->commentManager->save($comment); |
|
81
|
|
|
|
|
82
|
|
|
return new RedirectResponse($this->router->generate('sonata_news_view', [ |
|
83
|
|
|
'permalink' => $this->blog->getPermalinkGenerator()->generate($comment->getPost()), |
|
84
|
|
|
])); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|