X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FSite%2FStatusCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FSite%2FStatusCommand.php;h=776961b06da2fdffe443c037ec28372aeb1380d8;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Site/StatusCommand.php b/vendor/drupal/console/src/Command/Site/StatusCommand.php new file mode 100644 index 000000000..776961b06 --- /dev/null +++ b/vendor/drupal/console/src/Command/Site/StatusCommand.php @@ -0,0 +1,264 @@ +systemManager = $systemManager; + $this->settings = $settings; + $this->configFactory = $configFactory; + $this->themeHandler = $themeHandler; + $this->appRoot = $appRoot; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('site:status') + ->setDescription($this->trans('commands.site.status.description')) + ->addOption( + 'format', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.site.status.options.format'), + 'table' + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $systemData = $this->getSystemData(); + $connectionData = $this->getConnectionData(); + $themeInfo = $this->getThemeData(); + $directoryData = $this->getDirectoryData(); + + $siteData = array_merge( + $systemData, + $connectionData, + $themeInfo, + $directoryData + ); + + $format = $input->getOption('format'); + + if ('table' === $format) { + $this->showDataAsTable($io, $siteData); + } + + if ('json' === $format) { + $output->writeln(json_encode($siteData, JSON_PRETTY_PRINT)); + } + } + + protected function getSystemData() + { + if (!$this->systemManager) { + return []; + } + + $requirements = $this->systemManager->listRequirements(); + $systemData = []; + + foreach ($requirements as $key => $requirement) { + if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) { + $title = $requirement['title']->render(); + } else { + $title = $requirement['title']; + } + + $systemData['system'][$title] = strip_tags($requirement['value']); + } + + if ($this->settings) { + try { + $hashSalt = $this->settings->getHashSalt(); + } catch (\Exception $e) { + $hashSalt = ''; + } + $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = $hashSalt; + $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion(); + } + + return $systemData; + } + + protected function getConnectionData() + { + $connectionInfo = Database::getConnectionInfo(); + + $connectionData = []; + foreach ($this->connectionInfoKeys as $connectionInfoKey) { + if ("password" == $connectionInfoKey) { + continue; + } + + $connectionKey = $this->trans('commands.site.status.messages.'.$connectionInfoKey); + $connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey]; + } + + $connectionData['database'][$this->trans('commands.site.status.messages.connection')] = sprintf( + '%s//%s:%s@%s%s/%s', + $connectionInfo['default']['driver'], + $connectionInfo['default']['username'], + $connectionInfo['default']['password'], + $connectionInfo['default']['host'], + $connectionInfo['default']['port'] ? ':'.$connectionInfo['default']['port'] : '', + $connectionInfo['default']['database'] + ); + + return $connectionData; + } + + protected function getThemeData() + { + $config = $this->configFactory->get('system.theme'); + + return [ + 'theme' => [ + 'theme_default' => $config->get('default'), + 'theme_admin' => $config->get('admin'), + ], + ]; + } + + protected function getDirectoryData() + { + $systemTheme = $this->configFactory->get('system.theme'); + + $themeDefaultDirectory = ''; + $themeAdminDirectory = ''; + try { + $themeDefault = $this->themeHandler->getTheme( + $systemTheme->get('default') + ); + $themeDefaultDirectory = sprintf('/%s', $themeDefault->getpath()); + + $themeAdmin = $this->themeHandler->getTheme( + $systemTheme->get('admin') + ); + $themeAdminDirectory = sprintf('/%s', $themeAdmin->getpath()); + } catch (\Exception $e) { + } + + $systemFile = $this->configFactory->get('system.file'); + + return [ + 'directory' => [ + $this->trans('commands.site.status.messages.directory_root') => $this->appRoot, + $this->trans('commands.site.status.messages.directory_temporary') => $systemFile->get('path.temporary'), + $this->trans('commands.site.status.messages.directory_theme_default') => $themeDefaultDirectory, + $this->trans('commands.site.status.messages.directory_theme_admin') => $themeAdminDirectory, + ], + ]; + } + + protected function showDataAsTable(DrupalStyle $io, $siteData) + { + if (empty($siteData)) { + return []; + } + $io->newLine(); + foreach ($this->groups as $group) { + $tableRows = []; + $groupData = $siteData[$group]; + $io->comment($this->trans('commands.site.status.messages.'.$group)); + + foreach ($groupData as $key => $item) { + $tableRows[] = [$key, $item]; + } + + $io->table([], $tableRows, 'compact'); + } + } +}