Skip to content
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

Updated list commands #1458

Draft
wants to merge 38 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1504aa6
Added interfaces
sreichel Aug 7, 2024
0be0fdb
Updated workflows
sreichel Aug 7, 2024
9b5ac5b
Updated signature
sreichel Aug 7, 2024
6889b7e
Let tests pass ... (fix it later)
sreichel Aug 7, 2024
a54d824
Updated workflows (php version)
sreichel Aug 7, 2024
94eae9b
Reverted for php7.4
sreichel Aug 7, 2024
ce4ab80
Reverted for php7.4 (2)
sreichel Aug 7, 2024
5eb59a9
Renamed interface [skip ci]
sreichel Aug 7, 2024
123e36e
Updated admin:user:list
sreichel Aug 7, 2024
a595d5b
Updated cache:list
sreichel Aug 7, 2024
8d33a1c
Updated interface
sreichel Aug 9, 2024
4c1e401
Updated sys:store:list
sreichel Aug 9, 2024
5651ee6
Updated cms:block:list
sreichel Aug 9, 2024
caab9c3
Updated sys:cron:list
sreichel Aug 10, 2024
09f9d3e
Updated index:list
sreichel Aug 10, 2024
84a83d0
Updated AbstractMagentoCommand
sreichel Aug 10, 2024
81ba741
Added composer/composer to dev-deps
sreichel Aug 10, 2024
dd5c13e
Updated dev:theme:list
sreichel Aug 10, 2024
bbf411d
Updated AbstractAdminUserCommand
sreichel Aug 10, 2024
10fe55c
Minor changes
sreichel Aug 10, 2024
3d7c002
Updated script:repo:list
sreichel Aug 11, 2024
df447e4
Updated sys:cron:history
sreichel Aug 13, 2024
ad92faa
Updated sys:cron:list [skip ci]
sreichel Aug 13, 2024
b6b2ade
Updated sys:store:config:base-url:list
sreichel Aug 13, 2024
2e6a857
Updated dev:email-template:usage
sreichel Aug 13, 2024
9c84d91
Updated dev:module:rewrite:list
sreichel Aug 13, 2024
5cf802e
Updated dev:module:list
sreichel Aug 14, 2024
e81a1a2
Updated customer:list
sreichel Aug 14, 2024
30833e8
Fixed tests
sreichel Aug 14, 2024
c7fcb88
Merge branch 'develop' into list-commands
sreichel Aug 22, 2024
135f0ec
Merge branch 'develop' into list-commands
sreichel Nov 12, 2024
36a4a26
Updated test
sreichel Nov 12, 2024
b249395
Fixed test (?)
sreichel Nov 12, 2024
f574798
Fixed test (?)
sreichel Nov 12, 2024
2318443
Fixed test (?)
sreichel Nov 12, 2024
c3a814f
Merge branch 'develop' into list-commands
sreichel Feb 3, 2025
b78bef8
updated test
sreichel Feb 4, 2025
4e4a240
updated test ... test
sreichel Feb 4, 2025
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"magerun"
],
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.3.0 || ~8.2.0 || ~8.4.0",
"ext-json": "*",
"ext-libxml": "*",
"ext-pdo": "*",
Expand Down
71 changes: 68 additions & 3 deletions src/N98/Magento/Command/AbstractMagentoCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace N98\Magento\Command;

use Composer\Composer;
Expand Down Expand Up @@ -39,6 +41,8 @@
*/
abstract class AbstractMagentoCommand extends Command
{
public const COMMAND_OPTION_FORMAT = 'format';

/**
* @var string
*/
Expand Down Expand Up @@ -69,6 +73,28 @@ abstract class AbstractMagentoCommand extends Command
*/
protected $config;

/**
* @var array|null
*/
protected ?array $data = null;

/**
* @var string
*/
protected static string $noResultMessage = '';

/**
* @var bool
*/
protected static bool $detectMagentoSilent = true;

protected function configure()
{
if ($this instanceof CommandWithFormatOption || $this instanceof CommandFormatable) {
$this->addFormatOption();
}
}

/**
* Initializes the command just after the input has been validated.
*
Expand All @@ -83,11 +109,50 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->checkDeprecatedAliases($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($this instanceof CommandFormatable) {
$this->detectMagento($output, static::$detectMagentoSilent);

$formatOption = $input->getOption(static::COMMAND_OPTION_FORMAT);

if ($formatOption === null) {
$this->writeSection($output, $this->getSectionTitle($input, $output));
}

if (!$this->initMagento()) {
return Command::FAILURE;
}

$data = $this->getListData($input, $output);
if ($formatOption === null && $data === []) {
if (static::$noResultMessage) {
$output->writeln(sprintf(
'<info>%s</info>',
static::$noResultMessage
));
} else {
$output->writeln(sprintf(
'<info>No entry found for "%s" </info>',
$this->getSectionTitle($input, $output)
));
}
}

$this->getTableHelper()
->setHeaders($this->getListHeader($input, $output))
->renderByFormat($output, $data, $input->getOption(self::COMMAND_OPTION_FORMAT));

return Command::SUCCESS;
}

return Command::INVALID;
}

private function _initWebsites()
{
$this->_websiteCodeMap = [];
/** @var \Mage_Core_Model_Website[] $websites */
$websites = Mage::app()->getWebsites(false);
$websites = Mage::app()->getWebsites();
foreach ($websites as $website) {
$this->_websiteCodeMap[$website->getId()] = $website->getCode();
}
Expand Down Expand Up @@ -638,7 +703,7 @@ protected function createSubCommandFactory(
public function addFormatOption(): self
{
$this->addOption(
'format',
self::COMMAND_OPTION_FORMAT,
null,
InputOption::VALUE_OPTIONAL,
'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
Expand Down
12 changes: 9 additions & 3 deletions src/N98/Magento/Command/Admin/User/AbstractAdminUserCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php

declare(strict_types=1);

namespace N98\Magento\Command\Admin\User;

use Mage;
use Mage_Admin_Model_Roles;
use Mage_Admin_Model_Rules;
use Mage_Admin_Model_User;
use N98\Magento\Command\AbstractMagentoCommand;

/**
Expand All @@ -12,23 +18,23 @@
abstract class AbstractAdminUserCommand extends AbstractMagentoCommand
{
/**
* @return \Mage_Core_Model_Abstract|\Mage_Admin_Model_User
* @return Mage_Admin_Model_User
*/
protected function getUserModel()
{
return $this->_getModel('admin/user');
}

/**
* @return \Mage_Core_Model_Abstract
* @return Mage_Admin_Model_Roles
*/
protected function getRoleModel()
{
return $this->_getModel('admin/roles');
}

/**
* @return \Mage_Core_Model_Abstract
* @return Mage_Admin_Model_Rules
*/
protected function getRulesModel()
{
Expand Down
71 changes: 48 additions & 23 deletions src/N98/Magento/Command/Admin/User/ListCommand.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,76 @@
<?php

declare(strict_types=1);

namespace N98\Magento\Command\Admin\User;

use Mage_Admin_Model_User;
use N98\Magento\Command\CommandFormatable;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function is_array;

/**
* List admin user password command
*
* @package N98\Magento\Command\Admin\User
*/
class ListCommand extends AbstractAdminUserCommand
class ListCommand extends AbstractAdminUserCommand implements CommandFormatable
{
protected function configure()
/**
* @var string
*/
protected static $defaultName = 'admin:user:list';

/**
* @var string
*/
protected static $defaultDescription = 'List admin users.';

/**
* @var string
*/
protected static string $noResultMessage = 'No admin users found.';

/**
* {@inheritDoc}
*/
public function getSectionTitle(InputInterface $input, OutputInterface $output): string
{
return 'Admin users';
}

/**
* {@inheritDoc}
*/
public function getListHeader(InputInterface $input, OutputInterface $output): array
{
$this
->setName('admin:user:list')
->setDescription('List admin users.')
->addFormatOption()
;
return ['id', 'username', 'email', 'status'];
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
public function getListData(InputInterface $input, OutputInterface $output): array
{
$this->detectMagento($output, true);
if (!$this->initMagento()) {
return 0;
if (is_array($this->data)) {
return $this->data;
}

/** @var \Mage_Admin_Model_User $userModel */
$userModel = $this->getUserModel();
$userList = $userModel->getCollection();
$table = [];
$this->data = [];
/** @var Mage_Admin_Model_User $user */
foreach ($userList as $user) {
$table[] = [$user->getId(), $user->getUsername(), $user->getEmail(), $user->getIsActive() ? 'active' : 'inactive'];
$this->data[] = [
$user->getId(),
$user->getUsername(),
$user->getEmail(),
$user->getIsActive() ? 'active' : 'inactive'
];
}

$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['id', 'username', 'email', 'status'])
->renderByFormat($output, $table, $input->getOption('format'));
return 0;
return $this->data;
}
}
56 changes: 34 additions & 22 deletions src/N98/Magento/Command/Cache/ListCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace N98\Magento\Command\Cache;

use N98\Magento\Command\CommandFormatable;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -10,39 +13,48 @@
*
* @package N98\Magento\Command\Cache
*/
class ListCommand extends AbstractCacheCommand
class ListCommand extends AbstractCacheCommand implements CommandFormatable
{
protected function configure()
/**
* @var string
*/
public static $defaultName = 'cache:list';

/**
* @var string
*/
public static $defaultDescription = 'Lists all magento caches.';

/**
* {@inheritDoc}
*/
public function getSectionTitle(InputInterface $input, OutputInterface $output): string
{
$this
->setName('cache:list')
->setDescription('Lists all magento caches')
->addFormatOption()
;
return 'Caches';
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
public function getListHeader(InputInterface $input, OutputInterface $output): array
{
$this->detectMagento($output, true);
if (!$this->initMagento()) {
return 0;
}
return ['code', 'status'];
}

$cacheTypes = $this->_getCacheModel()->getTypes();
/**
* {@inheritDoc}
*/
public function getListData(InputInterface $input, OutputInterface $output): array
{
$table = [];
$cacheTypes = $this->_getCacheModel()->getTypes();
foreach ($cacheTypes as $cacheCode => $cacheInfo) {
$table[] = [$cacheCode, $cacheInfo['status'] ? 'enabled' : 'disabled'];
$table[] = [
$cacheCode,
$cacheInfo['status'] ? 'enabled' : 'disabled'
];
}

$tableHelper = $this->getTableHelper();
$tableHelper
->setHeaders(['code', 'status'])
->renderByFormat($output, $table, $input->getOption('format'));
return 0;
return $table;
}
}
Loading
Loading