‪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;
28 use TYPO3\CMS\Core\Package\PackageManager;
30 
34 class ‪SetupExtensionsCommand extends Command
35 {
36  public function ‪__construct(
37  private readonly EventDispatcherInterface $eventDispatcher,
38  private readonly ‪InstallUtility $installUtility,
39  private readonly PackageManager $packageManager
40  ) {
41  parent::__construct();
42  }
43 
47  protected function ‪configure()
48  {
49  $this
50  ->setDescription('Set up extensions')
51  ->setHelp(
52  <<<'EOD'
53 Setup all extensions or the given extension by extension key. This must
54 be performed after new extensions are required via ‪Composer.
55 
56 The command performs all necessary setup operations, such as database
57 schema changes, static data import, distribution files import etc.
58 
59 The given extension keys must be recognized by ‪TYPO3 or will be ignored.
60 EOD
61  )
62  ->addOption(
63  'extension',
64  '-e',
65  InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
66  'Only set up extensions with given key'
67  );
68  }
69 
73  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
74  {
76  $this->eventDispatcher->dispatch(new ‪PackagesMayHaveChangedEvent());
77 
78  $io = new SymfonyStyle($input, ‪$output);
79  $extensionKeys = $input->getOption('extension');
80  $extensionKeysToSetUp = array_keys($this->packageManager->getActivePackages());
81  if (!empty($extensionKeys)) {
82  $extensionKeysToSetUp = array_filter(
83  $extensionKeysToSetUp,
84  static function ($extKey) use ($extensionKeys) {
85  return in_array($extKey, $extensionKeys, true);
86  }
87  );
88  }
89  $this->installUtility->updateDatabase();
90  foreach ($extensionKeysToSetUp as $extensionKey) {
91  $this->installUtility->processExtensionSetup($extensionKey);
92  }
93  if (empty($extensionKeysToSetUp)) {
94  $io->error('Given extensions "' . implode(', ', $extensionKeys) . '" not found in the system.');
95  return Command::FAILURE;
96  }
97  $io->success('Extension(s) "' . implode(', ', $extensionKeysToSetUp) . '" successfully set up.');
98 
99  return Command::SUCCESS;
100  }
101 }
‪TYPO3\CMS\Extensionmanager\Command\SetupExtensionsCommand\__construct
‪__construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly InstallUtility $installUtility, private readonly PackageManager $packageManager)
Definition: SetupExtensionsCommand.php:36
‪Composer
‪TYPO3
‪TYPO3\CMS\Extensionmanager\Command\SetupExtensionsCommand
Definition: SetupExtensionsCommand.php:35
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:58
‪TYPO3\CMS\Extensionmanager\Command
Definition: ActivateExtensionCommand.php:18
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Extensionmanager\Command\SetupExtensionsCommand\configure
‪configure()
Definition: SetupExtensionsCommand.php:47
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:64
‪TYPO3\CMS\Core\Package\Event\PackagesMayHaveChangedEvent
Definition: PackagesMayHaveChangedEvent.php:23
‪TYPO3\CMS\Extensionmanager\Command\SetupExtensionsCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SetupExtensionsCommand.php:73
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication()
Definition: Bootstrap.php:529