Skip to content

Commit

Permalink
[site:status] improvements (#4063)
Browse files Browse the repository at this point in the history
* Use Database::getConnectionInfoAsUrl to get the db URL

* 1

* 2

* 3

* 5

* 6

* 7

* 8

* 10

* 11

* 12

* 13

* 14

* 15

* 16

* 17

* 18

* 19

* 20

* 21

* Update StatusCommand.php

* 22
  • Loading branch information
mondrake authored and enzolutions committed May 29, 2019
1 parent 9685080 commit df8b95b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/services/site.yml
Expand Up @@ -21,6 +21,6 @@ services:
- { name: drupal.command }
console.site_status:
class: Drupal\Console\Command\Site\StatusCommand
arguments: ['@?system.manager', '@settings', '@config.factory', '@theme_handler', '@app.root']
arguments: ['@?system.manager', '@settings', '@config.factory', '@theme_handler', '@app.root', '@renderer']
tags:
- { name: drupal.command }
74 changes: 64 additions & 10 deletions src/Command/Site/StatusCommand.php
Expand Up @@ -16,6 +16,8 @@
use Drupal\Core\Site\Settings;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Extension\ThemeHandler;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* This command provides a report of the current drupal installation.
Expand All @@ -41,6 +43,20 @@ class StatusCommand extends ContainerAwareCommand
'directory',
];

/**
* A list of system requirements to be skipped from output.
*
* @var array
*/
protected $systemDataSkipList = [
// The PHP memory limit in CLI is different from the one available to the
// web server. Skip to avoid confusion.
'php_memory_limit',
// The web server cannot be determined in CLI since Drupal takes it from
// the $_SERVER variable in HTTP requests.
'webserver',
];

/**
* @var SystemManager
*/
Expand All @@ -66,27 +82,35 @@ class StatusCommand extends ContainerAwareCommand
*/
protected $appRoot;

/**
* @var RendererInterface
*/
protected $renderer;

/**
* DebugCommand constructor.
*
* @param SystemManager $systemManager
* @param Settings $settings
* @param ConfigFactory $configFactory
* @param ThemeHandler $themeHandler
* @param SystemManager $systemManager
* @param Settings $settings
* @param ConfigFactory $configFactory
* @param ThemeHandler $themeHandler
* @param $appRoot
* @param RendererInterface $renderer
*/
public function __construct(
SystemManager $systemManager = null,
Settings $settings,
ConfigFactory $configFactory,
ThemeHandler $themeHandler,
$appRoot
$appRoot,
RendererInterface $renderer
) {
$this->systemManager = $systemManager;
$this->settings = $settings;
$this->configFactory = $configFactory;
$this->themeHandler = $themeHandler;
$this->appRoot = $appRoot;
$this->renderer = $renderer;
parent::__construct();
}

Expand Down Expand Up @@ -149,14 +173,42 @@ protected function getSystemData()
$systemData = [];

foreach ($requirements as $key => $requirement) {
if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) {
if (in_array($key, $this->systemDataSkipList)) {
continue;
}

if ($requirement['title'] instanceof TranslatableMarkup) {
$title = $requirement['title']->render();
} else {
$title = $requirement['title'];
}

$value = empty($requirement['description']) ? $requirement['value'] : $requirement['value'] . ' (' . $requirement['description'] . ')';
$systemData['system'][strip_tags($title)] = strip_tags($value); ;
$value = !empty($requirement['value']) ? strip_tags($requirement['value']) : '';
if (isset($requirement['severity'])) {
switch ($requirement['severity']) {
case SystemManager::REQUIREMENT_ERROR:
$value = "<error>$value</error>";
break;

case SystemManager::REQUIREMENT_WARNING:
$value = "<comment>$value</comment>";
break;

}
}

if ($this->getIo()->isVerbose()) {
$description = !empty($requirement['description']) ? $requirement['description'] : null;
if ($description instanceof TranslatableMarkup) {
$description = $description->render();
}
if (is_array($description)) {
$description = $this->renderer->renderPlain($description);
}
$value .= $description ? ' (' . strip_tags($description) . ')' : '';
}

$systemData['system'][strip_tags($title)] = $value;
}


Expand Down Expand Up @@ -185,8 +237,10 @@ protected function getConnectionData()
continue;
}

$connectionKey = $this->trans('commands.site.status.messages.' . $connectionInfoKey);
$connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey];
if (!empty($connectionInfo['default'][$connectionInfoKey])) {
$connectionKey = $this->trans('commands.site.status.messages.' . $connectionInfoKey);
$connectionData['database'][$connectionKey] = $connectionInfo['default'][$connectionInfoKey];
}
}

$connection_url = Database::getConnectionInfoAsUrl();
Expand Down

0 comments on commit df8b95b

Please sign in to comment.