‪TYPO3CMS  ‪main
SetupExtensionsCommand.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;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Input\InputOption;
24 use Symfony\Component\Console\Output\OutputInterface;
25 use Symfony\Component\Console\Style\SymfonyStyle;
31 use TYPO3\CMS\Core\Package\PackageManager;
32 
36 class ‪SetupExtensionsCommand extends Command
37 {
38  public function ‪__construct(
39  private readonly PackageManager $packageManager,
40  private readonly EventDispatcherInterface $eventDispatcher,
41  private readonly ‪PackageActivationService $packageActivationService,
42  ) {
43  parent::__construct();
44  }
45 
49  protected function ‪configure()
50  {
51  $this
52  ->setDescription('Set up extensions')
53  ->setHelp(
54  <<<'EOD'
55 Setup all extensions or the given extension by extension key. This must
56 be performed after new extensions are required via ‪Composer.
57 
58 The command performs all necessary setup operations, such as database
59 schema changes, static data import, distribution files import etc.
60 
61 The given extension keys must be recognized by ‪TYPO3 or will be ignored.
62 EOD
63  )
64  ->addOption(
65  'extension',
66  '-e',
67  InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
68  'Only set up extensions with given key'
69  );
70  }
71 
75  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
76  {
78  $this->eventDispatcher->dispatch(new ‪PackagesMayHaveChangedEvent());
79 
80  $io = new SymfonyStyle($input, ‪$output);
81  $extensionKeys = $input->getOption('extension');
82  $extensionsToSetUp = $this->packageManager->getActivePackages();
83  if (!empty($extensionKeys)) {
84  $extensionsToSetUp = array_filter(
85  $extensionsToSetUp,
86  static function ($extKey) use ($extensionKeys) {
87  return in_array($extKey, $extensionKeys, true);
88  },
89  ARRAY_FILTER_USE_KEY
90  );
91  }
92  if (empty($extensionsToSetUp)) {
93  $io->error('Given extension(s) "' . implode(', ', $extensionKeys) . '" not found in the system.');
94  return Command::FAILURE;
95  }
96  $this->packageActivationService->updateDatabase();
97  foreach ($extensionsToSetUp as $extensionKey => $package) {
98  $event = $this->eventDispatcher->dispatch(
99  new ‪PackageInitializationEvent(extensionKey: $extensionKey, package: $package, emitter: $this)
100  );
101  if ($event->hasStorageEntry(CheckForImportRequirements::class)) {
102  $io->warning(
103  $event->getStorageEntry(CheckForImportRequirements::class)->getResult()['exception']?->getMessage() ?? ''
104  );
105  }
106  }
107  $io->success('Extension(s) "' . implode(', ', array_keys($extensionsToSetUp)) . '" successfully set up.');
108 
109  return Command::SUCCESS;
110  }
111 }
‪Composer
‪TYPO3\CMS\Core\Command\SetupExtensionsCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SetupExtensionsCommand.php:75
‪TYPO3
‪TYPO3\CMS\Core\Command\SetupExtensionsCommand\configure
‪configure()
Definition: SetupExtensionsCommand.php:49
‪TYPO3\CMS\Core\Package\Event\PackageInitializationEvent
Definition: PackageInitializationEvent.php:30
‪TYPO3\CMS\Core\Package\Initialization\CheckForImportRequirements
Definition: CheckForImportRequirements.php:33
‪TYPO3\CMS\Core\Command\SetupExtensionsCommand
Definition: SetupExtensionsCommand.php:37
‪TYPO3\CMS\Core\Command\SetupExtensionsCommand\__construct
‪__construct(private readonly PackageManager $packageManager, private readonly EventDispatcherInterface $eventDispatcher, private readonly PackageActivationService $packageActivationService,)
Definition: SetupExtensionsCommand.php:38
‪TYPO3\CMS\Core\Package\PackageActivationService
Definition: PackageActivationService.php:41
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Core\Command
Definition: CacheFlushCommand.php:18
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:62
‪TYPO3\CMS\Core\Package\Event\PackagesMayHaveChangedEvent
Definition: PackagesMayHaveChangedEvent.php:23
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication()
Definition: Bootstrap.php:527