Completed
Push — master ( 635f13...3b2a71 )
by Axel
37:58 queued 21:55
created

UpgraderController::upgradeAction()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 2
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\Bundle\CoreInstallerBundle\Controller;
15
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel;
21
use Zikula\Bundle\CoreBundle\YamlDumper;
22
23
/**
24
 * Class UpgraderController
25
 */
26
class UpgraderController extends AbstractController
27
{
28
    public const ZIKULACORE_MINIMUM_UPGRADE_VERSION = '1.4.3';
29
30
    public function __construct(ContainerInterface $container)
31
    {
32
        parent::__construct($container);
33
        $this->router = $container->get('router');
34
        $this->form = $this->container->get('form.factory');
35
    }
36
37
    public function upgradeAction(Request $request, $stage): Response
38
    {
39
        $currentVersion = $this->container->getParameter(ZikulaKernel::CORE_INSTALLED_VERSION_PARAM);
40
        if (version_compare($currentVersion, ZikulaKernel::VERSION, '=')) {
41
            $stage = 'complete';
42
        }
43
        // not installed?
44
        if (false === $this->container->getParameter('installed')) {
45
            return new RedirectResponse($this->router->generate('install'));
46
        }
47
48
        $yamlDumper = new YamlDumper($this->container->get('kernel')->getProjectDir() . '/config', 'services_custom.yaml');
49
        $yamlDumper->setParameter('upgrading', true);
50
        $request->setLocale($this->container->getParameter('locale'));
51
52
        return $this->controllerHelper->processWizard($request, $stage, 'upgrade', $yamlDumper);
53
    }
54
}
55