|
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;"; |
|
|
|
|
|
|
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': |
|
|
|
|
|
|
85
|
|
|
$this->schemaTool->update([HookRuntimeEntity::class]); |
|
86
|
|
|
case '2.0.1': //current version |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Update successful |
|
90
|
|
|
return true; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.