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