[BUGFIX] Prevent crash in Install Tool and EM with invalid ext_tables.sql
[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 try {
387 $this->updateDbWithExtTablesSql($extTablesSqlContent);
388 } catch (\TYPO3\CMS\Core\Database\Schema\Exception\StatementException $e) {
389 throw new ExtensionManagerException(
390 $e->getMessage(),
391 1476340371
392 );
393 }
394 }
395
396 $this->importStaticSqlFile($extension['siteRelPath']);
397 $this->importT3DFile($extension['siteRelPath']);
398 }
399
400 /**
401 * Gets all database updates due to runtime configuration, like caching framework or
402 * category api for example
403 *
404 * @param string $extensionKey
405 */
406 protected function processRuntimeDatabaseUpdates($extensionKey)
407 {
408 $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($extensionKey);
409 if (!empty($sqlString)) {
410 $this->updateDbWithExtTablesSql(implode(LF . LF . LF . LF, $sqlString));
411 }
412 }
413
414 /**
415 * Emits a signal to manipulate the tables definitions
416 *
417 * @param string $extensionKey
418 * @return mixed
419 * @throws ExtensionManagerException
420 */
421 protected function emitTablesDefinitionIsBeingBuiltSignal($extensionKey)
422 {
423 $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', [[], $extensionKey]);
424 // This is important to support old associated returns
425 $signalReturn = array_values($signalReturn);
426 $sqlString = $signalReturn[0];
427 if (!is_array($sqlString)) {
428 throw new ExtensionManagerException(
429 sprintf(
430 'The signal %s of class %s returned a value of type %s, but array was expected.',
431 'tablesDefinitionIsBeingBuilt',
432 __CLASS__,
433 gettype($sqlString)
434 ),
435 1382360258
436 );
437 }
438 return $sqlString;
439 }
440
441 /**
442 * Reload Cache files and Typo3LoadedExtensions
443 *
444 * @return void
445 */
446 public function reloadCaches()
447 {
448 $this->reloadOpcache();
449 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf(false);
450 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(false);
451 }
452
453 /**
454 * Reloads PHP opcache
455 */
456 protected function reloadOpcache()
457 {
458 GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
459 }
460
461 /**
462 * Save default configuration of an extension
463 *
464 * @param string $extensionKey
465 * @return void
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 * @return void
479 */
480 public function updateDbWithExtTablesSql($rawDefinitions)
481 {
482 $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
483 $statements = $sqlReader->getCreateTableStatementArray($rawDefinitions);
484 if (count($statements) !== 0) {
485 $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
486 $schemaMigrationService->install($statements);
487 }
488 }
489
490 /**
491 * Import static SQL data (normally used for ext_tables_static+adt.sql)
492 *
493 * @param string $rawDefinitions
494 * @return void
495 */
496 public function importStaticSql($rawDefinitions)
497 {
498 $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
499 $statements = $sqlReader->getStatementArray($rawDefinitions);
500
501 $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
502 $schemaMigrationService->importStaticData($statements, true);
503 }
504
505 /**
506 * Remove an extension (delete the directory)
507 *
508 * @param string $extension
509 * @throws ExtensionManagerException
510 * @return void
511 */
512 public function removeExtension($extension)
513 {
514 $absolutePath = $this->fileHandlingUtility->getAbsoluteExtensionPath($extension);
515 if ($this->fileHandlingUtility->isValidExtensionPath($absolutePath)) {
516 if ($this->packageManager->isPackageAvailable($extension)) {
517 // Package manager deletes the extension and removes the entry from PackageStates.php
518 $this->packageManager->deletePackage($extension);
519 } else {
520 // The extension is not listed in PackageStates.php, we can safely remove it
521 $this->fileHandlingUtility->removeDirectory($absolutePath);
522 }
523 } else {
524 throw new ExtensionManagerException('No valid extension path given.', 1342875724);
525 }
526 }
527
528 /**
529 * Get the data dump for an extension
530 *
531 * @param string $extension
532 * @return array
533 */
534 public function getExtensionSqlDataDump($extension)
535 {
536 $extension = $this->enrichExtensionWithDetails($extension);
537 $filePrefix = PATH_site . $extension['siteRelPath'];
538 $sqlData['extTables'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables.sql');
539 $sqlData['staticSql'] = $this->getSqlDataDumpForFile($filePrefix . 'ext_tables_static+adt.sql');
540 return $sqlData;
541 }
542
543 /**
544 * Gets the sql data dump for a specific sql file (for example ext_tables.sql)
545 *
546 * @param string $sqlFile
547 * @return string
548 */
549 protected function getSqlDataDumpForFile($sqlFile)
550 {
551 $sqlData = '';
552 if (file_exists($sqlFile)) {
553 $sqlContent = file_get_contents($sqlFile);
554 $fieldDefinitions = $this->installToolSqlParser->getFieldDefinitions_fileContent($sqlContent);
555 $sqlData = $this->databaseUtility->dumpStaticTables($fieldDefinitions);
556 }
557 return $sqlData;
558 }
559
560 /**
561 * Checks if an update for an extension is available which also resolves dependencies.
562 *
563 * @internal
564 * @param Extension $extensionData
565 * @return bool
566 */
567 public function isUpdateAvailable(Extension $extensionData)
568 {
569 return (bool)$this->getUpdateableVersion($extensionData);
570 }
571
572 /**
573 * Returns the updateable version for an extension which also resolves dependencies.
574 *
575 * @internal
576 * @param Extension $extensionData
577 * @return bool|Extension FALSE if no update available otherwise latest possible update
578 */
579 public function getUpdateableVersion(Extension $extensionData)
580 {
581 // Only check for update for TER extensions
582 $version = $extensionData->getIntegerVersion();
583
584 /** @var $extensionUpdates[] \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
585 $extensionUpdates = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
586 $extensionData->getExtensionKey(),
587 $version,
588 0,
589 false
590 );
591 if ($extensionUpdates->count() > 0) {
592 foreach ($extensionUpdates as $extensionUpdate) {
593 try {
594 $this->dependencyUtility->checkDependencies($extensionUpdate);
595 if (!$this->dependencyUtility->hasDependencyErrors()) {
596 return $extensionUpdate;
597 }
598 } catch (ExtensionManagerException $e) {
599 }
600 }
601 }
602 return false;
603 }
604
605 /**
606 * Uses the export import extension to import a T3D or XML file to PID 0
607 * Execution state is saved in the this->registry, so it only happens once
608 *
609 * @param string $extensionSiteRelPath
610 * @return void
611 */
612 protected function importT3DFile($extensionSiteRelPath)
613 {
614 $registryKeysToCheck = [
615 $extensionSiteRelPath . 'Initialisation/data.t3d',
616 $extensionSiteRelPath . 'Initialisation/dataImported',
617 ];
618 foreach ($registryKeysToCheck as $registryKeyToCheck) {
619 if ($this->registry->get('extensionDataImport', $registryKeyToCheck)) {
620 // Data was imported before => early return
621 return;
622 }
623 }
624 $importFileToUse = null;
625 $possibleImportFiles = [
626 $extensionSiteRelPath . 'Initialisation/data.t3d',
627 $extensionSiteRelPath . 'Initialisation/data.xml'
628 ];
629 foreach ($possibleImportFiles as $possibleImportFile) {
630 if (!file_exists(PATH_site . $possibleImportFile)) {
631 continue;
632 }
633 $importFileToUse = $possibleImportFile;
634 }
635 if ($importFileToUse !== null) {
636 /** @var ImportExportUtility $importExportUtility */
637 $importExportUtility = $this->objectManager->get(ImportExportUtility::class);
638 try {
639 $importResult = $importExportUtility->importT3DFile(PATH_site . $importFileToUse, 0);
640 $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
641 $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
642 } catch (\ErrorException $e) {
643 /** @var \TYPO3\CMS\Core\Log\Logger $logger */
644 $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
645 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
646 }
647 }
648 }
649
650 /**
651 * Emits a signal after an t3d file was imported
652 *
653 * @param string $importFileToUse
654 * @param int $importResult
655 */
656 protected function emitAfterExtensionT3DImportSignal($importFileToUse, $importResult)
657 {
658 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionT3DImport', [$importFileToUse, $importResult, $this]);
659 }
660
661 /**
662 * Imports a static tables SQL File (ext_tables_static+adt)
663 * Execution state is saved in the this->registry, so it only happens once
664 *
665 * @param string $extensionSiteRelPath
666 * @return void
667 */
668 protected function importStaticSqlFile($extensionSiteRelPath)
669 {
670 $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
671 if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
672 $extTablesStaticSqlFile = PATH_site . $extTablesStaticSqlRelFile;
673 if (file_exists($extTablesStaticSqlFile)) {
674 $extTablesStaticSqlContent = file_get_contents($extTablesStaticSqlFile);
675 $this->importStaticSql($extTablesStaticSqlContent);
676 }
677 $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, 1);
678 $this->emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile);
679 }
680 }
681
682 /**
683 * Emits a signal after a static sql file was imported
684 *
685 * @param string $extTablesStaticSqlRelFile
686 */
687 protected function emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile)
688 {
689 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionStaticSqlImport', [$extTablesStaticSqlRelFile, $this]);
690 }
691
692 /**
693 * Imports files from Initialisation/Files to fileadmin
694 * via lowlevel copy directory method
695 *
696 * @param string $extensionSiteRelPath relative path to extension dir
697 * @param string $extensionKey
698 */
699 protected function importInitialFiles($extensionSiteRelPath, $extensionKey)
700 {
701 $importRelFolder = $extensionSiteRelPath . 'Initialisation/Files';
702 if (!$this->registry->get('extensionDataImport', $importRelFolder)) {
703 $importFolder = PATH_site . $importRelFolder;
704 if (file_exists($importFolder)) {
705 $destinationRelPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . $extensionKey;
706 $destinationAbsolutePath = PATH_site . $destinationRelPath;
707 if (!file_exists($destinationAbsolutePath) &&
708 GeneralUtility::isAllowedAbsPath($destinationAbsolutePath)
709 ) {
710 GeneralUtility::mkdir($destinationAbsolutePath);
711 }
712 GeneralUtility::copyDirectory($importRelFolder, $destinationRelPath);
713 $this->registry->set('extensionDataImport', $importRelFolder, 1);
714 $this->emitAfterExtensionFileImportSignal($destinationAbsolutePath);
715 }
716 }
717 }
718
719 /**
720 * Emits a signal after extension files were imported
721 *
722 * @param string $destinationAbsolutePath
723 */
724 protected function emitAfterExtensionFileImportSignal($destinationAbsolutePath)
725 {
726 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', [$destinationAbsolutePath, $this]);
727 }
728 }