‪TYPO3CMS  ‪main
ExtensionListCommand.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 Symfony\Component\Console\Command\Command;
21 use Symfony\Component\Console\Helper\FormatterHelper;
22 use Symfony\Component\Console\Helper\Table;
23 use Symfony\Component\Console\Helper\TableCell;
24 use Symfony\Component\Console\Input\InputInterface;
25 use Symfony\Component\Console\Input\InputOption;
26 use Symfony\Component\Console\Output\OutputInterface;
27 use Symfony\Component\Console\Style\SymfonyStyle;
28 use TYPO3\CMS\Core\Package\PackageManager;
29 
35 class ‪ExtensionListCommand extends Command
36 {
37  public function ‪__construct(private readonly PackageManager $packageManager)
38  {
39  parent::__construct();
40  }
41 
45  protected function ‪configure()
46  {
47  $this
48  ->addOption(
49  'all',
50  'a',
51  InputOption::VALUE_NONE,
52  'Also display currently inactive/uninstalled extensions.'
53  )
54  ->addOption(
55  'inactive',
56  'i',
57  InputOption::VALUE_NONE,
58  'Only show inactive/uninstalled extensions available for installation.'
59  );
60  }
61 
65  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
66  {
67  $io = new SymfonyStyle($input, ‪$output);
68 
69  $onlyShowInactiveExtensions = $input->getOption('inactive');
70  $showAlsoInactiveExtensions = $input->getOption('all');
71  if ($onlyShowInactiveExtensions) {
72  $packages = $this->packageManager->getAvailablePackages();
73  $io->title('All inactive/currently uninstalled extensions');
74  } elseif ($showAlsoInactiveExtensions) {
75  $packages = $this->packageManager->getAvailablePackages();
76  $io->title('All installed (= active) and available (= inactive/currently uninstalled) extensions');
77  } else {
78  $packages = $this->packageManager->getActivePackages();
79  $io->title('All installed (= active) extensions');
80  }
81 
82  $table = new Table(‪$output);
83  $table->setHeaders([
84  'Extension Key',
85  'Version',
86  'Type',
87  'Status',
88  ]);
89  $table->setColumnWidths([30, 10, 8, 6]);
90 
92  $formatter = $this->getHelper('formatter');
93  foreach ($packages as $package) {
94  $isActivePackage = $this->packageManager->isPackageActive($package->getPackageKey());
95  if (!$package->getPackageMetaData()->isExtensionType()) {
96  continue;
97  }
98  // Do not show the package if it is active but we only want to see inactive packages
99  if ($onlyShowInactiveExtensions && $isActivePackage) {
100  continue;
101  }
102  $type = $package->getPackageMetaData()->isFrameworkType() ? 'System' : 'Local';
103  // Ensure that the inactive extensions are shown as well
104  if ($onlyShowInactiveExtensions || ($showAlsoInactiveExtensions && !$isActivePackage)) {
105  $status = '<comment>inactive</comment>';
106  } else {
107  $status = '<info>active</info>';
108  }
109 
110  $table->addRow([$package->getPackageKey(), $package->getPackageMetaData()->getVersion(), $type, $status]);
111 
112  // Also show the title of the extension, if verbose option is set
113  if (‪$output->isVerbose()) {
114  $title = (string)$package->getPackageMetaData()->getTitle();
115  $table->addRow([new TableCell(' ' . $formatter->truncate($title, 80) . "\n\n", ['colspan' => 4])]);
116  }
117  }
118  $table->render();
119  return Command::SUCCESS;
120  }
121 }
‪TYPO3\CMS\Core\Command\ExtensionListCommand\__construct
‪__construct(private readonly PackageManager $packageManager)
Definition: ExtensionListCommand.php:37
‪TYPO3\CMS\Core\Command\ExtensionListCommand\configure
‪configure()
Definition: ExtensionListCommand.php:45
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Core\Command
Definition: CacheFlushCommand.php:18
‪TYPO3\CMS\Core\Command\ExtensionListCommand
Definition: ExtensionListCommand.php:36
‪TYPO3\CMS\Core\Command\ExtensionListCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: ExtensionListCommand.php:65