Skip to content
Permalink
Browse files

[debug:module] Allow multiple options (#4125)

  • Loading branch information...
harold20 authored and enzolutions committed Aug 5, 2019
1 parent a51b7f4 commit 350cc3d8ac10f0945c7a5118ffcc21f865a831d1
Showing with 49 additions and 88 deletions.
  1. +1 −1 config/services/debug.yml
  2. +48 −87 src/Command/Debug/ModuleCommand.php
@@ -67,7 +67,7 @@ services:
- { name: drupal.command }
console.module_debug:
class: Drupal\Console\Command\Debug\ModuleCommand
arguments: ['@console.configuration_manager', '@console.site', '@http_client']
arguments: ['@console.configuration_manager', '@console.site']
tags:
- { name: drupal.command }
console.image_styles_debug:
@@ -7,13 +7,12 @@
namespace Drupal\Console\Command\Debug;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Site;
use GuzzleHttp\Client;
use Drupal\Console\Core\Utils\ConfigurationManager;
class ModuleCommand extends Command
@@ -28,14 +27,6 @@ class ModuleCommand extends Command
*/
protected $site;
/**
* DebugCommand constructor.
*
* @param Client $httpClient
*/
protected $httpClient;
/**
* ChainDebugCommand constructor.
*
@@ -44,12 +35,10 @@ class ModuleCommand extends Command
*/
public function __construct(
ConfigurationManager $configurationManager,
Site $site,
Client $httpClient
Site $site
) {
$this->configurationManager = $configurationManager;
$this->site = $site;
$this->httpClient = $httpClient;
parent::__construct();
}
@@ -84,61 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$status = strtolower($input->getOption('status'));
$type = strtolower($input->getOption('type'));
$modules = strtolower($input->getArgument('module'));
if ($modules) {
$config = $this->configurationManager->getConfiguration();
$repo = $config->get('application.composer.repositories.default');
foreach ($modules as $module) {
$url = sprintf(
'%s/packages/drupal/%s.json',
$config->get('application.composer.packages.default'),
$module
);
try {
$data = $this->httpClient->getUrlAsJson($repo . $url);
} catch (\Exception $e) {
$this->getIo()->error(
sprintf(
$this->trans('commands.debug.module.messages.no-results'),
$module
)
);
return 1;
}
$tableHeader = [
'<info>'.$data->package->name.'</info>'
];
$tableRows = [];
$tableRows[] = [
$data->package->description
];
$tableRows[] = [
'<comment>'.$this->trans('commands.debug.module.messages.total-downloads').'</comment>',
$data->package->downloads->total
];
$tableRows[] = [
'<comment>'.$this->trans('commands.debug.module.messages.total-monthly').'</comment>',
$data->package->downloads->monthly
];
$tableRows[] = [
'<comment>'.$this->trans('commands.debug.module.messages.total-daily').'</comment>',
$data->package->downloads->daily
];
$this->getIo()->table($tableHeader, $tableRows, 'compact');
}
return 0;
}
$modules = $input->getArgument('module');
if ($status == 'installed') {
$status = 1;
@@ -166,32 +101,58 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->trans('commands.debug.module.messages.origin'),
];
$tableRows = [];
$modules = system_rebuild_module_data();
foreach ($modules as $module_id => $module) {
if ($status >= 0 && $status != $module->status) {
$tableRows = $this->getModules($status, $type, $modules);
$this->getIo()->table($tableHeader, $tableRows, 'compact');
}
/**
* Get the module info
* @param $status
* @param $type
* @param $modules
*
* @return array
*/
private function getModules($status, $type, $modules) {
$result = [];
$modulesData = system_rebuild_module_data();
if(!$modules) {
$modules = array_keys($modulesData) ;
}
foreach ($modules as $module) {
$moduleData = $modulesData[strtolower($module)];
if(!$moduleData) {
continue;
}
if ($status >= 0 && $status != $moduleData->status) {
continue;
}
if ($type !== null && $type !== $module->origin) {
if ($type !== null && $type !== $moduleData->origin) {
continue;
}
$module_status = ($module->status) ? $this->trans('commands.debug.module.messages.installed') : $this->trans('commands.debug.module.messages.uninstalled');
$module_origin = ($module->origin) ? $module->origin : 'no core';
$schema_version = (drupal_get_installed_schema_version($module_id)!= -1?drupal_get_installed_schema_version($module_id): '');
$tableRows [] = [
$module_id,
$module->info['name'],
$module->info['package'],
$module->info['version'],
$schema_version,
$module_status,
$module_origin,
$module_status = ($moduleData->status) ? $this->trans('commands.debug.module.messages.installed') : $this->trans('commands.debug.module.messages.uninstalled');
$module_origin = ($moduleData->origin) ? $moduleData->origin : 'no core';
$schema_version = (drupal_get_installed_schema_version($module)!= -1?drupal_get_installed_schema_version($module): '');
$result [] = [
$module,
$moduleData->info['name'],
$moduleData->info['package'],
$moduleData->info['version'],
$schema_version,
$module_status,
$module_origin,
];
}
$this->getIo()->table($tableHeader, $tableRows, 'compact');
return $result;
}
}

0 comments on commit 350cc3d

Please sign in to comment.
You can’t perform that action at this time.