‪TYPO3CMS  9.5
ExtensionListCommand.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Helper\Table;
20 use Symfony\Component\Console\Helper\TableCell;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Input\InputOption;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use Symfony\Component\Console\Style\SymfonyStyle;
25 use TYPO3\CMS\Core\Package\PackageManager;
27 
33 class ‪ExtensionListCommand extends Command
34 {
38  protected function ‪configure()
39  {
40  $this
41  ->setDescription('Shows the list of extensions available to the system.')
42  ->addOption(
43  'all',
44  'a',
45  InputOption::VALUE_NONE,
46  'Also display currently inactive/uninstalled extensions.'
47  )
48  ->addOption(
49  'inactive',
50  'i',
51  InputOption::VALUE_NONE,
52  'Only show inactive/uninstalled extensions available for installation.'
53  );
54  }
55 
61  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
62  {
63  $io = new SymfonyStyle($input, ‪$output);
64  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
65 
66  $onlyShowInactiveExtensions = $input->getOption('inactive');
67  $showAlsoInactiveExtensions = $input->getOption('all');
68  if ($onlyShowInactiveExtensions) {
69  $packages = $packageManager->getAvailablePackages();
70  $io->title('All inactive/currently uninstalled extensions');
71  } elseif ($showAlsoInactiveExtensions) {
72  $packages = $packageManager->getAvailablePackages();
73  $io->title('All installed (= active) and available (= inactive/currently uninstalled) extensions');
74  } else {
75  $packages = $packageManager->getActivePackages();
76  $io->title('All installed (= active) extensions');
77  }
78 
79  $table = new Table(‪$output);
80  $table->setHeaders([
81  'Extension Key',
82  'Version',
83  'Type',
84  'Status',
85  ]);
86  $table->setColumnWidths([30, 10, 8, 6]);
87 
88  $formatter = $this->getHelper('formatter');
89  foreach ($packages as $package) {
90  $isActivePackage = $packageManager->isPackageActive($package->getPackageKey());
91  // Do not show the package if it is active but we only want to see inactive packages
92  if ($onlyShowInactiveExtensions && $isActivePackage) {
93  continue;
94  }
95  if ($package->getValueFromComposerManifest('type') === 'typo3-cms-framework') {
96  $type = 'System';
97  } else {
98  $type = 'Local';
99  }
100 
101  // Ensure that the inactive extensions are shown as well
102  if ($onlyShowInactiveExtensions || ($showAlsoInactiveExtensions && !$isActivePackage)) {
103  $status = '<comment>inactive</comment>';
104  } else {
105  $status = '<info>active</info>';
106  }
107 
108  $table->addRow([$package->getPackageKey(), $package->getPackageMetaData()->getVersion(), $type, $status]);
109 
110  // Also show the description of the extension, if verbose option is set
111  if (‪$output->isVerbose()) {
112  $description = (string)$package->getValueFromComposerManifest('description');
113  $table->addRow([new TableCell(' ' . $formatter->truncate($description, 80) . "\n\n", ['colspan' => 4])]);
114  }
115  }
116  $table->render();
117  }
118 }
‪TYPO3\CMS\Core\Command\ExtensionListCommand\configure
‪configure()
Definition: ExtensionListCommand.php:38
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Core\Command
Definition: DumpAutoloadCommand.php:3
‪TYPO3\CMS\Core\Command\ExtensionListCommand
Definition: ExtensionListCommand.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Command\ExtensionListCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: ExtensionListCommand.php:61