‪TYPO3CMS  10.4
SiteListCommand.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\Input\InputInterface;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use Symfony\Component\Console\Style\SymfonyStyle;
26 
30 class ‪SiteListCommand extends Command
31 {
35  protected ‪$siteFinder;
36 
38  {
39  $this->siteFinder = ‪$siteFinder;
40  parent::__construct();
41  }
42 
46  protected function ‪configure()
47  {
48  $this->setDescription('Shows the list of sites available to the system.');
49  }
50 
56  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
57  {
58  $io = new SymfonyStyle($input, ‪$output);
59  $sites = $this->siteFinder->getAllSites();
60 
61  if (empty($sites)) {
62  $io->title('No sites configured');
63  $io->note('Configure new sites in the "Sites" module.');
64  return 0;
65  }
66 
67  $io->title('All configured sites');
68  $table = new Table(‪$output);
69  $table->setHeaders([
70  'Identifier',
71  'Root PID',
72  'Base URL',
73  'Language',
74  'Locale',
75  'Status',
76  ]);
77  foreach ($sites as $site) {
78  $baseUrls = [];
79  $languages = [];
80  ‪$locales = [];
81  $status = [];
82  foreach ($site->getLanguages() as $language) {
83  $baseUrls[] = (string)$language->getBase();
84  $languages[] = sprintf(
85  '%s (id:%d)',
86  $language->getTitle(),
87  $language->getLanguageId()
88  );
89  ‪$locales[] = $language->getLocale();
90  $status[] = $language->isEnabled()
91  ? '<fg=green>enabled</>'
92  : '<fg=yellow>disabled</>';
93  }
94  $table->addRow(
95  [
96  '<options=bold>' . $site->getIdentifier() . '</>',
97  $site->getRootPageId(),
98  implode("\n", $baseUrls),
99  implode("\n", $languages),
100  implode("\n", ‪$locales),
101  implode("\n", $status),
102  ]
103  );
104  }
105  $table->render();
106  return 0;
107  }
108 }
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Command\SiteListCommand\$siteFinder
‪SiteFinder $siteFinder
Definition: SiteListCommand.php:34
‪TYPO3\CMS\Core\Command\SiteListCommand\__construct
‪__construct(SiteFinder $siteFinder)
Definition: SiteListCommand.php:36
‪$locales
‪$locales
Definition: be_users.php:7
‪TYPO3\CMS\Core\Command\SiteListCommand
Definition: SiteListCommand.php:31
‪TYPO3\CMS\Core\Command\SiteListCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SiteListCommand.php:55
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Command
Definition: DumpAutoloadCommand.php:18
‪TYPO3\CMS\Core\Command\SiteListCommand\configure
‪configure()
Definition: SiteListCommand.php:45