|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / setup / src / Magento / Setup / Console / Command / |
Filename | /home/dev2.destoffenstraat.com/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php |
Size | 5.12 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 28-Jan-2025 06:45 |
Last accessed | 24-Aug-2025 05:48 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Setup\Console\Command;
use Magento\Framework\Console\Cli;
use Magento\Framework\Module\FullModuleList;
use Magento\Framework\Module\ModuleList;
use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command for displaying status of modules
*/
class ModuleStatusCommand extends AbstractSetupCommand
{
/**
* @var ObjectManagerProvider
*/
private $objectManagerProvider;
/**
* @param ObjectManagerProvider $objectManagerProvider
*/
public function __construct(ObjectManagerProvider $objectManagerProvider)
{
$this->objectManagerProvider = $objectManagerProvider;
parent::__construct();
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName('module:status')
->setDescription('Displays status of modules')
->addArgument(
'module-names',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Optional module name'
)
->addOption('enabled', null, null, 'Print only enabled modules')
->addOption('disabled', null, null, 'Print only disabled modules');
parent::configure();
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleNames = $input->getArgument('module-names');
if (!empty($moduleNames)) {
foreach ($moduleNames as $moduleName) {
$this->showSpecificModule($moduleName, $output);
}
return Cli::RETURN_SUCCESS;
}
$onlyEnabled = $input->getOption('enabled');
if ($onlyEnabled) {
return $this->showEnabledModules($output);
}
$onlyDisabled = $input->getOption('disabled');
if ($onlyDisabled) {
return $this->showDisabledModules($output);
}
$output->writeln('<info>List of enabled modules:</info>');
$this->showEnabledModules($output);
$output->writeln('');
$output->writeln("<info>List of disabled modules:</info>");
$this->showDisabledModules($output);
$output->writeln('');
return Cli::RETURN_SUCCESS;
}
/**
* Specific module show
*
* @param string $moduleName
* @param OutputInterface $output
* @return int
*/
private function showSpecificModule(string $moduleName, OutputInterface $output): int
{
$allModules = $this->getAllModules();
if (!in_array($moduleName, $allModules->getNames(), true)) {
$output->writeln($moduleName . ' : <error>Module does not exist</error>');
return Cli::RETURN_FAILURE;
}
$enabledModules = $this->getEnabledModules();
if (in_array($moduleName, $enabledModules->getNames(), true)) {
$output->writeln($moduleName . ' : <info>Module is enabled</info>');
return Cli::RETURN_FAILURE;
}
$output->writeln($moduleName . ' : <info> Module is disabled</info>');
return Cli::RETURN_SUCCESS;
}
/**
* Enable modules show
*
* @param OutputInterface $output
* @return int
*/
private function showEnabledModules(OutputInterface $output): int
{
$enabledModules = $this->getEnabledModules();
$enabledModuleNames = $enabledModules->getNames();
if (count($enabledModuleNames) === 0) {
$output->writeln('None');
return Cli::RETURN_FAILURE;
}
$output->writeln(join("\n", $enabledModuleNames));
return Cli::RETURN_SUCCESS;
}
/**
* Disabled modules show
*
* @param OutputInterface $output
* @return int
*/
private function showDisabledModules(OutputInterface $output): int
{
$disabledModuleNames = $this->getDisabledModuleNames();
if (count($disabledModuleNames) === 0) {
$output->writeln('None');
return Cli::RETURN_FAILURE;
}
$output->writeln(join("\n", $disabledModuleNames));
return Cli::RETURN_SUCCESS;
}
/**
* Returns all modules
*
* @return FullModuleList
*/
private function getAllModules(): FullModuleList
{
return $this->objectManagerProvider->get()
->create(FullModuleList::class);
}
/**
* Returns enabled modules
*
* @return ModuleList
*/
private function getEnabledModules(): ModuleList
{
return $this->objectManagerProvider->get()
->create(ModuleList::class);
}
/**
* Returns disabled module names
*
* @return array
*/
private function getDisabledModuleNames(): array
{
$fullModuleList = $this->getAllModules();
$enabledModules = $this->getEnabledModules();
return array_diff($fullModuleList->getNames(), $enabledModules->getNames());
}
}
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Setup\Console\Command;
use Magento\Framework\Console\Cli;
use Magento\Framework\Module\FullModuleList;
use Magento\Framework\Module\ModuleList;
use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command for displaying status of modules
*/
class ModuleStatusCommand extends AbstractSetupCommand
{
/**
* @var ObjectManagerProvider
*/
private $objectManagerProvider;
/**
* @param ObjectManagerProvider $objectManagerProvider
*/
public function __construct(ObjectManagerProvider $objectManagerProvider)
{
$this->objectManagerProvider = $objectManagerProvider;
parent::__construct();
}
/**
* @inheritdoc
*/
protected function configure()
{
$this->setName('module:status')
->setDescription('Displays status of modules')
->addArgument(
'module-names',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Optional module name'
)
->addOption('enabled', null, null, 'Print only enabled modules')
->addOption('disabled', null, null, 'Print only disabled modules');
parent::configure();
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleNames = $input->getArgument('module-names');
if (!empty($moduleNames)) {
foreach ($moduleNames as $moduleName) {
$this->showSpecificModule($moduleName, $output);
}
return Cli::RETURN_SUCCESS;
}
$onlyEnabled = $input->getOption('enabled');
if ($onlyEnabled) {
return $this->showEnabledModules($output);
}
$onlyDisabled = $input->getOption('disabled');
if ($onlyDisabled) {
return $this->showDisabledModules($output);
}
$output->writeln('<info>List of enabled modules:</info>');
$this->showEnabledModules($output);
$output->writeln('');
$output->writeln("<info>List of disabled modules:</info>");
$this->showDisabledModules($output);
$output->writeln('');
return Cli::RETURN_SUCCESS;
}
/**
* Specific module show
*
* @param string $moduleName
* @param OutputInterface $output
* @return int
*/
private function showSpecificModule(string $moduleName, OutputInterface $output): int
{
$allModules = $this->getAllModules();
if (!in_array($moduleName, $allModules->getNames(), true)) {
$output->writeln($moduleName . ' : <error>Module does not exist</error>');
return Cli::RETURN_FAILURE;
}
$enabledModules = $this->getEnabledModules();
if (in_array($moduleName, $enabledModules->getNames(), true)) {
$output->writeln($moduleName . ' : <info>Module is enabled</info>');
return Cli::RETURN_FAILURE;
}
$output->writeln($moduleName . ' : <info> Module is disabled</info>');
return Cli::RETURN_SUCCESS;
}
/**
* Enable modules show
*
* @param OutputInterface $output
* @return int
*/
private function showEnabledModules(OutputInterface $output): int
{
$enabledModules = $this->getEnabledModules();
$enabledModuleNames = $enabledModules->getNames();
if (count($enabledModuleNames) === 0) {
$output->writeln('None');
return Cli::RETURN_FAILURE;
}
$output->writeln(join("\n", $enabledModuleNames));
return Cli::RETURN_SUCCESS;
}
/**
* Disabled modules show
*
* @param OutputInterface $output
* @return int
*/
private function showDisabledModules(OutputInterface $output): int
{
$disabledModuleNames = $this->getDisabledModuleNames();
if (count($disabledModuleNames) === 0) {
$output->writeln('None');
return Cli::RETURN_FAILURE;
}
$output->writeln(join("\n", $disabledModuleNames));
return Cli::RETURN_SUCCESS;
}
/**
* Returns all modules
*
* @return FullModuleList
*/
private function getAllModules(): FullModuleList
{
return $this->objectManagerProvider->get()
->create(FullModuleList::class);
}
/**
* Returns enabled modules
*
* @return ModuleList
*/
private function getEnabledModules(): ModuleList
{
return $this->objectManagerProvider->get()
->create(ModuleList::class);
}
/**
* Returns disabled module names
*
* @return array
*/
private function getDisabledModuleNames(): array
{
$fullModuleList = $this->getAllModules();
$enabledModules = $this->getEnabledModules();
return array_diff($fullModuleList->getNames(), $enabledModules->getNames());
}
}