[FEATURE] Doctrine: Implement SchemaMigrationService
[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
478 if (count($statements) !== 0) {
479 $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
480 $schemaMigrationService->install($statements);
481 }
482 }
483
484 /**
485 * Import static SQL data (normally used for ext_tables_static+adt.sql)
486 *
487 * @param string $rawDefinitions
488 * @return void
489 */
490 public function importStaticSql($rawDefinitions)
491 {
492 $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
493 $statements = $sqlReader->getStatementArray($rawDefinitions);
494
495 $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
496 $schemaMigrationService->importStaticData($statements, true);
497 }
498
499 /**
500 * Remove an extension (delete the directory)
501 *
502 * @param string $extension
503 * @throws ExtensionManagerException
504 * @return void
505 */
506 public function removeExtension($extension)
507 {
508 $absolutePath = $this->fileHandlingUtility->getAbsoluteExtensionPath($extension);
509 if ($this->fileHandlingUtility->isValidExtensionPath($absolutePath)) {
510 if ($this->packageManager->isPackageAvailable($extension)) {
511 // Package manager deletes the extension and removes the entry from PackageStates.php
512 $this->packageManager->deletePackage($extension);
513 } else {
514 // The extension is not listed in PackageStates.php, we can safely remove it
515 $this->fileHandlingUtility->removeDirectory($absolutePath);
516 }
517 } else {
518 throw new ExtensionManagerException('No valid extension path given.', 1342875724);
519 }
520 }
521
522 /**
523 * Get the data dump for an extension
524 *
525 * @param string $extension
526 * @return array
527 */
528 public function getExtensionSqlDataDump($extension)
529 {
530 $extension = $this->enrichExtensionWithDetails($extension);
531 $filePrefix = PATH_site . $extension['siteRelPath'];
532 $sqlData['extTables'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables.sql');
533 $sqlData['staticSql'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables_static+adt.sql');
534 return $sqlData;
535 }
536
537 /**
538 * Gets the sql data dump for a specific sql file (for example ext_tables.sql)
539 *
540 * @param string $sqlFile
541 * @return string
542 */
543 protected function getSqlDataDumpForFile($sqlFile)
544 {
545 $sqlData = '';
546 if (file_exists($sqlFile)) {
547 $sqlContent = file_get_contents($sqlFile);
548 $fieldDefinitions = $this->installToolSqlParser->getFieldDefinitions_fileContent($sqlContent);
549 $sqlData = $this->databaseUtility->dumpStaticTables($fieldDefinitions);
550 }
551 return $sqlData;
552 }
553
554 /**
555 * Checks if an update for an extension is available which also resolves dependencies.
556 *
557 * @internal
558 * @param Extension $extensionData
559 * @return bool
560 */
561 public function isUpdateAvailable(Extension $extensionData)
562 {
563 return (bool)$this->getUpdateableVersion($extensionData);
564 }
565
566 /**
567 * Returns the updateable version for an extension which also resolves dependencies.
568 *
569 * @internal
570 * @param Extension $extensionData
571 * @return bool|Extension FALSE if no update available otherwise latest possible update
572 */
573 public function getUpdateableVersion(Extension $extensionData)
574 {
575 // Only check for update for TER extensions
576 $version = $extensionData->getIntegerVersion();
577
578 /** @var $extensionUpdates[] \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
579 $extensionUpdates = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
580 $extensionData->getExtensionKey(),
581 $version,
582 0,
583 false
584 );
585 if ($extensionUpdates->count() > 0) {
586 foreach ($extensionUpdates as $extensionUpdate) {
587 try {
588 $this->dependencyUtility->checkDependencies($extensionUpdate);
589 if (!$this->dependencyUtility->hasDependencyErrors()) {
590 return $extensionUpdate;
591 }
592 } catch (ExtensionManagerException $e) {
593 }
594 }
595 }
596 return false;
597 }
598
599 /**
600 * Uses the export import extension to import a T3D or XML file to PID 0
601 * Execution state is saved in the this->registry, so it only happens once
602 *
603 * @param string $extensionSiteRelPath
604 * @return void
605 */
606 protected function importT3DFile($extensionSiteRelPath)
607 {
608 $registryKeysToCheck = [
609 $extensionSiteRelPath . 'Initialisation/data.t3d',
610 $extensionSiteRelPath . 'Initialisation/dataImported',
611 ];
612 foreach ($registryKeysToCheck as $registryKeyToCheck) {
613 if ($this->registry->get('extensionDataImport', $registryKeyToCheck)) {
614 // Data was imported before => early return
615 return;
616 }
617 }
618 $importFileToUse = null;
619 $possibleImportFiles = [
620 $extensionSiteRelPath . 'Initialisation/data.t3d',
621 $extensionSiteRelPath . 'Initialisation/data.xml'
622 ];
623 foreach ($possibleImportFiles as $possibleImportFile) {
624 if (!file_exists(PATH_site . $possibleImportFile)) {
625 continue;
626 }
627 $importFileToUse = $possibleImportFile;
628 }
629 if ($importFileToUse !== null) {
630 /** @var ImportExportUtility $importExportUtility */
631 $importExportUtility = $this->objectManager->get(ImportExportUtility::class);
632 try {
633 $importResult = $importExportUtility->importT3DFile(PATH_site . $importFileToUse, 0);
634 $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
635 $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
636 } catch (\ErrorException $e) {
637 /** @var \TYPO3\CMS\Core\Log\Logger $logger */
638 $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
639 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
640 }
641 }
642 }
643
644 /**
645 * Emits a signal after an t3d file was imported
646 *
647 * @param string $importFileToUse
648 * @param int $importResult
649 */
650 protected function emitAfterExtensionT3DImportSignal($importFileToUse, $importResult)
651 {
652 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionT3DImport', [$importFileToUse, $importResult, $this]);
653 }
654
655 /**
656 * Imports a static tables SQL File (ext_tables_static+adt)
657 * Execution state is saved in the this->registry, so it only happens once
658 *
659 * @param string $extensionSiteRelPath
660 * @return void
661 */
662 protected function importStaticSqlFile($extensionSiteRelPath)
663 {
664 $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
665 if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
666 $extTablesStaticSqlFile = PATH_site . $extTablesStaticSqlRelFile;
667 if (file_exists($extTablesStaticSqlFile)) {
668 $extTablesStaticSqlContent = file_get_contents($extTablesStaticSqlFile);
669 $this->importStaticSql($extTablesStaticSqlContent);
670 }
671 $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, 1);
672 $this->emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile);
673 }
674 }
675
676 /**
677 * Emits a signal after a static sql file was imported
678 *
679 * @param string $extTablesStaticSqlRelFile
680 */
681 protected function emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile)
682 {
683 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionStaticSqlImport', [$extTablesStaticSqlRelFile, $this]);
684 }
685
686 /**
687 * Imports files from Initialisation/Files to fileadmin
688 * via lowlevel copy directory method
689 *
690 * @param string $extensionSiteRelPath relative path to extension dir
691 * @param string $extensionKey
692 */
693 protected function importInitialFiles($extensionSiteRelPath, $extensionKey)
694 {
695 $importRelFolder = $extensionSiteRelPath . 'Initialisation/Files';
696 if (!$this->registry->get('extensionDataImport', $importRelFolder)) {
697 $importFolder = PATH_site . $importRelFolder;
698 if (file_exists($importFolder)) {
699 $destinationRelPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . $extensionKey;
700 $destinationAbsolutePath = PATH_site . $destinationRelPath;
701 if (!file_exists($destinationAbsolutePath) &&
702 GeneralUtility::isAllowedAbsPath($destinationAbsolutePath)
703 ) {
704 GeneralUtility::mkdir($destinationAbsolutePath);
705 }
706 GeneralUtility::copyDirectory($importRelFolder, $destinationRelPath);
707 $this->registry->set('extensionDataImport', $importRelFolder, 1);
708 $this->emitAfterExtensionFileImportSignal($destinationAbsolutePath);
709 }
710 }
711 }
712
713 /**
714 * Emits a signal after extension files were imported
715 *
716 * @param string $destinationAbsolutePath
717 */
718 protected function emitAfterExtensionFileImportSignal($destinationAbsolutePath)
719 {
720 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', [$destinationAbsolutePath, $this]);
721 }
722
723 /**
724 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
725 */
726 protected function getDatabaseConnection()
727 {
728 return $GLOBALS['TYPO3_DB'];
729 }
730 }