Completed
Push — master ( 91aa98...cdf5a9 )
by Craig
05:11
created

removeThemeModuleSchemas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
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 - 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\PermissionsModule;
15
16
use Zikula\ExtensionsModule\Installer\AbstractExtensionInstaller;
17
use Zikula\PermissionsModule\Entity\PermissionEntity;
18
19
class PermissionsModuleInstaller extends AbstractExtensionInstaller
20
{
21
    public function install(): bool
22
    {
23
        $this->schemaTool->create([
24
            PermissionEntity::class
25
        ]);
26
27
        $this->createDefaultData();
28
29
        return true;
30
    }
31
32
    public function upgrade(string $oldVersion): bool
33
    {
34
        // Upgrade dependent on old version number
35
        switch ($oldVersion) {
36
            case '1.2.0': // shipped with Core-1.4.3 through Core-2.0.15
37
                $this->delVar('rowview');
38
                $this->delVar('rowedit');
39
                $this->removeThemeModuleSchemas();
40
        }
41
42
        return true;
43
    }
44
45
    private function removeThemeModuleSchemas(): void
46
    {
47
        // for Core-3.0.0
48
        $this->entityManager->getConnection()->executeQuery(
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

48
        $this->entityManager->/** @scrutinizer ignore-call */ 
49
                              getConnection()->executeQuery(
Loading history...
49
            "DELETE group_perms WHERE component LIKE 'ZikulaThemeModule%'"
50
        );
51
    }
52
53
    public function uninstall(): bool
54
    {
55
        // Deletion not allowed
56
        return false;
57
    }
58
59
    /**
60
     * Create the default data for the Permissions module.
61
     */
62
    public function createDefaultData(): void
63
    {
64
        // give administrator group full access to everything as top priority
65
        $record = new PermissionEntity();
66
        $record['gid']       = 2;
67
        $record['sequence']  = 1;
68
        $record['component'] = '.*';
69
        $record['instance']  = '.*';
70
        $record['level']     = ACCESS_ADMIN; // 800
71
        $this->entityManager->persist($record);
72
73
        // give user group comment access to everything as second priority
74
        $record = new PermissionEntity();
75
        $record['gid']       = 1;
76
        $record['sequence']  = 2;
77
        $record['component'] = '.*';
78
        $record['instance']  = '.*';
79
        $record['level']     = ACCESS_COMMENT; // 300
80
        $this->entityManager->persist($record);
81
82
        // allow unregistered users only read access to everything as lowest priority
83
        $record = new PermissionEntity();
84
        $record['gid']       = 0;
85
        $record['sequence']  = 3;
86
        $record['component'] = '.*';
87
        $record['instance']  = '.*';
88
        $record['level']     = ACCESS_READ; // 200
89
        $this->entityManager->persist($record);
90
91
        $this->entityManager->flush();
92
93
        $this->setVar('lockadmin', 1);
94
        $this->setVar('adminid', 1);
95
        $this->setVar('filter', 1);
96
    }
97
}
98