1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Routes. |
5
|
|
|
* |
6
|
|
|
* @copyright Zikula contributors (Zikula) |
7
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
8
|
|
|
* @author Zikula contributors <[email protected]>. |
9
|
|
|
* @see https://ziku.la |
10
|
|
|
* @version Generated by ModuleStudio 1.4.0 (https://modulestudio.de). |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace Zikula\RoutesModule\Base; |
16
|
|
|
|
17
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
18
|
|
|
use Exception; |
19
|
|
|
use Psr\Log\LoggerInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
21
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
22
|
|
|
use Zikula\Bundle\CoreBundle\Doctrine\Helper\SchemaHelper; |
23
|
|
|
use Zikula\ExtensionsModule\AbstractExtension; |
24
|
|
|
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface; |
25
|
|
|
use Zikula\ExtensionsModule\Installer\AbstractExtensionInstaller; |
26
|
|
|
use Zikula\RoutesModule\Entity\RouteEntity; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Installer base class. |
30
|
|
|
*/ |
31
|
|
|
abstract class AbstractRoutesModuleInstaller extends AbstractExtensionInstaller |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var string[] |
35
|
|
|
*/ |
36
|
|
|
protected $entities = [ |
37
|
|
|
RouteEntity::class, |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var LoggerInterface |
42
|
|
|
*/ |
43
|
|
|
protected $logger; |
44
|
|
|
|
45
|
|
|
public function __construct( |
46
|
|
|
AbstractExtension $extension, |
47
|
|
|
ManagerRegistry $managerRegistry, |
48
|
|
|
SchemaHelper $schemaTool, |
49
|
|
|
RequestStack $requestStack, |
50
|
|
|
TranslatorInterface $translator, |
51
|
|
|
VariableApiInterface $variableApi, |
52
|
|
|
LoggerInterface $logger) { |
53
|
|
|
parent::__construct($extension, $managerRegistry, $schemaTool, $requestStack, $translator, $variableApi); |
54
|
|
|
$this->logger = $logger; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function install(): bool |
58
|
|
|
{ |
59
|
|
|
// create all tables from according entity definitions |
60
|
|
|
try { |
61
|
|
|
$this->schemaTool->create($this->entities); |
62
|
|
|
} catch (Exception $exception) { |
63
|
|
|
$this->addFlash('error', $this->trans('Doctrine Exception') . ': ' . $exception->getMessage()); |
64
|
|
|
$this->logger->error( |
65
|
|
|
'{app}: Could not create the database tables during installation. Error details: {errorMessage}.', |
66
|
|
|
['app' => 'ZikulaRoutesModule', 'errorMessage' => $exception->getMessage()] |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
throw $exception; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// set up all our vars with initial values |
73
|
|
|
$this->setVar('routeEntriesPerPage', 10); |
74
|
|
|
$this->setVar('showOnlyOwnEntries', false); |
75
|
|
|
$this->setVar('allowModerationSpecificCreatorForRoute', false); |
76
|
|
|
$this->setVar('allowModerationSpecificCreationDateForRoute', false); |
77
|
|
|
|
78
|
|
|
// initialisation successful |
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function upgrade(string $oldVersion): bool |
83
|
|
|
{ |
84
|
|
|
/* |
85
|
|
|
// upgrade dependent on old version number |
86
|
|
|
switch ($oldVersion) { |
87
|
|
|
case '1.0.0': |
88
|
|
|
// do something |
89
|
|
|
// ... |
90
|
|
|
// update the database schema |
91
|
|
|
try { |
92
|
|
|
$this->schemaTool->update($this->entities); |
93
|
|
|
} catch (Exception $exception) { |
94
|
|
|
$this->addFlash('error', $this->trans('Doctrine Exception') . ': ' . $exception->getMessage()); |
95
|
|
|
$this->logger->error( |
96
|
|
|
'{app}: Could not update the database tables during the upgrade.' |
97
|
|
|
. ' Error details: {errorMessage}.', |
98
|
|
|
['app' => 'ZikulaRoutesModule', 'errorMessage' => $exception->getMessage()] |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
throw $exception; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
// update successful |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function uninstall(): bool |
111
|
|
|
{ |
112
|
|
|
try { |
113
|
|
|
$this->schemaTool->drop($this->entities); |
114
|
|
|
} catch (Exception $exception) { |
115
|
|
|
$this->addFlash('error', $this->trans('Doctrine Exception') . ': ' . $exception->getMessage()); |
116
|
|
|
$this->logger->error( |
117
|
|
|
'{app}: Could not remove the database tables during uninstallation. Error details: {errorMessage}.', |
118
|
|
|
['app' => 'ZikulaRoutesModule', 'errorMessage' => $exception->getMessage()] |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
throw $exception; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// remove all module vars |
125
|
|
|
$this->delVars(); |
126
|
|
|
|
127
|
|
|
// uninstallation successful |
128
|
|
|
return true; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|