‪TYPO3CMS  ‪main
PackageActivationService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\EventDispatcher\EventDispatcherInterface;
33 
41 {
42  public function ‪__construct(
43  private ‪Registry $registry,
44  private ‪SqlReader $sqlReader,
45  private ‪SchemaMigrator $schemaMigrator,
46  private PackageManager $packageManager,
47  private ‪CacheManager $cacheManager,
48  private ‪BootService $bootService,
49  private ‪OpcodeCacheService $opcodeCacheService,
50  private EventDispatcherInterface $eventDispatcher,
51  private ‪ExtensionConfiguration $extensionConfiguration,
52  ) {}
53 
54  public function ‪activate(array $extensionKeys, ?object $emitter = null): void
55  {
56  $packages = [];
57  foreach ($extensionKeys as $extensionKey) {
58  $this->packageManager->activatePackage($extensionKey);
59  $this->extensionConfiguration->synchronizeExtConfTemplateWithLocalConfiguration($extensionKey);
60  $packages[$extensionKey] = $this->packageManager->getPackage($extensionKey);
61  }
62  $this->cacheManager->flushCaches();
63  // Load a new container as we are reloading ext_localconf.php files
64  $container = $this->bootService->getContainer(false);
65  $backup = $this->bootService->makeCurrent($container);
66  // Reload cache files and Typo3LoadedExtensions
67  $this->opcodeCacheService->clearAllActive();
68  $container->get(ExtLocalconfFactory::class)->loadUncached();
69  $tcaFactory = $container->get(TcaFactory::class);
70  ‪$GLOBALS['TCA'] = $tcaFactory->create();
71  $container->get(ExtTablesFactory::class)->loadUncached();
72 
73  $this->‪updateDatabase();
74  $eventDispatcher = $container->get(EventDispatcherInterface::class);
75  foreach ($packages as $extensionKey => $package) {
76  $eventDispatcher->dispatch(new ‪PackageInitializationEvent($extensionKey, $package, $container, $emitter));
77  }
78  // Reset to the original container instance
79  $this->bootService->makeCurrent(null, $backup);
80  }
81 
82  public function ‪reloadExtensionData(array $extensionKeys, ?object $emitter = null): void
83  {
84  foreach ($extensionKeys as $extensionKey) {
85  try {
86  $package = $this->packageManager->getPackage($extensionKey);
87  $this->registry->remove(
88  'extensionDataImport',
89  ‪PathUtility::stripPathSitePrefix($package->getPackagePath() . 'ext_tables_static+adt.sql')
90  );
91  $this->eventDispatcher->dispatch(
92  new ‪PackageInitializationEvent(extensionKey: $extensionKey, package: $package, emitter: $emitter)
93  );
95  }
96  }
97  }
98 
99  public function ‪updateDatabase(): void
100  {
101  $sqlStatements = [];
102  $sqlStatements[] = $this->sqlReader->getTablesDefinitionString();
103  $sqlStatements = $this->sqlReader->getCreateTableStatementArray(implode(LF . LF, array_filter($sqlStatements)));
104  $updateStatements = $this->schemaMigrator->getUpdateSuggestions($sqlStatements);
105  $updateStatements = array_merge_recursive(...array_values($updateStatements));
106  $selectedStatements = [];
107  foreach (['add', 'change', 'create_table', 'change_table'] as $action) {
108  if (empty($updateStatements[$action])) {
109  continue;
110  }
111  $statements = array_combine(array_keys($updateStatements[$action]), array_fill(0, count($updateStatements[$action]), true));
112  $selectedStatements = array_merge(
113  $selectedStatements,
114  $statements
115  );
116  }
117  $this->schemaMigrator->migrate($sqlStatements, $selectedStatements);
118  }
119 }
‪TYPO3\CMS\Core\Configuration\Tca\TcaFactory
Definition: TcaFactory.php:34
‪TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix
‪static stripPathSitePrefix(string $path)
Definition: PathUtility.php:428
‪TYPO3\CMS\Core\Package\Exception\UnknownPackageException
Definition: UnknownPackageException.php:23
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Package\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Package\PackageActivationService\activate
‪activate(array $extensionKeys, ?object $emitter=null)
Definition: PackageActivationService.php:54
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:31
‪TYPO3\CMS\Core\Core\BootService
Definition: BootService.php:35
‪TYPO3\CMS\Core\Package\PackageActivationService\reloadExtensionData
‪reloadExtensionData(array $extensionKeys, ?object $emitter=null)
Definition: PackageActivationService.php:82
‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator
Definition: SchemaMigrator.php:38
‪TYPO3\CMS\Core\Package\Event\PackageInitializationEvent
Definition: PackageInitializationEvent.php:30
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Configuration\Extension\ExtLocalconfFactory
Definition: ExtLocalconfFactory.php:28
‪TYPO3\CMS\Core\Service\OpcodeCacheService
Definition: OpcodeCacheService.php:27
‪TYPO3\CMS\Core\Package\PackageActivationService
Definition: PackageActivationService.php:41
‪TYPO3\CMS\Core\Configuration\Extension\ExtTablesFactory
Definition: ExtTablesFactory.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Package\PackageActivationService\updateDatabase
‪updateDatabase()
Definition: PackageActivationService.php:99
‪TYPO3\CMS\Core\Package
Definition: AbstractServiceProvider.php:18
‪TYPO3\CMS\Core\Package\PackageActivationService\__construct
‪__construct(private Registry $registry, private SqlReader $sqlReader, private SchemaMigrator $schemaMigrator, private PackageManager $packageManager, private CacheManager $cacheManager, private BootService $bootService, private OpcodeCacheService $opcodeCacheService, private EventDispatcherInterface $eventDispatcher, private ExtensionConfiguration $extensionConfiguration,)
Definition: PackageActivationService.php:42