From 5d2182d1276c550b642c312a1a3ecfed90977206 Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Wed, 2 Aug 2023 17:27:26 +0200 Subject: [PATCH] feat(GOM2-2320): update for magento 2.4.6-p1 --- src/IndexerReindexCommandPreference.php | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/IndexerReindexCommandPreference.php b/src/IndexerReindexCommandPreference.php index 15b41f2..24c26b7 100644 --- a/src/IndexerReindexCommandPreference.php +++ b/src/IndexerReindexCommandPreference.php @@ -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; @@ -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']; @@ -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) { @@ -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))), ); } @@ -144,7 +152,7 @@ private function getRelatedIndexerIds(string $indexerId) $relatedIndexerIds = array_merge( $relatedIndexerIds, [$relatedIndexerId], - $this->getRelatedIndexerIds($relatedIndexerId) + $this->getRelatedIndexerIds($relatedIndexerId), ); } @@ -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()), ); } } @@ -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);