5 * Contains \Drupal\Console\Command\Site\StatusCommand.
8 namespace Drupal\Console\Command\Site;
10 use Symfony\Component\Console\Input\InputOption;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Database\Database;
15 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Drupal\system\SystemManager;
18 use Drupal\Core\Site\Settings;
19 use Drupal\Core\Config\ConfigFactory;
20 use Drupal\Core\Extension\ThemeHandler;
23 * This command provides a report of the current drupal installation.
27 class StatusCommand extends Command
29 use ContainerAwareCommandTrait;
31 /* @var $connectionInfoKeys array */
32 protected $connectionInfoKeys = [
51 protected $systemManager;
61 protected $configFactory;
66 protected $themeHandler;
74 * DebugCommand constructor.
76 * @param SystemManager $systemManager
77 * @param Settings $settings
78 * @param ConfigFactory $configFactory
79 * @param ThemeHandler $themeHandler
82 public function __construct(
83 SystemManager $systemManager,
85 ConfigFactory $configFactory,
86 ThemeHandler $themeHandler,
89 $this->systemManager = $systemManager;
90 $this->settings = $settings;
91 $this->configFactory = $configFactory;
92 $this->themeHandler = $themeHandler;
93 $this->appRoot = $appRoot;
94 parent::__construct();
100 protected function configure()
103 ->setName('site:status')
104 ->setDescription($this->trans('commands.site.status.description'))
108 InputOption::VALUE_OPTIONAL,
109 $this->trans('commands.site.status.options.format'),
117 protected function execute(InputInterface $input, OutputInterface $output)
119 // Make sure all modules are loaded.
120 $this->container->get('module_handler')->loadAll();
122 $io = new DrupalStyle($input, $output);
124 $systemData = $this->getSystemData();
125 $connectionData = $this->getConnectionData();
126 $themeInfo = $this->getThemeData();
127 $directoryData = $this->getDirectoryData();
129 $siteData = array_merge(
136 $format = $input->getOption('format');
138 if ('table' === $format) {
139 $this->showDataAsTable($io, $siteData);
142 if ('json' === $format) {
143 $output->writeln(json_encode($siteData, JSON_PRETTY_PRINT));
147 protected function getSystemData()
149 if (!$this->systemManager) {
153 $requirements = $this->systemManager->listRequirements();
156 foreach ($requirements as $key => $requirement) {
157 if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) {
158 $title = $requirement['title']->render();
160 $title = $requirement['title'];
163 $systemData['system'][$title] = strip_tags($requirement['value']);
166 if ($this->settings) {
168 $hashSalt = $this->settings->getHashSalt();
169 } catch (\Exception $e) {
172 $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = $hashSalt;
173 $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion();
179 protected function getConnectionData()
181 $connectionInfo = Database::getConnectionInfo();
183 $connectionData = [];
184 foreach ($this->connectionInfoKeys as $connectionInfoKey) {
185 if ("password" == $connectionInfoKey) {
189 $connectionKey = $this->trans('commands.site.status.messages.'.$connectionInfoKey);
190 $connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey];
193 $connectionData['database'][$this->trans('commands.site.status.messages.connection')] = sprintf(
195 $connectionInfo['default']['driver'],
196 $connectionInfo['default']['username'],
197 $connectionInfo['default']['password'],
198 $connectionInfo['default']['host'],
199 $connectionInfo['default']['port'] ? ':'.$connectionInfo['default']['port'] : '',
200 $connectionInfo['default']['database']
203 return $connectionData;
206 protected function getThemeData()
208 $config = $this->configFactory->get('system.theme');
212 'theme_default' => $config->get('default'),
213 'theme_admin' => $config->get('admin'),
218 protected function getDirectoryData()
220 $systemTheme = $this->configFactory->get('system.theme');
222 $themeDefaultDirectory = '';
223 $themeAdminDirectory = '';
225 $themeDefault = $this->themeHandler->getTheme(
226 $systemTheme->get('default')
228 $themeDefaultDirectory = sprintf('/%s', $themeDefault->getpath());
230 $themeAdmin = $this->themeHandler->getTheme(
231 $systemTheme->get('admin')
233 $themeAdminDirectory = sprintf('/%s', $themeAdmin->getpath());
234 } catch (\Exception $e) {
237 $systemFile = $this->configFactory->get('system.file');
241 $this->trans('commands.site.status.messages.directory_root') => $this->appRoot,
242 $this->trans('commands.site.status.messages.directory_temporary') => $systemFile->get('path.temporary'),
243 $this->trans('commands.site.status.messages.directory_theme_default') => $themeDefaultDirectory,
244 $this->trans('commands.site.status.messages.directory_theme_admin') => $themeAdminDirectory,
249 protected function showDataAsTable(DrupalStyle $io, $siteData)
251 if (empty($siteData)) {
255 foreach ($this->groups as $group) {
257 $groupData = $siteData[$group];
258 $io->comment($this->trans('commands.site.status.messages.'.$group));
260 foreach ($groupData as $key => $item) {
261 $tableRows[] = [$key, $item];
264 $io->table([], $tableRows, 'compact');