1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller\Trick\Admin; |
4
|
|
|
|
5
|
|
|
use App\Entity\Trick; |
6
|
|
|
use App\Exception\RedirectException; |
7
|
|
|
use App\FlashMessage\AddFlashTrait; |
8
|
|
|
use App\FlashMessage\FlashMessageCategory; |
9
|
|
|
use App\History\TrickHistory; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RevertHistoryTrickController |
19
|
|
|
* @package App\Controller\Trick\Admin |
20
|
|
|
* @IsGranted("ROLE_ADMIN") |
21
|
|
|
*/ |
22
|
|
|
class RevertHistoryTrickController extends AbstractController |
23
|
|
|
{ |
24
|
|
|
use AddFlashTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var TrickHistory |
28
|
|
|
*/ |
29
|
|
|
private $trickHistory; |
30
|
|
|
|
31
|
|
|
public function __construct(TrickHistory $trickHistory) |
32
|
|
|
{ |
33
|
|
|
$this->trickHistory = $trickHistory; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Trick $trick |
38
|
|
|
* @param $historyId |
39
|
|
|
* @param Request $request |
40
|
|
|
* @return RedirectResponse |
41
|
|
|
* @Route("/trick/revert/{id}/{historyId}", name="trick.revert") |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
public function revertHistory(Trick $trick, int $historyId, Request $request) |
45
|
|
|
{ |
46
|
|
|
$submittedToken = $request->request->get('_token'); |
47
|
|
|
if (!$this->isCsrfTokenValid('revert-trick' . $historyId, $submittedToken)) { |
48
|
|
|
throw new RedirectException($this->generateUrl('home'), 'Bad CSRF Token'); |
49
|
|
|
} |
50
|
|
|
$version = $request->request->get('_version'); |
51
|
|
|
$this->trickHistory->revertToHistory($trick->getId(), $version); |
52
|
|
|
|
53
|
|
|
$this->addFlashMessage(FlashMessageCategory::SUCCESS, 'Reverted ' . $trick->getName()); |
54
|
|
|
return $this->redirectToRoute('trick.show', [ |
55
|
|
|
'id' => $trick->getId(), |
56
|
|
|
'slug' => $trick->getSlug(), |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |