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