Passed
Push — master ( 526180...6b4bc9 )
by Manuele
03:25 queued 56s
created

SetupController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setup() 0 22 4
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