Skip to content

[debug:module] Allow multiple options #4125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/services/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
135 changes: 48 additions & 87 deletions src/Command/Debug/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,14 +27,6 @@ class ModuleCommand extends Command
*/
protected $site;

/**
* DebugCommand constructor.
*
* @param Client $httpClient
*/

protected $httpClient;

/**
* ChainDebugCommand constructor.
*
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}