|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routes. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Zikula contributors (Zikula) |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
* @author Zikula contributors <[email protected]>. |
|
8
|
|
|
* @link http://www.zikula.org |
|
9
|
|
|
* @link http://zikula.org |
|
10
|
|
|
* @version Generated by ModuleStudio 0.7.1 (http://modulestudio.de). |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Zikula\RoutesModule\Base; |
|
14
|
|
|
|
|
15
|
|
|
use Doctrine\DBAL\Connection; |
|
16
|
|
|
use RuntimeException; |
|
17
|
|
|
use Zikula\Core\AbstractExtensionInstaller; |
|
18
|
|
|
use Zikula_Workflow_Util; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Installer base class. |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractRoutesModuleInstaller extends AbstractExtensionInstaller |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Install the ZikulaRoutesModule application. |
|
27
|
|
|
* |
|
28
|
|
|
* @return boolean True on success, or false |
|
29
|
|
|
* |
|
30
|
|
|
* @throws RuntimeException Thrown if database tables can not be created or another error occurs |
|
31
|
|
|
*/ |
|
32
|
|
|
public function install() |
|
33
|
|
|
{ |
|
34
|
|
|
$logger = $this->container->get('logger'); |
|
35
|
|
|
|
|
36
|
|
|
// create all tables from according entity definitions |
|
37
|
|
|
try { |
|
38
|
|
|
$this->schemaTool->create($this->listEntityClasses()); |
|
39
|
|
|
} catch (\Exception $e) { |
|
40
|
|
|
$this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage()); |
|
41
|
|
|
$logger->error('{app}: Could not create the database tables during installation. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]); |
|
42
|
|
|
|
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// set up all our vars with initial values |
|
47
|
|
|
$this->setVar('routeEntriesPerPage', 10); |
|
48
|
|
|
|
|
49
|
|
|
// create the default data |
|
50
|
|
|
$this->createDefaultData(); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
// initialisation successful |
|
55
|
|
|
return true; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Upgrade the ZikulaRoutesModule application from an older version. |
|
60
|
|
|
* |
|
61
|
|
|
* If the upgrade fails at some point, it returns the last upgraded version. |
|
62
|
|
|
* |
|
63
|
|
|
* @param integer $oldVersion Version to upgrade from |
|
64
|
|
|
* |
|
65
|
|
|
* @return boolean True on success, false otherwise |
|
66
|
|
|
* |
|
67
|
|
|
* @throws RuntimeException Thrown if database tables can not be updated |
|
68
|
|
|
*/ |
|
69
|
|
|
public function upgrade($oldVersion) |
|
70
|
|
|
{ |
|
71
|
|
|
/* |
|
|
|
|
|
|
72
|
|
|
$logger = $this->container->get('logger'); |
|
73
|
|
|
|
|
74
|
|
|
// Upgrade dependent on old version number |
|
75
|
|
|
switch ($oldVersion) { |
|
76
|
|
|
case '1.0.0': |
|
77
|
|
|
// do something |
|
78
|
|
|
// ... |
|
79
|
|
|
// update the database schema |
|
80
|
|
|
try { |
|
81
|
|
|
$this->schemaTool->update($this->listEntityClasses()); |
|
82
|
|
|
} catch (\Exception $e) { |
|
83
|
|
|
$this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage()); |
|
84
|
|
|
$logger->error('{app}: Could not update the database tables during the upgrade. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]); |
|
85
|
|
|
|
|
86
|
|
|
return false; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
*/ |
|
90
|
|
|
|
|
91
|
|
|
// update successful |
|
92
|
|
|
return true; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Uninstall ZikulaRoutesModule. |
|
97
|
|
|
* |
|
98
|
|
|
* @return boolean True on success, false otherwise |
|
99
|
|
|
* |
|
100
|
|
|
* @throws RuntimeException Thrown if database tables or stored workflows can not be removed |
|
101
|
|
|
*/ |
|
102
|
|
|
public function uninstall() |
|
103
|
|
|
{ |
|
104
|
|
|
$logger = $this->container->get('logger'); |
|
105
|
|
|
|
|
106
|
|
|
// delete stored object workflows |
|
107
|
|
|
$result = Zikula_Workflow_Util::deleteWorkflowsForModule('ZikulaRoutesModule'); |
|
108
|
|
|
if (false === $result) { |
|
109
|
|
|
$this->addFlash('error', $this->__f('An error was encountered while removing stored object workflows for the %s extension.', ['%s' => 'ZikulaRoutesModule'])); |
|
110
|
|
|
$logger->error('{app}: Could not remove stored object workflows during uninstallation.', ['app' => 'ZikulaRoutesModule']); |
|
111
|
|
|
|
|
112
|
|
|
return false; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
try { |
|
116
|
|
|
$this->schemaTool->drop($this->listEntityClasses()); |
|
117
|
|
|
} catch (\Exception $e) { |
|
118
|
|
|
$this->addFlash('error', $this->__('Doctrine Exception') . ': ' . $e->getMessage()); |
|
119
|
|
|
$logger->error('{app}: Could not remove the database tables during uninstallation. Error details: {errorMessage}.', ['app' => 'ZikulaRoutesModule', 'errorMessage' => $e->getMessage()]); |
|
120
|
|
|
|
|
121
|
|
|
return false; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// uninstall subscriber hooks |
|
125
|
|
|
$this->hookApi->uninstallSubscriberHooks($this->bundle->getMetaData()); |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
// remove all module vars |
|
129
|
|
|
$this->delVars(); |
|
130
|
|
|
|
|
131
|
|
|
// uninstallation successful |
|
132
|
|
|
return true; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Build array with all entity classes for ZikulaRoutesModule. |
|
137
|
|
|
* |
|
138
|
|
|
* @return array list of class names |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function listEntityClasses() |
|
141
|
|
|
{ |
|
142
|
|
|
$classNames = []; |
|
143
|
|
|
$classNames[] = 'Zikula\RoutesModule\Entity\RouteEntity'; |
|
144
|
|
|
|
|
145
|
|
|
return $classNames; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Create the default data for ZikulaRoutesModule. |
|
150
|
|
|
* |
|
151
|
|
|
* @return void |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function createDefaultData() |
|
154
|
|
|
{ |
|
155
|
|
|
$entityManager = $this->container->get('doctrine.orm.default_entity_manager'); |
|
156
|
|
|
$logger = $this->container->get('logger'); |
|
157
|
|
|
$request = $this->container->get('request_stack')->getCurrentRequest(); |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
$entityClass = 'Zikula\RoutesModule\Entity\RouteEntity'; |
|
160
|
|
|
$entityManager->getRepository($entityClass)->truncateTable($logger); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.