|
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\Core; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
16
|
|
|
use Zikula\Common\Translator\TranslatorTrait; |
|
17
|
|
|
use Zikula\ExtensionsModule\ExtensionVariablesTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Installation and upgrade routines for the blocks extension |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractExtensionInstaller implements ExtensionInstallerInterface, ContainerAwareInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use TranslatorTrait; |
|
25
|
|
|
use ExtensionVariablesTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string the bundle name |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $name; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $container; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var AbstractBundle |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $bundle; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var \Doctrine\ORM\EntityManager |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $entityManager; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var \Zikula\Core\Doctrine\Helper\SchemaHelper |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $schemaTool; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var MockHookApi |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $hookApi; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* initialise the extension |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool true on success, false otherwise |
|
61
|
|
|
*/ |
|
62
|
|
|
abstract public function install(); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* upgrade the blocks extension |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $oldversion version being upgraded |
|
68
|
|
|
* |
|
69
|
|
|
* @return bool true if successful, false otherwise |
|
70
|
|
|
*/ |
|
71
|
|
|
abstract public function upgrade($oldversion); |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* delete the blocks extension |
|
75
|
|
|
* |
|
76
|
|
|
* Since the blocks extension should never be deleted we'all always return false here |
|
77
|
|
|
* @return bool false |
|
78
|
|
|
*/ |
|
79
|
|
|
abstract public function uninstall(); |
|
80
|
|
|
|
|
81
|
|
|
public function setBundle(AbstractBundle $bundle) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->bundle = $bundle; |
|
84
|
|
|
$this->name = $bundle->getName(); |
|
85
|
|
|
if ($this->container) { |
|
86
|
|
|
// both here and in `setContainer` so either method can be called first. |
|
87
|
|
|
$this->container->get('translator')->setDomain($this->bundle->getTranslationDomain()); |
|
88
|
|
|
} |
|
89
|
|
|
$this->hookApi = new MockHookApi(); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param ContainerInterface|null $container |
|
94
|
|
|
*/ |
|
95
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->container = $container; |
|
98
|
|
|
$this->setTranslator($container->get('translator')); |
|
99
|
|
|
$this->entityManager = $container->get('doctrine')->getManager(); |
|
100
|
|
|
$this->schemaTool = $container->get('zikula_core.common.doctrine.schema_tool'); |
|
101
|
|
|
$this->extensionName = $this->name; // for ExtensionVariablesTrait |
|
102
|
|
|
$this->variableApi = $container->get('zikula_extensions_module.api.variable'); // for ExtensionVariablesTrait |
|
103
|
|
|
if ($this->bundle) { |
|
104
|
|
|
$container->get('translator')->setDomain($this->bundle->getTranslationDomain()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setTranslator($translator) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->translator = $translator; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Convenience shortcut to add a session flash message. |
|
115
|
|
|
* @param $type |
|
116
|
|
|
* @param $message |
|
117
|
|
|
*/ |
|
118
|
|
View Code Duplication |
public function addFlash($type, $message) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
if (!$this->container->has('session')) { |
|
121
|
|
|
throw new \LogicException('You can not use the addFlash method if sessions are disabled.'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$this->container->get('session')->getFlashBag()->add($type, $message); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @deprecated Remove at Core-3.0 |
|
130
|
|
|
* Class MockHookApi |
|
131
|
|
|
* This class only exists to prevent errors where an Installer class tries to call a method like |
|
132
|
|
|
* `$this->hookApi->uninstallSubscriberHooks()`. This method call is no longer required because the tables it populated |
|
133
|
|
|
* have been removed. But a module author may unknowingly leave them in the installer. |
|
134
|
|
|
*/ |
|
135
|
|
|
class MockHookApi |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
public function __call($name, $arguments) |
|
138
|
|
|
{ |
|
139
|
|
|
// intentionally do nothing |
|
140
|
|
|
@trigger_error('All methods from HookApi are no longer needed. They should be completely removed from the Installer class.'); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.