Skip to content

Commit

Permalink
Add module status feature to dev:module:list
Browse files Browse the repository at this point in the history
Related to netz98#1422
  • Loading branch information
cmuench committed Apr 27, 2024
1 parent b32d3b0 commit bd89341
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions src/N98/Magento/Command/Developer/Module/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace N98\Magento\Command\Developer\Module;

use Magento\Framework\Filter\Input;
use Magento\Framework\Module\FullModuleList;
use Magento\Framework\Module\Manager;
use N98\Magento\Command\AbstractMagentoCommand;
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
use Symfony\Component\Console\Command\Command;
Expand All @@ -21,21 +24,31 @@ class ListCommand extends AbstractMagentoCommand
protected $moduleList;

/**
* @var \Magento\Framework\Module\ModuleListInterface
* @var \Magento\Framework\Module\FullModuleList
*/
protected $moduleListObject;

/**
* @var Manager
*/
protected $moduleManager;

/**
* @return array
*/
public function getModuleList()
{
return $this->moduleList;
}

/**
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param FullModuleList $moduleList
* @param Manager $moduleManager
*/
public function inject(\Magento\Framework\Module\ModuleListInterface $moduleList)
public function inject(\Magento\Framework\Module\FullModuleList $moduleList, Manager $moduleManager)
{
$this->moduleListObject = $moduleList;
$this->moduleManager = $moduleManager;
}

protected function configure()
Expand All @@ -49,6 +62,8 @@ protected function configure()
'Show modules of a specific vendor (case insensitive)'
)
->setDescription('List all installed modules')
->addOption('only-enabled', 'e', InputOption::VALUE_NONE, 'Show only enabled modules')
->addOption('only-disabled', 'd', InputOption::VALUE_NONE, 'Show only disabled modules')
->addOption(
'format',
null,
Expand All @@ -65,35 +80,62 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('only-disabled') && $input->getOption('only-enabled')) {
throw new \Exception('You can only use one of the options --only-enabled or --only-disabled');
}

$this->detectMagento($output, true);

if ($input->getOption('format') == null) {
$this->writeSection($output, 'Magento Modules');
}

$this->initMagento();
$this->prepareModuleList($input->getOption('vendor'));
$this->prepareModuleList($input);

$this->getHelper('table')
->setHeaders(['Name', '(Schema) Version'])
->setHeaders(['Name', '(Schema) Version', 'Status'])
->renderByFormat($output, $this->moduleList, $input->getOption('format'));

return Command::SUCCESS;
}

protected function prepareModuleList($vendor)
/**
* @param string $vendor
* @return void
*/
protected function prepareModuleList(InputInterface $input)
{
$this->moduleList = [];

foreach ($this->moduleListObject->getAll() as $moduleName => $info) {
$vendor = $input->getOption('vendor');

foreach ($this->moduleListObject->getNames() as $moduleName) {

$info = $this->moduleListObject->getOne($moduleName);

// First index is (probably always) vendor
$moduleNameData = explode('_', $moduleName);

if ($vendor !== null && strtolower($moduleNameData[0]) !== strtolower($vendor)) {
continue;
}

$this->moduleList[] = [$info['name'], $info['setup_version']];
$isEnabled = $this->moduleManager->isEnabled($moduleName);

if ($isEnabled && $input->getOption('only-disabled')) {
continue;
}

if (!$isEnabled && $input->getOption('only-enabled')) {
continue;
}

$this->moduleList[] = [
$info['name'],
$info['setup_version'],
$isEnabled ? 'enabled' : 'disabled',
];
}
}
}

0 comments on commit bd89341

Please sign in to comment.