|
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\ExtensionsModule; |
|
13
|
|
|
|
|
14
|
|
|
use Zikula\Bundle\CoreBundle\Bundle\MetaData; |
|
15
|
|
|
use Zikula\Bundle\CoreBundle\Bundle\Scanner; |
|
16
|
|
|
use Zikula\Core\AbstractExtensionInstaller; |
|
17
|
|
|
use Zikula\ExtensionsModule\Api\ExtensionApi; |
|
18
|
|
|
use Zikula\ExtensionsModule\Entity\ExtensionEntity; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Installation and upgrade routines for the extensions module. |
|
22
|
|
|
*/ |
|
23
|
|
|
class ExtensionsModuleInstaller extends AbstractExtensionInstaller |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Install the Extensions module. |
|
27
|
|
|
* |
|
28
|
|
|
* @return boolean true if installation is successful, false otherwise |
|
29
|
|
|
*/ |
|
30
|
|
|
public function install() |
|
31
|
|
|
{ |
|
32
|
|
|
$entities = [ |
|
33
|
|
|
'Zikula\ExtensionsModule\Entity\ExtensionEntity', |
|
34
|
|
|
'Zikula\ExtensionsModule\Entity\ExtensionDependencyEntity', |
|
35
|
|
|
'Zikula\ExtensionsModule\Entity\ExtensionVarEntity', |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
try { |
|
39
|
|
|
$this->schemaTool->create($entities); |
|
40
|
|
|
} catch (\Exception $e) { |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// populate default data |
|
45
|
|
|
$this->defaultData(); |
|
46
|
|
|
$this->setVar('itemsperpage', 40); |
|
47
|
|
|
|
|
48
|
|
|
// Initialisation successful |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Upgrade the module from an old version. |
|
54
|
|
|
* |
|
55
|
|
|
* This function must consider all the released versions of the module! |
|
56
|
|
|
* If the upgrade fails at some point, it returns the last upgraded version. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $oldversion Version number string to upgrade from |
|
|
|
|
|
|
59
|
|
|
* |
|
60
|
|
|
* @return boolean|string True on success, last valid version string or false if fails |
|
61
|
|
|
*/ |
|
62
|
|
|
public function upgrade($oldVersion) |
|
63
|
|
|
{ |
|
64
|
|
|
// Upgrade dependent on old version number |
|
65
|
|
|
switch ($oldVersion) { |
|
66
|
|
|
case '3.7.10': |
|
|
|
|
|
|
67
|
|
|
// Load DB connection |
|
68
|
|
|
$connection = $this->entityManager->getConnection(); |
|
69
|
|
|
|
|
70
|
|
|
// increase length of some hook table fields from 20 to 60 |
|
71
|
|
|
$commands = []; |
|
72
|
|
|
$commands[] = "ALTER TABLE `hook_provider` CHANGE `method` `method` VARCHAR(60) NOT NULL"; |
|
73
|
|
|
$commands[] = "ALTER TABLE `hook_runtime` CHANGE `method` `method` VARCHAR(60) NOT NULL"; |
|
74
|
|
|
|
|
75
|
|
|
foreach ($commands as $sql) { |
|
76
|
|
|
$stmt = $connection->executeQuery($sql); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
case '3.7.11': |
|
|
|
|
|
|
79
|
|
|
$this->schemaTool->update(['Zikula\ExtensionsModule\Entity\ExtensionEntity']); |
|
80
|
|
|
case '3.7.12': |
|
|
|
|
|
|
81
|
|
|
$this->setVar('itemsperpage', 40); |
|
82
|
|
|
case '3.7.13': |
|
|
|
|
|
|
83
|
|
|
$this->schemaTool->update(['Zikula\ExtensionsModule\Entity\ExtensionEntity']); |
|
84
|
|
|
case '3.7.14': |
|
85
|
|
|
// future upgrade routines |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// Update successful |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* delete the modules module |
|
94
|
|
|
* |
|
95
|
|
|
* This function is only ever called once during the lifetime of a particular |
|
96
|
|
|
* module instance. |
|
97
|
|
|
* |
|
98
|
|
|
* Since the modules module should never be deleted we'all always return false here |
|
99
|
|
|
* @return boolean false this module cannot be deleted |
|
100
|
|
|
*/ |
|
101
|
|
|
public function uninstall() |
|
102
|
|
|
{ |
|
103
|
|
|
// Deletion not allowed |
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Create the default data for the Extensions module. |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
public function defaultData() |
|
113
|
|
|
{ |
|
114
|
|
|
$scanner = new Scanner(); |
|
115
|
|
|
$jsonPath = realpath(__DIR__ . '/composer.json'); |
|
116
|
|
|
$jsonContent = $scanner->decode($jsonPath); |
|
117
|
|
|
$metaData = new MetaData($jsonContent); |
|
118
|
|
|
if (!empty($this->container)) { |
|
119
|
|
|
$metaData->setTranslator($this->container->get('translator')); |
|
120
|
|
|
} |
|
121
|
|
|
$meta = $metaData->getFilteredVersionInfoArray(); |
|
122
|
|
|
$meta['state'] = ExtensionApi::STATE_ACTIVE; |
|
123
|
|
|
unset($meta['dependencies']); |
|
124
|
|
|
unset($meta['oldnames']); |
|
125
|
|
|
|
|
126
|
|
|
$entity = new ExtensionEntity(); |
|
127
|
|
|
$entity->merge($meta); |
|
128
|
|
|
|
|
129
|
|
|
$this->entityManager->persist($entity); |
|
130
|
|
|
$this->entityManager->flush(); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.