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