Completed
Pull Request — master (#4281)
by Craig
04:35
created

RoutesModuleInstaller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A upgrade() 0 44 5
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula - https://ziku.la/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Zikula\RoutesModule;
15
16
use Zikula\RoutesModule\Base\AbstractRoutesModuleInstaller;
17
18
class RoutesModuleInstaller extends AbstractRoutesModuleInstaller
19
{
20
    public function upgrade(string $oldVersion): bool
21
    {
22
        switch ($oldVersion) {
23
            case '1.1.0': // shipped with Core-1.4.3
24
                // rename createdUserId field to createdBy_id
25
                $sql = '
26
                    ALTER TABLE `zikula_routes_route`
27
                    CHANGE `createdUserId` `createdBy_id` int(11) NOT NULL
28
                ';
29
                $this->entityManager->getConnection()->exec($sql);
0 ignored issues
show
Bug introduced by
The method getConnection() does not exist on Doctrine\Persistence\ObjectManager. It seems like you code against a sub-type of Doctrine\Persistence\ObjectManager such as Doctrine\ORM\Decorator\EntityManagerDecorator or Doctrine\ORM\EntityManagerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
                $this->entityManager->/** @scrutinizer ignore-call */ 
30
                                      getConnection()->exec($sql);
Loading history...
30
31
                // rename updatedUserId field to updatedBy_id
32
                $sql = '
33
                    ALTER TABLE `zikula_routes_route`
34
                    CHANGE `updatedUserId` `updatedBy_id` int(11) NOT NULL
35
                ';
36
                $this->entityManager->getConnection()->exec($sql);
37
            case '1.1.1':
38
                // drop obsolete fields
39
                $fieldNames = ['routeType', 'replacedRouteName', 'sort_group'];
40
                foreach ($fieldNames as $fieldName) {
41
                    $sql = '
42
                        ALTER TABLE `zikula_routes_route`
43
                        DROP COLUMN `' . $fieldName . '`
44
                    ';
45
                    $this->entityManager->getConnection()->exec($sql);
46
                }
47
                // add new field
48
                $sql = '
49
                    ALTER TABLE `zikula_routes_route`
50
                    ADD `options` LONGTEXT NOT NULL
51
                    COMMENT \'(DC2Type:array)\' AFTER `requirements`
52
                ';
53
                $this->entityManager->getConnection()->exec($sql);
54
                $sql = '
55
                    UPDATE `zikula_routes_route`
56
                    SET `options` = \'a:0:{}\';
57
                ';
58
                $this->entityManager->getConnection()->exec($sql);
59
            case '1.1.2': // shipped with Core-2.0.15
60
                // nothing
61
        }
62
63
        return true;
64
    }
65
}
66