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