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 $io = new DrupalStyle($input, $output);
121 $systemData = $this->getSystemData();
122 $connectionData = $this->getConnectionData();
123 $themeInfo = $this->getThemeData();
124 $directoryData = $this->getDirectoryData();
126 $siteData = array_merge(
133 $format = $input->getOption('format');
135 if ('table' === $format) {
136 $this->showDataAsTable($io, $siteData);
139 if ('json' === $format) {
140 $output->writeln(json_encode($siteData, JSON_PRETTY_PRINT));
144 protected function getSystemData()
146 if (!$this->systemManager) {
150 $requirements = $this->systemManager->listRequirements();
153 foreach ($requirements as $key => $requirement) {
154 if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) {
155 $title = $requirement['title']->render();
157 $title = $requirement['title'];
160 $systemData['system'][$title] = strip_tags($requirement['value']);
163 if ($this->settings) {
165 $hashSalt = $this->settings->getHashSalt();
166 } catch (\Exception $e) {
169 $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = $hashSalt;
170 $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion();
176 protected function getConnectionData()
178 $connectionInfo = Database::getConnectionInfo();
180 $connectionData = [];
181 foreach ($this->connectionInfoKeys as $connectionInfoKey) {
182 if ("password" == $connectionInfoKey) {
186 $connectionKey = $this->trans('commands.site.status.messages.'.$connectionInfoKey);
187 $connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey];
190 $connectionData['database'][$this->trans('commands.site.status.messages.connection')] = sprintf(
192 $connectionInfo['default']['driver'],
193 $connectionInfo['default']['username'],
194 $connectionInfo['default']['password'],
195 $connectionInfo['default']['host'],
196 $connectionInfo['default']['port'] ? ':'.$connectionInfo['default']['port'] : '',
197 $connectionInfo['default']['database']
200 return $connectionData;
203 protected function getThemeData()
205 $config = $this->configFactory->get('system.theme');
209 'theme_default' => $config->get('default'),
210 'theme_admin' => $config->get('admin'),
215 protected function getDirectoryData()
217 $systemTheme = $this->configFactory->get('system.theme');
219 $themeDefaultDirectory = '';
220 $themeAdminDirectory = '';
222 $themeDefault = $this->themeHandler->getTheme(
223 $systemTheme->get('default')
225 $themeDefaultDirectory = sprintf('/%s', $themeDefault->getpath());
227 $themeAdmin = $this->themeHandler->getTheme(
228 $systemTheme->get('admin')
230 $themeAdminDirectory = sprintf('/%s', $themeAdmin->getpath());
231 } catch (\Exception $e) {
234 $systemFile = $this->configFactory->get('system.file');
238 $this->trans('commands.site.status.messages.directory_root') => $this->appRoot,
239 $this->trans('commands.site.status.messages.directory_temporary') => $systemFile->get('path.temporary'),
240 $this->trans('commands.site.status.messages.directory_theme_default') => $themeDefaultDirectory,
241 $this->trans('commands.site.status.messages.directory_theme_admin') => $themeAdminDirectory,
246 protected function showDataAsTable(DrupalStyle $io, $siteData)
248 if (empty($siteData)) {
252 foreach ($this->groups as $group) {
254 $groupData = $siteData[$group];
255 $io->comment($this->trans('commands.site.status.messages.'.$group));
257 foreach ($groupData as $key => $item) {
258 $tableRows[] = [$key, $item];
261 $io->table([], $tableRows, 'compact');