[FEATURE] Add commands for listing and showing sites 04/58104/9
authorDaniel Goerz <daniel.goerz@posteo.de>
Fri, 31 Aug 2018 14:35:15 +0000 (16:35 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Sat, 1 Sep 2018 14:46:33 +0000 (16:46 +0200)
This patch adds the following CLI commands:
site:list - shows a list of all configured sites
site:show - shows the configuration of a single site

Resolves: #86066
Releases: master
Change-Id: I9bfecceea7a28f81f99373ea847e868289de0c70
Reviewed-on: https://review.typo3.org/58104
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Command/SiteListCommand.php [new file with mode: 0644]
typo3/sysext/core/Classes/Command/SiteShowCommand.php [new file with mode: 0644]
typo3/sysext/core/Configuration/Commands.php
typo3/sysext/core/Documentation/Changelog/master/Feature-86066-CLICommandsForListingAndShowingSites.rst [new file with mode: 0644]

diff --git a/typo3/sysext/core/Classes/Command/SiteListCommand.php b/typo3/sysext/core/Classes/Command/SiteListCommand.php
new file mode 100644 (file)
index 0000000..20091ed
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Command;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Table;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use TYPO3\CMS\Core\Site\SiteFinder;
+
+/**
+ * Command for listing all configured sites
+ */
+class SiteListCommand extends Command
+{
+    /**
+     * Defines the allowed options for this command
+     */
+    protected function configure()
+    {
+        $this->setDescription('Shows the list of sites available to the system.');
+    }
+
+    /**
+     * Shows a table with all configured sites
+     *
+     * @inheritdoc
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $io = new SymfonyStyle($input, $output);
+        $siteFinder = new SiteFinder();
+        $sites = $siteFinder->getAllSites();
+
+        if (empty($sites)) {
+            $io->title('No sites configured');
+            $io->note('Configure new sites in the "Sites" module.');
+            return;
+        }
+
+        $io->title('All configured sites');
+        $table = new Table($output);
+        $table->setHeaders([
+            'Identifier',
+            'Root PID',
+            'Base URL',
+            'Language',
+            'Locale',
+            'Status',
+        ]);
+        foreach ($sites as $site) {
+            $baseUrls = [];
+            $languages = [];
+            foreach ($site->getLanguages() as $language) {
+                $baseUrls[] = (string)$language->getBase();
+                $languages[] = sprintf(
+                    '%s (id:%d)',
+                    $language->getTitle(),
+                    $language->getLanguageId()
+                );
+                $locales[] = $language->getLocale();
+                $status[] = $language->isEnabled()
+                    ? '<fg=green>enabled</>'
+                    : '<fg=yellow>disabled</>';
+            }
+            $table->addRow(
+                [
+                    '<options=bold>' . $site->getIdentifier() . '</>',
+                    $site->getRootPageId(),
+                    implode("\n", $baseUrls),
+                    implode("\n", $languages),
+                    implode("\n", $locales),
+                    implode("\n", $status),
+                ]
+            );
+        }
+        $table->render();
+    }
+}
diff --git a/typo3/sysext/core/Classes/Command/SiteShowCommand.php b/typo3/sysext/core/Classes/Command/SiteShowCommand.php
new file mode 100644 (file)
index 0000000..707370c
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Command;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use Symfony\Component\Yaml\Yaml;
+use TYPO3\CMS\Core\Site\SiteFinder;
+
+/**
+ * Command for showing the configuration of a site
+ */
+class SiteShowCommand extends Command
+{
+    /**
+     * Defines the allowed options for this command
+     */
+    protected function configure()
+    {
+        $this->setDescription('Shows the configuration of the specified site. Specify the identifier via "site:show <identifier>".')
+            ->addArgument(
+                'identifier',
+                InputArgument::REQUIRED,
+                'The identifier of the site'
+            );
+    }
+
+    /**
+     * Shows the configuration of a site
+     *
+     * @inheritdoc
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $io = new SymfonyStyle($input, $output);
+        $siteFinder = new SiteFinder();
+        $site = $siteFinder->getSiteByIdentifier($input->getArgument('identifier'));
+        $io->title('Site configuration for ' . $input->getArgument('identifier'));
+        $io->block(Yaml::dump($site->getConfiguration(), 4));
+    }
+}
index 9c450fc..c13b715 100644 (file)
@@ -12,4 +12,12 @@ return [
         'class' => \TYPO3\CMS\Core\Command\ExtensionListCommand::class,
         'schedulable' => false
     ],
         'class' => \TYPO3\CMS\Core\Command\ExtensionListCommand::class,
         'schedulable' => false
     ],
+    'site:list' => [
+        'class' => \TYPO3\CMS\Core\Command\SiteListCommand::class,
+        'schedulable' => false
+    ],
+    'site:show' => [
+        'class' => \TYPO3\CMS\Core\Command\SiteShowCommand::class,
+        'schedulable' => false
+    ]
 ];
 ];
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-86066-CLICommandsForListingAndShowingSites.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-86066-CLICommandsForListingAndShowingSites.rst
new file mode 100644 (file)
index 0000000..eddfa53
--- /dev/null
@@ -0,0 +1,30 @@
+.. include:: ../../Includes.txt
+
+============================================================
+Feature: #86066 - CLI Commands for listing and showing sites
+============================================================
+
+See :issue:`86066`
+
+Description
+===========
+
+Two new CLI commands have been added:
+-  `site:list`
+-  `site:show`
+
+The list command can be executed via `typo3/sysext/core/bin/typo3 site:list` and will list all
+configured sites with their configured Identifier, root page, base URL, languages, locales and
+a flag whether or not the site is enabled.
+
+The show command can be executed via `typo3/sysext/core/bin/typo3 site:show <identifier>`.
+It needs an identifier of a configured site which must be provided after the command name.
+The command will output the complete configuration for the site in the YAML syntax.
+
+
+Impact
+======
+
+Reading access to the configured sites and their detailed configuration is now possible from CLI.
+
+.. index:: CLI, ext:core