Skip to content

Commit

Permalink
Merge pull request #11 from ho-nl/2.4.6-p1
Browse files Browse the repository at this point in the history
feat(GOM2-2320): update for magento 2.4.6-p1
  • Loading branch information
Maikel-Koek authored Aug 3, 2023
2 parents 8c70258 + 5d2182d commit 9442c05
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/IndexerReindexCommandPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class IndexerReindexCommandPreference extends \Magento\Indexer\Console\Command\I
public function __construct(
ObjectManagerFactory $objectManagerFactory,
IndexerRegistry $indexerRegistry = null,
DependencyInfoProvider $dependencyInfoProvider = null
DependencyInfoProvider $dependencyInfoProvider = null,
) {
$this->indexerRegistry = $indexerRegistry;
$this->dependencyInfoProvider = $dependencyInfoProvider;
Expand All @@ -68,8 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($this->getIndexers($input) as $indexer) {
try {
$this->validateIndexerStatus($indexer);
$startTime = intval(microtime(true));
$output->writeln('Rebuilding ' . $indexer->getTitle() . ' index at ' . gmdate('H:i:s', $startTime));
$startTime = new \DateTimeImmutable();
$output->writeln(__('Rebuilding %1 index at %2', $indexer->getTitle(), $startTime->format('H:i:s')));
$indexerConfig = $this->getConfig()->getIndexer($indexer->getId());
$sharedIndex = $indexerConfig['shared_index'];

Expand All @@ -80,12 +80,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->validateSharedIndex($sharedIndex);
}
}
$resultTime = intval(microtime(true) - $startTime);
$endTime = new \DateTimeImmutable();
$interval = $startTime->diff($endTime);
$days = $interval->format('%d');
$hours = $days > 0 ? $days * 24 + $interval->format('%H') : $interval->format('%H');
$minutes = $interval->format('%I');
$seconds = $interval->format('%S');
$output->writeln(
' > ' .
$indexer->getTitle() .
' index has been rebuilt successfully in ' .
gmdate('H:i:s', $resultTime)
__(
'> %1 index has been rebuilt successfully in %2:%3:%4',
$indexer->getTitle(),
$hours,
$minutes,
$seconds,
),
);
$returnValue = Cli::RETURN_SUCCESS;
} catch (LocalizedException $e) {
Expand Down Expand Up @@ -127,7 +135,7 @@ protected function getIndexers(InputInterface $input)

return array_intersect_key(
$allIndexers,
array_flip(array_unique(array_merge(array_keys($indexers), $invalidRelatedIndexers, $dependentIndexers)))
array_flip(array_unique(array_merge(array_keys($indexers), $invalidRelatedIndexers, $dependentIndexers))),
);
}

Expand All @@ -144,7 +152,7 @@ private function getRelatedIndexerIds(string $indexerId)
$relatedIndexerIds = array_merge(
$relatedIndexerIds,
[$relatedIndexerId],
$this->getRelatedIndexerIds($relatedIndexerId)
$this->getRelatedIndexerIds($relatedIndexerId),
);
}

Expand Down Expand Up @@ -181,7 +189,7 @@ private function validateIndexerStatus(IndexerInterface $indexer)
{
if ($indexer->getStatus() == StateInterface::STATUS_WORKING) {
throw new LocalizedException(
__('%1 index is locked by another reindex process. Skipping.', $indexer->getTitle())
__('%1 index is locked by another reindex process. Skipping.', $indexer->getTitle()),
);
}
}
Expand Down Expand Up @@ -214,7 +222,7 @@ private function validateSharedIndex($sharedIndex)
{
if (empty($sharedIndex)) {
throw new \InvalidArgumentException(
'The sharedIndex is an invalid shared index identifier. Verify the identifier and try again.'
'The sharedIndex is an invalid shared index identifier. Verify the identifier and try again.',
);
}
$indexerIds = $this->getIndexerIdsBySharedIndex($sharedIndex);
Expand Down

0 comments on commit 9442c05

Please sign in to comment.