6 declare(strict_types=1);
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Input\InputArgument;
28 private $commandName =
'indexer:show-dimensions-mode';
34 private $configReader;
50 $this->configReader = $configReader;
51 $this->indexers = $indexers;
60 $this->setName($this->commandName)
61 ->setDescription(
'Shows Indexer Dimension Mode')
62 ->setDefinition($this->getInputList());
72 protected function execute(InputInterface $input, OutputInterface
$output)
74 $errors = $this->validate($input);
76 throw new \InvalidArgumentException(implode(PHP_EOL,
$errors));
80 $indexer = $this->getObjectManager()->get(\
Magento\Indexer\Model\Indexer::class);
82 $selectedIndexers = $input->getArgument(self::INPUT_KEY_INDEXER);
83 if ($selectedIndexers) {
84 $indexersList = (array)$selectedIndexers;
86 $indexersList = $this->indexers;
88 foreach ($indexersList as $indexerId) {
90 $configPath = sprintf(self::XML_PATH_DIMENSIONS_MODE_MASK, $indexerId);
94 }
catch (\Exception $e) {
95 $output->writeln(
'"' .
$indexer->getTitle() .
'" indexer process unknown error:' . PHP_EOL);
96 $output->writeln($e->getMessage() . PHP_EOL);
109 private function getInputList(): array
111 $optionDescription =
'Space-separated list of index types or omit to apply to all indexes';
113 self::INPUT_KEY_INDEXER,
114 InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
115 $optionDescription .
' (' . implode($this->indexers) .
')' 127 private function validate(InputInterface $input): array
129 $inputIndexer = (array)$input->getArgument(self::INPUT_KEY_INDEXER);
130 $acceptedValues = array_keys($this->indexers);
131 $errors = $this->validateArgument(self::INPUT_KEY_INDEXER, $inputIndexer, $acceptedValues);
144 private function validateArgument(
string $inputKey, array $inputIndexer, array $acceptedValues): array
147 $acceptedIndexerValues =
' Accepted values for "<' . $inputKey .
'>" are \'' .
148 implode(
',', $acceptedValues) .
'\'';
149 if (!empty($inputIndexer) && !\array_intersect($inputIndexer, $acceptedValues)) {
150 $errors[] =
'Invalid value for "<' . $inputKey .
'>" argument.' . $acceptedIndexerValues;
__construct(ObjectManagerFactory $objectManagerFactory, ScopeConfigInterface $configReader, array $indexers)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
const DIMENSION_MODE_NONE
const XML_PATH_DIMENSIONS_MODE_MASK