1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license GPLv3, http://www.gnu.org/copyleft/gpl.html |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2016 |
6
|
|
|
* @package TYPO3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Aimeos; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use \Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
14
|
|
|
use \TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent; |
|
|
|
|
15
|
|
|
use \TYPO3\CMS\Core\Database\Event\AlterTableDefinitionStatementsEvent; |
|
|
|
|
16
|
|
|
use \TYPO3\CMS\Install\Updates\UpgradeWizardInterface; |
|
|
|
|
17
|
|
|
use \TYPO3\CMS\Install\Updates\RepeatableInterface; |
|
|
|
|
18
|
|
|
use \TYPO3\CMS\Install\Updates\ChattyInterface; |
|
|
|
|
19
|
|
|
use \TYPO3\CMS\Core\Utility\GeneralUtility; |
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Aimeos setup class. |
24
|
|
|
* |
25
|
|
|
* @package TYPO3 |
26
|
|
|
*/ |
27
|
|
|
class Setup implements UpgradeWizardInterface, RepeatableInterface, ChattyInterface |
28
|
|
|
{ |
29
|
|
|
private $output; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Return the identifier for this wizard |
34
|
|
|
* This should be the same string as used in the ext_localconf class registration |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getIdentifier() : string |
39
|
|
|
{ |
40
|
|
|
return 'aimeos'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Return the speaking name of this wizard |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getTitle() : string |
50
|
|
|
{ |
51
|
|
|
return 'Aimeos database migration'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return the description for this wizard |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getDescription() : string |
61
|
|
|
{ |
62
|
|
|
return 'Updates the Aimeos database tables and migrates data if necessary'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Execute the update |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public function executeUpdate() : bool |
72
|
|
|
{ |
73
|
|
|
try { |
74
|
|
|
ob_start(); |
75
|
|
|
$exectimeStart = microtime(true); |
76
|
|
|
|
77
|
|
|
self::execute(); |
78
|
|
|
|
79
|
|
|
$this->output->writeln(ob_get_clean()); |
80
|
|
|
$this->output->writeln(sprintf('Setup process lasted %1$f sec', (microtime(true) - $exectimeStart))); |
81
|
|
|
} catch(\Throwable $t) { |
82
|
|
|
$this->output->writeln(ob_get_clean()); |
83
|
|
|
$this->output->writeln($t->getMessage()); |
84
|
|
|
$this->output->writeln($t->getTraceAsString()); |
85
|
|
|
|
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the classes the upgrade wizard depends on |
95
|
|
|
* |
96
|
|
|
* @return string[] |
97
|
|
|
*/ |
98
|
|
|
public function getPrerequisites() : array |
99
|
|
|
{ |
100
|
|
|
return []; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Setter injection for output into upgrade wizards |
106
|
|
|
* |
107
|
|
|
* @param OutputInterface $output |
108
|
|
|
*/ |
109
|
|
|
public function setOutput(OutputInterface $output) : void |
110
|
|
|
{ |
111
|
|
|
$this->output = $output; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Checks if update is necessary |
117
|
|
|
* |
118
|
|
|
* @return bool Whether an update is required (TRUE) or not (FALSE) |
119
|
|
|
*/ |
120
|
|
|
public function updateNecessary() : bool |
121
|
|
|
{ |
122
|
|
|
return true; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Executes the setup tasks for updating the database. |
128
|
|
|
*/ |
129
|
|
|
public static function execute() |
130
|
|
|
{ |
131
|
|
|
ini_set('max_execution_time', 0); |
132
|
|
|
|
133
|
|
|
$extconf = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class); |
134
|
|
|
$demo = $extconf->get('aimeos', 'useDemoData') ?: false; |
135
|
|
|
|
136
|
|
|
\Aimeos\MShop::cache(false); |
137
|
|
|
\Aimeos\MAdmin::cache(false); |
138
|
|
|
|
139
|
|
|
$site = $extconf->get('aimeos', 'siteCode') ?: 'default'; |
140
|
|
|
$template = $extconf->get('aimeos', 'siteTpl') ?: 'default'; |
141
|
|
|
$codelen = $extconf->get('aimeos', 'codeLength') ?: 64; |
142
|
|
|
|
143
|
|
|
$boostrap = \Aimeos\Aimeos\Base::aimeos(); |
144
|
|
|
$ctx = self::context(['setup' => ['default' => ['demo' => (string) $demo]]])->setEditor('setup'); |
145
|
|
|
|
146
|
|
|
\Aimeos\Setup::use($boostrap, ['codelength' => $codelen])->verbose('vvv') |
147
|
|
|
->context($ctx->setEditor('aimeos:setup')) |
148
|
|
|
->up($site, $template); |
149
|
|
|
|
150
|
|
|
$extconf->set('aimeos', ['useDemoData' => '']); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the current schema for the install tool |
156
|
|
|
* |
157
|
|
|
* @param array $list List of SQL statements |
158
|
|
|
* @return array SQL statements required for the install tool |
159
|
|
|
*/ |
160
|
|
|
public static function schema(array $list) : array |
161
|
|
|
{ |
162
|
|
|
$ctx = self::context(); |
163
|
|
|
$connectionNames = array_keys($ctx->config()->get( 'resource')); |
164
|
|
|
$connectionNames = array_filter($connectionNames, fn (string $key): bool => str_starts_with($key, 'db')); |
165
|
|
|
|
166
|
|
|
foreach ($connectionNames as $connectionName) { |
167
|
|
|
$conn = $ctx->db($connectionName); |
168
|
|
|
$adapter = $ctx->config('resource/' . $connectionName . '/adapter'); |
|
|
|
|
169
|
|
|
|
170
|
|
|
$tables = []; |
171
|
|
|
foreach(['fe_users_', 'madmin_', 'mshop_'] as $prefix) { |
172
|
|
|
switch ($adapter) { |
173
|
|
|
case "pgsql": $sql = 'SELECT tablename FROM pg_catalog.pg_tables where tablename ~ \'^' . $prefix . '\''; break; |
174
|
|
|
default: $sql = 'SHOW TABLES like \'' . $prefix . '%\''; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$result = $conn->create($sql)->execute(); |
178
|
|
|
|
179
|
|
|
while(($row = $result->fetch(\Aimeos\Base\DB\Result\Base::FETCH_NUM)) !== null) { |
180
|
|
|
$tables[] = $row[0]; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
foreach($tables as $table) { |
185
|
|
|
switch ($adapter) { |
186
|
|
|
case "pgsql": $sql = 'CREATE TABLE IF NOT EXISTS ' . $table . '()'; break; |
187
|
|
|
default: $sql = 'SHOW CREATE TABLE `' . $table . '`'; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$result = $conn->create($sql)->execute(); |
191
|
|
|
|
192
|
|
|
while(($row = $result->fetch(\Aimeos\Base\DB\Result\Base::FETCH_NUM)) !== null) { |
193
|
|
|
$str = $row[1]; |
194
|
|
|
|
195
|
|
|
$str = str_replace('"', '`', $str); |
196
|
|
|
$str = preg_replace('/CONSTRAINT `[a-zA-Z0-9_-]+` /', '', $str); |
197
|
|
|
$str = preg_replace('/ DEFAULT CHARSET=[^ ;]+/', '', $str); |
198
|
|
|
$str = preg_replace('/ COLLATE=[^ ;]+/', '', $str); |
199
|
|
|
|
200
|
|
|
$list[] = $str . ";\n"; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
return ['sqlString' => $list]; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Alter schema to avoid TYPO3 dropping Aimeos tables |
211
|
|
|
* |
212
|
|
|
* @param AlterTableDefinitionStatementsEvent $event Event object |
213
|
|
|
*/ |
214
|
|
|
public function schemaEvent(AlterTableDefinitionStatementsEvent $event) |
215
|
|
|
{ |
216
|
|
|
$list = self::schema([]); |
217
|
|
|
|
218
|
|
|
foreach ($list['sqlString'] ?? [] as $sql) { |
219
|
|
|
$event->addSqlData($sql); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Update schema if extension is installed |
226
|
|
|
* |
227
|
|
|
* @param AfterPackageActivationEvent $event Event object |
228
|
|
|
*/ |
229
|
|
|
public function setupEvent(AfterPackageActivationEvent $event) |
230
|
|
|
{ |
231
|
|
|
if ($event->getPackageKey() === 'aimeos' && \Aimeos\Aimeos\Base::getExtConfig('autoSetup', true)) { |
232
|
|
|
self::execute(); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Returns a new context object. |
239
|
|
|
* |
240
|
|
|
* @param array $config Nested array of configuration settings |
241
|
|
|
* @return \Aimeos\MShop\ContextIface Context object |
242
|
|
|
*/ |
243
|
|
|
protected static function context(array $config = []) : \Aimeos\MShop\ContextIface |
244
|
|
|
{ |
245
|
|
|
$aimeosExtPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('aimeos'); |
246
|
|
|
|
247
|
|
|
if (file_exists($aimeosExtPath . '/Resources/Libraries/autoload.php') === true) { |
248
|
|
|
require_once $aimeosExtPath . '/Resources/Libraries/autoload.php'; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$ctx = new \Aimeos\MShop\Context(); |
252
|
|
|
$conf = \Aimeos\Aimeos\Base::config($config); |
253
|
|
|
|
254
|
|
|
$ctx->setConfig($conf); |
255
|
|
|
$ctx->setDatabaseManager(new \Aimeos\Base\DB\Manager\Standard($conf->get('resource', []), 'DBAL')); |
256
|
|
|
$ctx->setFilesystemManager(new \Aimeos\Base\Filesystem\Manager\Standard($conf->get('resource', []))); |
257
|
|
|
$ctx->setLogger(new \Aimeos\Base\Logger\Errorlog(\Aimeos\Base\Logger\Iface::INFO)); |
258
|
|
|
$ctx->setSession(new \Aimeos\Base\Session\None()); |
259
|
|
|
$ctx->setCache(new \Aimeos\Base\Cache\None()); |
260
|
|
|
|
261
|
|
|
// Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above) |
262
|
|
|
if (php_sapi_name() === 'cli' && class_exists('\TYPO3\CMS\Core\Database\ConnectionPool') |
263
|
|
|
&& method_exists('\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections') |
264
|
|
|
) { |
265
|
|
|
$ctx->setProcess(new \Aimeos\Base\Process\Pcntl(\Aimeos\Aimeos\Base::getExtConfig('pcntlMax', 4))); |
266
|
|
|
} else { |
267
|
|
|
$ctx->setProcess(new \Aimeos\Base\Process\None()); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$factory = GeneralUtility::makeInstance('TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory'); |
271
|
|
|
return $ctx->setPassword(new \Aimeos\Base\Password\Typo3($factory->getDefaultHashInstance('FE'))); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths