Skip to content

Commit

Permalink
Merge pull request #501 from jmolivas/410-site-status-command
Browse files Browse the repository at this point in the history
410 site status command
  • Loading branch information
jmolivas committed Mar 11, 2015
2 parents bd92f9e + dd6a544 commit d6bb8ff
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 7 deletions.
21 changes: 21 additions & 0 deletions config/translations/console.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,27 @@ commands:
configuration-key: Configuration key
original: Original Value
updated: Override Value
status:
description: View current Drupal Installation status
messages:
application: Application
system: System Info
database: Database connection
driver: Driver
host: Host
database: Database
port: Port
username: Username
password: Password
themes: Themes
connection: Connection
theme_default: Default theme
theme_admin: Admin theme
directories: Directories
directory_root: Site root directory
directory_temporary: Site temporary directory
directory_theme_default: Default theme directory
directory_theme_admin: Admin theme directory
maintenance:
description: Switch site into maintenance mode
arguments:
Expand Down
5 changes: 5 additions & 0 deletions config/translations/console.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,8 @@ commands:
help: Update the console command to the latest version.
messages:
success: The console has been updated to the latest version.
site:
status:
description: View current Drupal Installation status
arguments:
fields-group: Show a set of fields groupping by type All available groups are: version, database, theme, directories
14 changes: 9 additions & 5 deletions config/translations/console.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ commands:
inputs: common.questions.inputs
routing: Mise à jour fichier de routage
module:
description: Générer un module.
help: Le <info> générer: le module </ info> commande aide à générer un nouveau module
description: Générer un module.
help: Le <info> générer: le module </ info> commande aide à générer un nouveau module
welcome: Bienvenue sur le générateur de modules Drupal
options:
module: Le nom du module
Expand All @@ -159,10 +159,10 @@ commands:
description: Entrez la description du module
core: Entrez la version core Drupal
package: Entrez le nom du paquet
controller: Voulez-vous générer un contrôleur par défaut
controller: Voulez-vous générer un contrôleur par défaut
test: Voulez-vous générer une classe de test unitaire
warnings:
module-unavailable: Warning The following modules are not already available in your local environment "%s"
module-unavailable: Warning The following modules are not already available in your local environment "%s"
permission:
description: Generate module permissions
help: The <info>generate:permissions</info> command helps you generate new permissions
Expand Down Expand Up @@ -349,4 +349,8 @@ commands:
help: Update the console command to the latest version.
messages:
success: The console has been updated to the latest version.

site:
status:
description: View current Drupal Installation status
arguments:
fields-group: show a set of fields groupping by type All available groups are: version, database, theme, directories
5 changes: 5 additions & 0 deletions config/translations/console.pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,8 @@ commands:
messages:
rebuilding: Reconstruindo rotas, favor aguarde um momento
completed: Reconstrução de rota(s) finalizada.
site:
status:
description: View current Drupal Installation status
arguments:
fields-group: show a set of fields groupping by type All available groups are: version, database, theme, directories
23 changes: 23 additions & 0 deletions src/Command/ContainerAwareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,29 @@ public function getAuthenticationProviders()
return $this->getContainer()->get('authentication')->getSortedProviders();
}

/**
* @return \Drupal\system\SystemManager
*/
public function getSystemManager()
{
return $this->getContainer()->get('system.manager');
}

/**
* @return array
*/
public function getConnectionInfo()
{
return \Drupal\Core\Database\Database::getConnectionInfo();
}

/**
* @return \Drupal\Core\Extension\ThemeHandlerInterface
*/
public function getThemeHandler()
{
return $this->getContainer()->get('theme_handler');
}

public function validateModuleExist($module_name)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Helper/MessageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MessageHelper extends Helper
/**
* @param TranslatorHelper $translator
*/
function __construct(TranslatorHelper $translator)
public function __construct(TranslatorHelper $translator)
{
$this->translator = $translator;
}
Expand Down Expand Up @@ -191,7 +191,8 @@ public function showGeneratedFiles($output, $files)
* @param string $file
* @param int $index
*/
private function showFile($output, $file, $index){
private function showFile($output, $file, $index)
{
$output->writeln(sprintf(
'<info>%s</info> - <comment>%s</comment>',
$index,
Expand Down
183 changes: 183 additions & 0 deletions src/Command/SiteStatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\SiteStatusCommand.
*/

namespace Drupal\AppConsole\Command;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This command provides a view of the current drupal installation.
*
* @category site
*/
class SiteStatusCommand extends ContainerAwareCommand
{

/* @var $connectionInfoKeys array */
protected $connectionInfoKeys = [
'driver',
'host',
'database',
'port',
'username',
'password'
];

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('site:status')
->setDescription($this->trans('commands.site.status.description'))
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$systemManager = $this->getSystemManager();
$requirements = $systemManager->listRequirements();

$table = $this->getHelperSet()->get('table');

$table->setlayout($table::LAYOUT_COMPACT);

$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.application')
),
null
]);
$table->addRow([
'Drupal Console',
$this->getApplication()->getVersion()
]);
$table->addRow([null, null]);

$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.system')
),
null
]);

foreach ($requirements as $requirement) {
$table->addRow([
$requirement['title'],
$requirement['value']
]);
}
$table->addRow([null, null]);

$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.database')
),
null
]);

$connectionInfo = $this->getConnectionInfo();

foreach ($this->connectionInfoKeys as $connectionInfoKey) {
$table->addRow([
$this->trans('commands.site.status.messages.'.$connectionInfoKey),
$connectionInfo['default'][$connectionInfoKey]
]);
}

$table->addRow([
$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']
)
]);

$table->addRow([null, null]);
$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.themes')
),
null
]);

$themes = $this->getThemesInfo();
foreach ($themes as $key => $theme) {
$table->addRow([
$this->trans('commands.site.status.messages.'.$key),
$theme
]);
}

$table->addRow([null, null]);
$table->addRow([
sprintf(
'<comment>%s</comment>',
$this->trans('commands.site.status.messages.directories')
),
null
]);

$directories = $this->getDirectoriesInfo();
foreach ($directories as $key => $directory) {
$table->addRow([
$this->trans('commands.site.status.messages.'.$key),
$directory
]);
}

$table->render($output);
}

protected function getThemesInfo()
{
$configFactory = $this->getConfigFactory();
$config = $configFactory->get('system.theme');

return [
'theme_default' => $config->get('default'),
'theme_admin' => $config->get('admin')
];
}

protected function getDirectoriesInfo()
{
$drupalBootstrap = $this->getHelperSet()->get('bootstrap');
$drupal_root = $drupalBootstrap->getDrupalRoot();

$configFactory = $this->getConfigFactory();
$systemTheme = $configFactory->get('system.theme');

$themeHandler = $this->getThemeHandler();
$themeDefault = $themeHandler->getTheme($systemTheme->get('default'));
$themeAdmin = $themeHandler->getTheme($systemTheme->get('admin'));

$systemFile = $this->getConfigFactory()->get('system.file');

return [
'directory_root' => $drupal_root,
'directory_temporary' => $systemFile->get('path.temporary'),
'directory_theme_default' => '/'. $themeDefault->getpath(),
'directory_theme_admin' => '/' . $themeAdmin->getpath(),
];
}
}

0 comments on commit d6bb8ff

Please sign in to comment.