1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; |
13
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
15
|
|
|
|
16
|
|
|
class SetupController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Route("/setup", name="setup") |
20
|
|
|
* |
21
|
|
|
* @param Request $request The request |
22
|
|
|
* @param KernelInterface $kernel The kernel |
23
|
|
|
* @param PdoSessionHandler $sessionHandlerService The session handler |
24
|
|
|
* |
25
|
|
|
* @return Response |
26
|
|
|
*/ |
27
|
|
|
public function setup(Request $request, KernelInterface $kernel, PdoSessionHandler $sessionHandlerService) |
28
|
|
|
{ |
29
|
|
|
if ($request->query->get('key') === $this->getParameter('kernel.secret')) { |
30
|
|
|
$output = ''; |
31
|
|
|
try { |
32
|
|
|
$application = new Application($kernel); |
33
|
|
|
$application->setAutoExit(false); |
34
|
|
|
$application->run(new ArrayInput(['command' => 'doctrine:schema:create', '--force']), new NullOutput()); |
35
|
|
|
$output .= '[ <span style="color:green">OK</span> ] Database updated<br />'; |
36
|
|
|
} catch (Exception $exception) { |
37
|
|
|
$output .= '[<span style="color:red">FAIL</span>] Database updated (' . $exception->getMessage( |
38
|
|
|
) . ')<br />'; |
39
|
|
|
} |
40
|
|
|
try { |
41
|
|
|
$sessionHandlerService->createTable(); |
42
|
|
|
$output .= '[ <span style="color:green">OK</span> ] Session table added<br />'; |
43
|
|
|
} catch (Exception $exception) { |
44
|
|
|
$output .= '[<span style="color:red">FAIL</span>] Session table added (' . $exception->getMessage( |
45
|
|
|
) . ')<br />'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return new Response( |
49
|
|
|
'<body style="background-color: black;color: white;"><pre>' . $output . '</pre></body>' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
throw $this->createNotFoundException('The given key is wrong'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|