[BUGFIX] Reload ext_emconf.php after extension update
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / InstallUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Service\OpcodeCacheService;
19 use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
20 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
21 use TYPO3\CMS\Impexp\Utility\ImportExportUtility;
22
23 /**
24 * Extension Manager Install Utility
25 */
26 class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
27
28 /**
29 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
30 */
31 public $objectManager;
32
33 /**
34 * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
35 */
36 public $installToolSqlParser;
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
40 */
41 protected $dependencyUtility;
42
43 /**
44 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
45 */
46 protected $fileHandlingUtility;
47
48 /**
49 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
50 */
51 protected $listUtility;
52
53 /**
54 * @var \TYPO3\CMS\Extensionmanager\Utility\DatabaseUtility
55 */
56 protected $databaseUtility;
57
58 /**
59 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
60 */
61 public $extensionRepository;
62
63 /**
64 * @var \TYPO3\CMS\Core\Package\PackageManager
65 */
66 protected $packageManager;
67
68 /**
69 * @var \TYPO3\CMS\Core\Cache\CacheManager
70 */
71 protected $cacheManager;
72
73 /**
74 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
75 */
76 protected $signalSlotDispatcher;
77
78 /**
79 * @var \TYPO3\CMS\Core\Registry
80 */
81 protected $registry;
82
83 /**
84 * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
85 */
86 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
87 $this->objectManager = $objectManager;
88 }
89
90 /**
91 * @param \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $installToolSqlParser
92 */
93 public function injectInstallToolSqlParser(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService $installToolSqlParser) {
94 $this->installToolSqlParser = $installToolSqlParser;
95 }
96
97 /**
98 * @param \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility
99 */
100 public function injectDependencyUtility(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility) {
101 $this->dependencyUtility = $dependencyUtility;
102 }
103
104 /**
105 * @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
106 */
107 public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility) {
108 $this->fileHandlingUtility = $fileHandlingUtility;
109 }
110
111 /**
112 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
113 */
114 public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility) {
115 $this->listUtility = $listUtility;
116 }
117
118 /**
119 * @param \TYPO3\CMS\Extensionmanager\Utility\DatabaseUtility $databaseUtility
120 */
121 public function injectDatabaseUtility(\TYPO3\CMS\Extensionmanager\Utility\DatabaseUtility $databaseUtility) {
122 $this->databaseUtility = $databaseUtility;
123 }
124
125 /**
126 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
127 */
128 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
129 $this->extensionRepository = $extensionRepository;
130 }
131
132 /**
133 * @param \TYPO3\CMS\Core\Package\PackageManager $packageManager
134 */
135 public function injectPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager) {
136 $this->packageManager = $packageManager;
137 }
138
139 /**
140 * @param \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
141 */
142 public function injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager) {
143 $this->cacheManager = $cacheManager;
144 }
145
146 /**
147 * @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
148 */
149 public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher) {
150 $this->signalSlotDispatcher = $signalSlotDispatcher;
151 }
152
153 /**
154 * @param \TYPO3\CMS\Core\Registry $registry
155 */
156 public function injectRegistry(\TYPO3\CMS\Core\Registry $registry) {
157 $this->registry = $registry;
158 }
159
160 /**
161 * Helper function to install an extension
162 * also processes db updates and clears the cache if the extension asks for it
163 *
164 * @param string $extensionKey
165 * @throws ExtensionManagerException
166 * @return void
167 */
168 public function install($extensionKey) {
169 $extension = $this->enrichExtensionWithDetails($extensionKey);
170 $this->ensureConfiguredDirectoriesExist($extension);
171 $this->loadExtension($extensionKey);
172 if (!empty($extension['clearcacheonload']) || !empty($extension['clearCacheOnLoad'])) {
173 $this->cacheManager->flushCaches();
174 } else {
175 $this->cacheManager->flushCachesInGroup('system');
176 }
177 $this->reloadCaches();
178
179 $this->importInitialFiles($extension['siteRelPath'], $extensionKey);
180 $this->processDatabaseUpdates($extension);
181 $this->processRuntimeDatabaseUpdates($extensionKey);
182 $this->saveDefaultConfiguration($extension['key']);
183
184 $this->emitAfterExtensionInstallSignal($extensionKey);
185 }
186
187 /**
188 * Helper function to uninstall an extension
189 *
190 * @param string $extensionKey
191 * @throws ExtensionManagerException
192 * @return void
193 */
194 public function uninstall($extensionKey) {
195 $dependentExtensions = $this->dependencyUtility->findInstalledExtensionsThatDependOnMe($extensionKey);
196 if (is_array($dependentExtensions) && !empty($dependentExtensions)) {
197 throw new ExtensionManagerException(
198 \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
199 'extensionList.uninstall.dependencyError',
200 'extensionmanager',
201 array($extensionKey, implode(',', $dependentExtensions))
202 ),
203 1342554622
204 );
205 } else {
206 $this->unloadExtension($extensionKey);
207 }
208 }
209
210 /**
211 * Wrapper function to check for loaded extensions
212 *
213 * @param string $extensionKey
214 * @return bool TRUE if extension is loaded
215 */
216 public function isLoaded($extensionKey) {
217 return $this->packageManager->isPackageActive($extensionKey);
218 }
219
220 /**
221 * Wrapper function for loading extensions
222 *
223 * @param string $extensionKey
224 * @return void
225 */
226 protected function loadExtension($extensionKey) {
227 $this->packageManager->activatePackage($extensionKey);
228 }
229
230 /**
231 * Wrapper function for unloading extensions
232 *
233 * @param string $extensionKey
234 * @return void
235 */
236 protected function unloadExtension($extensionKey) {
237 $this->packageManager->deactivatePackage($extensionKey);
238 $this->emitAfterExtensionUninstallSignal($extensionKey);
239 $this->cacheManager->flushCachesInGroup('system');
240 }
241
242 /**
243 * Emits a signal after an extension has been installed
244 *
245 * @param string $extensionKey
246 */
247 protected function emitAfterExtensionInstallSignal($extensionKey) {
248 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionInstall', array($extensionKey, $this));
249 }
250
251 /**
252 * Emits a signal after an extension has been uninstalled
253 *
254 * @param string $extensionKey
255 */
256 protected function emitAfterExtensionUninstallSignal($extensionKey) {
257 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionUninstall', array($extensionKey, $this));
258 }
259
260 /**
261 * Checks if an extension is available in the system
262 *
263 * @param string $extensionKey
264 * @return bool
265 */
266 public function isAvailable($extensionKey) {
267 return $this->packageManager->isPackageAvailable($extensionKey);
268 }
269
270 /**
271 * Reloads the package information, if the package is already registered
272 *
273 * @param string $extensionKey
274 * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageStateException if the package isn't available
275 * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageKeyException if an invalid package key was passed
276 * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackagePathException if an invalid package path was passed
277 * @throws \TYPO3\CMS\Core\Package\Exception\InvalidPackageManifestException if no extension configuration file could be found
278 */
279 public function reloadPackageInformation($extensionKey) {
280 if ($this->packageManager->isPackageAvailable($extensionKey)) {
281 $this->reloadOpcache();
282 $this->packageManager->reloadPackageInformation($extensionKey);
283 }
284 }
285
286 /**
287 * Fetch additional information for an extension key
288 *
289 * @param string $extensionKey
290 * @access private
291 * @return array
292 * @throws ExtensionManagerException
293 */
294 public function enrichExtensionWithDetails($extensionKey) {
295 $availableExtensions = $this->listUtility->getAvailableExtensions();
296 if (isset($availableExtensions[$extensionKey])) {
297 $extension = $availableExtensions[$extensionKey];
298 } else {
299 throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1342864081);
300 }
301 $availableAndInstalledExtensions = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(array($extensionKey => $extension));
302
303 if (!isset($availableAndInstalledExtensions[$extensionKey])) {
304 throw new ExtensionManagerException(
305 'Please check your uploaded extension "' . $extensionKey . '". The configuration file "ext_emconf.php" seems to be invalid.',
306 1391432222
307 );
308 }
309
310 return $availableAndInstalledExtensions[$extensionKey];
311 }
312
313 /**
314 * Creates directories as requested in ext_emconf.php
315 *
316 * @param array $extension
317 */
318 protected function ensureConfiguredDirectoriesExist(array $extension) {
319 $this->fileHandlingUtility->ensureConfiguredDirectoriesExist($extension);
320 }
321
322 /**
323 * Gets the content of the ext_tables.sql and ext_tables_static+adt.sql files
324 * Additionally adds the table definitions for the cache tables
325 *
326 * @param array $extension
327 */
328 public function processDatabaseUpdates(array $extension) {
329 $extTablesSqlFile = PATH_site . $extension['siteRelPath'] . 'ext_tables.sql';
330 $extTablesSqlContent = '';
331 if (file_exists($extTablesSqlFile)) {
332 $extTablesSqlContent .= GeneralUtility::getUrl($extTablesSqlFile);
333 }
334 if ($extTablesSqlContent !== '') {
335 $this->updateDbWithExtTablesSql($extTablesSqlContent);
336 }
337
338 $this->importStaticSqlFile($extension['siteRelPath']);
339 $this->importT3DFile($extension['siteRelPath']);
340 }
341
342 /**
343 * Gets all database updates due to runtime configuration, like caching framework or
344 * category api for example
345 *
346 * @param string $extensionKey
347 */
348 protected function processRuntimeDatabaseUpdates($extensionKey) {
349 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($extensionKey);
350 if (!empty($sqlString)) {
351 $this->updateDbWithExtTablesSql(implode(LF . LF . LF . LF, $sqlString));
352 }
353 }
354
355 /**
356 * Emits a signal to manipulate the tables definitions
357 *
358 * @param string $extensionKey
359 * @return mixed
360 * @throws ExtensionManagerException
361 */
362 protected function emitTablesDefinitionIsBeingBuiltSignal($extensionKey) {
363 $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', array(array(), $extensionKey));
364 // This is important to support old associated returns
365 $signalReturn = array_values($signalReturn);
366 $sqlString = $signalReturn[0];
367 if (!is_array($sqlString)) {
368 throw new ExtensionManagerException(
369 sprintf(
370 'The signal %s of class %s returned a value of type %s, but array was expected.',
371 'tablesDefinitionIsBeingBuilt',
372 __CLASS__,
373 gettype($sqlString)
374 ),
375 1382360258
376 );
377 }
378 return $sqlString;
379 }
380
381 /**
382 * Reload Cache files and Typo3LoadedExtensions
383 *
384 * @return void
385 */
386 public function reloadCaches() {
387 $this->reloadOpcache();
388 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf(FALSE);
389 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(FALSE);
390 }
391
392 /**
393 * Reloads PHP opcache
394 */
395 protected function reloadOpcache() {
396 GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
397 }
398
399 /**
400 * Save default configuration of an extension
401 *
402 * @param string $extensionKey
403 * @return void
404 */
405 protected function saveDefaultConfiguration($extensionKey) {
406 /** @var $configUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
407 $configUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
408 $configUtility->saveDefaultConfiguration($extensionKey);
409 }
410
411 /**
412 * Update database / process db updates from ext_tables
413 *
414 * @param string $rawDefinitions The raw SQL statements from ext_tables.sql
415 * @return void
416 */
417 public function updateDbWithExtTablesSql($rawDefinitions) {
418 $fieldDefinitionsFromFile = $this->installToolSqlParser->getFieldDefinitions_fileContent($rawDefinitions);
419 if (!empty($fieldDefinitionsFromFile)) {
420 $fieldDefinitionsFromCurrentDatabase = $this->installToolSqlParser->getFieldDefinitions_database();
421 $diff = $this->installToolSqlParser->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase);
422 $updateStatements = $this->installToolSqlParser->getUpdateSuggestions($diff);
423 $db = $this->getDatabaseConnection();
424 foreach ((array)$updateStatements['add'] as $string) {
425 $db->admin_query($string);
426 }
427 foreach ((array)$updateStatements['change'] as $string) {
428 $db->admin_query($string);
429 }
430 foreach ((array)$updateStatements['create_table'] as $string) {
431 $db->admin_query($string);
432 }
433 }
434 }
435
436 /**
437 * Import static SQL data (normally used for ext_tables_static+adt.sql)
438 *
439 * @param string $rawDefinitions
440 * @return void
441 */
442 public function importStaticSql($rawDefinitions) {
443 $statements = $this->installToolSqlParser->getStatementarray($rawDefinitions, 1);
444 list($statementsPerTable, $insertCount) = $this->installToolSqlParser->getCreateTables($statements, 1);
445 $db = $this->getDatabaseConnection();
446 // Traverse the tables
447 foreach ($statementsPerTable as $table => $query) {
448 $db->admin_query('DROP TABLE IF EXISTS ' . $table);
449 $db->admin_query($query);
450 if ($insertCount[$table]) {
451 $insertStatements = $this->installToolSqlParser->getTableInsertStatements($statements, $table);
452 foreach ($insertStatements as $statement) {
453 $db->admin_query($statement);
454 }
455 }
456 }
457 }
458
459 /**
460 * Remove an extension (delete the directory)
461 *
462 * @param string $extension
463 * @throws ExtensionManagerException
464 * @return void
465 */
466 public function removeExtension($extension) {
467 $absolutePath = $this->fileHandlingUtility->getAbsoluteExtensionPath($extension);
468 if ($this->fileHandlingUtility->isValidExtensionPath($absolutePath)) {
469 if ($this->packageManager->isPackageAvailable($extension)) {
470 // Package manager deletes the extension and removes the entry from PackageStates.php
471 $this->packageManager->deletePackage($extension);
472 } else {
473 // The extension is not listed in PackageStates.php, we can safely remove it
474 $this->fileHandlingUtility->removeDirectory($absolutePath);
475 }
476 } else {
477 throw new ExtensionManagerException('No valid extension path given.', 1342875724);
478 }
479 }
480
481 /**
482 * Get the data dump for an extension
483 *
484 * @param string $extension
485 * @return array
486 */
487 public function getExtensionSqlDataDump($extension) {
488 $extension = $this->enrichExtensionWithDetails($extension);
489 $filePrefix = PATH_site . $extension['siteRelPath'];
490 $sqlData['extTables'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables.sql');
491 $sqlData['staticSql'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables_static+adt.sql');
492 return $sqlData;
493 }
494
495 /**
496 * Gets the sql data dump for a specific sql file (for example ext_tables.sql)
497 *
498 * @param string $sqlFile
499 * @return string
500 */
501 protected function getSqlDataDumpForFile($sqlFile) {
502 $sqlData = '';
503 if (file_exists($sqlFile)) {
504 $sqlContent = GeneralUtility::getUrl($sqlFile);
505 $fieldDefinitions = $this->installToolSqlParser->getFieldDefinitions_fileContent($sqlContent);
506 $sqlData = $this->databaseUtility->dumpStaticTables($fieldDefinitions);
507 }
508 return $sqlData;
509 }
510
511
512 /**
513 * Checks if an update for an extension is available which also resolves dependencies.
514 *
515 * @internal
516 * @param Extension $extensionData
517 * @return bool
518 */
519 public function isUpdateAvailable(Extension $extensionData) {
520 return (bool)$this->getUpdateableVersion($extensionData);
521 }
522
523 /**
524 * Returns the updateable version for an extension which also resolves dependencies.
525 *
526 * @internal
527 * @param Extension $extensionData
528 * @return bool|Extension FALSE if no update available otherwise latest possible update
529 */
530 public function getUpdateableVersion(Extension $extensionData) {
531 // Only check for update for TER extensions
532 $version = $extensionData->getIntegerVersion();
533
534 /** @var $extensionUpdates[] \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
535 $extensionUpdates = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
536 $extensionData->getExtensionKey(),
537 $version,
538 0,
539 FALSE
540 );
541 if ($extensionUpdates->count() > 0) {
542 foreach ($extensionUpdates as $extensionUpdate) {
543 try {
544 $this->dependencyUtility->checkDependencies($extensionUpdate);
545 if (!$this->dependencyUtility->hasDependencyErrors()) {
546 return $extensionUpdate;
547 }
548 } catch (ExtensionManagerException $e) {
549 }
550 }
551 }
552 return FALSE;
553 }
554
555 /**
556 * Uses the export import extension to import a T3D or XML file to PID 0
557 * Execution state is saved in the this->registry, so it only happens once
558 *
559 * @param string $extensionSiteRelPath
560 * @return void
561 */
562 protected function importT3DFile($extensionSiteRelPath) {
563 $registryKeysToCheck = array(
564 $extensionSiteRelPath . 'Initialisation/data.t3d',
565 $extensionSiteRelPath . 'Initialisation/dataImported',
566 );
567 foreach ($registryKeysToCheck as $registryKeyToCheck) {
568 if ($this->registry->get('extensionDataImport', $registryKeyToCheck)) {
569 // Data was imported before => early return
570 return;
571 }
572 }
573 $importFileToUse = NULL;
574 $possibleImportFiles = array(
575 $extensionSiteRelPath . 'Initialisation/data.t3d',
576 $extensionSiteRelPath . 'Initialisation/data.xml'
577 );
578 foreach ($possibleImportFiles as $possibleImportFile) {
579 if (!file_exists(PATH_site . $possibleImportFile)) {
580 continue;
581 }
582 $importFileToUse = $possibleImportFile;
583 }
584 if ($importFileToUse !== NULL) {
585 /** @var ImportExportUtility $importExportUtility */
586 $importExportUtility = $this->objectManager->get(ImportExportUtility::class);
587 try {
588 $importResult = $importExportUtility->importT3DFile(PATH_site . $importFileToUse, 0);
589 $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
590 $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
591 } catch (\ErrorException $e) {
592 /** @var \TYPO3\CMS\Core\Log\Logger $logger */
593 $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
594 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
595 }
596 }
597 }
598
599 /**
600 * Emits a signal after an t3d file was imported
601 *
602 * @param string $importFileToUse
603 * @param int $importResult
604 */
605 protected function emitAfterExtensionT3DImportSignal($importFileToUse, $importResult) {
606 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionT3DImport', array($importFileToUse, $importResult, $this));
607 }
608
609 /**
610 * Imports a static tables SQL File (ext_tables_static+adt)
611 * Execution state is saved in the this->registry, so it only happens once
612 *
613 * @param string $extensionSiteRelPath
614 * @return void
615 */
616 protected function importStaticSqlFile($extensionSiteRelPath) {
617 $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
618 if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
619 $extTablesStaticSqlFile = PATH_site . $extTablesStaticSqlRelFile;
620 if (file_exists($extTablesStaticSqlFile)) {
621 $extTablesStaticSqlContent = GeneralUtility::getUrl($extTablesStaticSqlFile);
622 $this->importStaticSql($extTablesStaticSqlContent);
623 }
624 $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, 1);
625 $this->emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile);
626 }
627 }
628
629 /**
630 * Emits a signal after a static sql file was imported
631 *
632 * @param string $extTablesStaticSqlRelFile
633 */
634 protected function emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile) {
635 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionStaticSqlImport', array($extTablesStaticSqlRelFile, $this));
636 }
637
638 /**
639 * Imports files from Initialisation/Files to fileadmin
640 * via lowlevel copy directory method
641 *
642 * @param string $extensionSiteRelPath relative path to extension dir
643 * @param string $extensionKey
644 */
645 protected function importInitialFiles($extensionSiteRelPath, $extensionKey) {
646 $importRelFolder = $extensionSiteRelPath . 'Initialisation/Files';
647 if (!$this->registry->get('extensionDataImport', $importRelFolder)) {
648 $importFolder = PATH_site . $importRelFolder;
649 if (file_exists($importFolder)) {
650 $destinationRelPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . $extensionKey;
651 $destinationAbsolutePath = PATH_site . $destinationRelPath;
652 if (!file_exists($destinationAbsolutePath) &&
653 GeneralUtility::isAllowedAbsPath($destinationAbsolutePath)
654 ) {
655 GeneralUtility::mkdir($destinationAbsolutePath);
656 }
657 GeneralUtility::copyDirectory($importRelFolder, $destinationRelPath);
658 $this->registry->set('extensionDataImport', $importRelFolder, 1);
659 $this->emitAfterExtensionFileImportSignal($destinationAbsolutePath);
660 }
661 }
662 }
663
664 /**
665 * Emits a signal after extension files were imported
666 *
667 * @param string $destinationAbsolutePath
668 */
669 protected function emitAfterExtensionFileImportSignal($destinationAbsolutePath) {
670 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', array($destinationAbsolutePath, $this));
671 }
672
673 /**
674 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
675 */
676 protected function getDatabaseConnection() {
677 return $GLOBALS['TYPO3_DB'];
678 }
679
680 }