Passed
Push — master ( a719c0...651b5d )
by Craig
07:02
created

HookBundleInstaller::uninstall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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
namespace Zikula\Bundle\HookBundle;
13
14
use Doctrine\ORM\EntityManagerInterface;
15
use Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\Entity\HookBindingEntity;
16
use Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\Entity\HookRuntimeEntity;
17
use Zikula\Core\Doctrine\Helper\SchemaHelper;
18
use Zikula\Core\InstallerInterface;
19
20
/**
21
 * Class HookBundleInstaller
22
 */
23
class HookBundleInstaller implements InstallerInterface
24
{
25
    /**
26
     * @var SchemaHelper
27
     */
28
    private $schemaTool;
29
30
    /**
31
     * @var EntityManagerInterface
32
     */
33
    private $em;
34
35
    private static $entities = [
36
        HookBindingEntity::class,
37
        HookRuntimeEntity::class,
38
    ];
39
40
    /**
41
     * HookBundleInstaller constructor.
42
     * @param SchemaHelper $schemaTool
43
     * @param EntityManagerInterface $entityManager
44
     */
45
    public function __construct(
46
        SchemaHelper $schemaTool,
47
        EntityManagerInterface $entityManager
48
    ) {
49
        $this->schemaTool = $schemaTool;
50
        $this->em = $entityManager;
51
    }
52
53
    public function install()
54
    {
55
        try {
56
            $this->schemaTool->create(self::$entities);
57
        } catch (\Exception $e) {
58
            return false;
59
        }
60
61
        return true;
62
    }
63
64
    public function uninstall()
65
    {
66
        return false;
67
    }
68
69
    public function upgrade($currentCoreVersion)
70
    {
71
        // special note, the $currentCoreVersion var will contain the version of the CORE (not this bundle)
72
73
        if (version_compare($currentCoreVersion, '2.0.0', '<')) {
74
            // remove undefined entities
75
            foreach (['hook_area', 'hook_provider', 'hook_subscriber'] as $table) {
76
                $sql = "DROP TABLE $table;";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $table instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
77
                $connection = $this->em->getConnection();
78
                $stmt = $connection->prepare($sql);
79
                $stmt->execute();
80
                $stmt->closeCursor();
81
            }
82
        }
83
        switch ($currentCoreVersion) {
84
            case '2.0.0':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
85
                $this->schemaTool->update([HookRuntimeEntity::class]);
86
            case '2.0.1': //current version
87
        }
88
89
        // Update successful
90
        return true;
91
    }
92
}
93