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