Skip to content

#26206 Add information about currently reindexed index. #26207

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<actionGroup ref="logout" stepKey="logout"/>
</after>
<!-- Generate the datetime default value -->
<generateDate date="now" format="m/j/y g:i A" stepKey="generateDefaultValue"/>
<generateDate date="now" format="n/j/y g:i A" stepKey="generateDefaultValue"/>
<!-- Create new datetime product attribute -->
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributes"/>
<waitForPageLoad stepKey="waitForPageLoadAttributes"/>
Expand Down
63 changes: 31 additions & 32 deletions app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace Magento\Indexer\Console\Command;

use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Indexer\Config\DependencyInfoProvider;
use Magento\Framework\Indexer\ConfigInterface;
use Magento\Framework\Indexer\IndexerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Indexer\StateInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Indexer\ConfigInterface;
use Magento\Framework\App\ObjectManagerFactory;

/**
* Command to run indexers
Expand Down Expand Up @@ -78,6 +78,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($this->getIndexers($input) as $indexer) {
try {
$this->validateIndexerStatus($indexer);

$output->write($indexer->getTitle() . ' index ');

$startTime = microtime(true);
$indexerConfig = $this->getConfig()->getIndexer($indexer->getId());
$sharedIndex = $indexerConfig['shared_index'];
Expand All @@ -90,17 +93,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
$resultTime = microtime(true) - $startTime;

$output->writeln(
$indexer->getTitle() . ' index has been rebuilt successfully in ' . gmdate('H:i:s', $resultTime)
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', $resultTime)])
);
$returnValue = Cli::RETURN_SUCCESS;
} catch (LocalizedException $e) {
$output->writeln($e->getMessage());
$output->writeln(__('exception: %message', ['message' => $e->getMessage()]));
} catch (\Exception $e) {
$output->writeln($indexer->getTitle() . ' indexer process unknown error:');
$output->writeln('process unknown error:');
$output->writeln($e->getMessage());

$output->writeln($e->getTraceAsString(), OutputInterface::VERBOSITY_DEBUG);
}
}

return $returnValue;
}

Expand All @@ -111,25 +118,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getIndexers(InputInterface $input)
{
$indexers = parent::getIndexers($input);
$indexers = parent::getIndexers($input);
$allIndexers = $this->getAllIndexers();
if (!array_diff_key($allIndexers, $indexers)) {
return $indexers;
}

$relatedIndexers = [];
$dependentIndexers = [];
$relatedIndexers = [[]];
$dependentIndexers = [[]];

foreach ($indexers as $indexer) {
$relatedIndexers = array_merge(
$relatedIndexers,
$this->getRelatedIndexerIds($indexer->getId())
);
$dependentIndexers = array_merge(
$dependentIndexers,
$this->getDependentIndexerIds($indexer->getId())
);
$relatedIndexers[] = $this->getRelatedIndexerIds($indexer->getId());
$dependentIndexers[] = $this->getDependentIndexerIds($indexer->getId());
}

$relatedIndexers = array_merge(...$relatedIndexers);
$dependentIndexers = array_merge(...$dependentIndexers);

$invalidRelatedIndexers = [];
foreach (array_unique($relatedIndexers) as $relatedIndexer) {
if ($allIndexers[$relatedIndexer]->isInvalid()) {
Expand Down Expand Up @@ -157,18 +162,15 @@ protected function getIndexers(InputInterface $input)
* @param string $indexerId
* @return array
*/
private function getRelatedIndexerIds(string $indexerId)
private function getRelatedIndexerIds(string $indexerId): array
{
$relatedIndexerIds = [];
$relatedIndexerIds = [[]];
foreach ($this->getDependencyInfoProvider()->getIndexerIdsToRunBefore($indexerId) as $relatedIndexerId) {
$relatedIndexerIds = array_merge(
$relatedIndexerIds,
[$relatedIndexerId],
$this->getRelatedIndexerIds($relatedIndexerId)
);
$relatedIndexerIds[] = [$relatedIndexerId];
$relatedIndexerIds[] = $this->getRelatedIndexerIds($relatedIndexerId);
}

return array_unique($relatedIndexerIds);
return array_unique(array_merge(...$relatedIndexerIds));
}

/**
Expand All @@ -177,21 +179,18 @@ private function getRelatedIndexerIds(string $indexerId)
* @param string $indexerId
* @return array
*/
private function getDependentIndexerIds(string $indexerId)
private function getDependentIndexerIds(string $indexerId): array
{
$dependentIndexerIds = [];
$dependentIndexerIds = [[]];
foreach (array_keys($this->getConfig()->getIndexers()) as $id) {
$dependencies = $this->getDependencyInfoProvider()->getIndexerIdsToRunBefore($id);
if (array_search($indexerId, $dependencies) !== false) {
$dependentIndexerIds = array_merge(
$dependentIndexerIds,
[$id],
$this->getDependentIndexerIds($id)
);
$dependentIndexerIds[] = [$id];
$dependentIndexerIds[] = $this->getDependentIndexerIds($id);
}
}

return array_unique($dependentIndexerIds);
return array_unique(array_merge(...$dependentIndexerIds));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
class IndexerReindexCommandTest extends AbstractIndexerCommandCommonSetup
{
const STUB_INDEXER_NAME = 'Indexer Name';
/**
* Command being tested
*
Expand Down Expand Up @@ -107,7 +108,7 @@ public function testExecuteAll()
[
$this->getIndexerMock(
['reindexAll', 'getStatus'],
['indexer_id' => 'id_indexerOne', 'title' => 'Title_indexerOne']
['indexer_id' => 'id_indexerOne', 'title' => self::STUB_INDEXER_NAME]
)
]
);
Expand All @@ -117,7 +118,10 @@ public function testExecuteAll()
$commandTester->execute([]);
$actualValue = $commandTester->getDisplay();
$this->assertSame(Cli::RETURN_SUCCESS, $commandTester->getStatusCode());
$this->assertStringStartsWith('Title_indexerOne index has been rebuilt successfully in', $actualValue);
$this->assertStringStartsWith(
self::STUB_INDEXER_NAME . ' index has been rebuilt successfully in',
$actualValue
);
}

/**
Expand Down Expand Up @@ -174,6 +178,7 @@ public function testExecuteWithIndex(
$this->objectManagerFactory,
$this->indexerRegistryMock
);

$commandTester = new CommandTester($this->command);
$commandTester->execute(['index' => $inputIndexers]);
$this->assertSame(Cli::RETURN_SUCCESS, $commandTester->getStatusCode());
Expand Down Expand Up @@ -344,7 +349,8 @@ public function executeWithIndexDataProvider()
],
'With dependencies and multiple indexers in request' => [
'inputIndexers' => [
'indexer_1', 'indexer_3'
'indexer_1',
'indexer_3'
],
'indexers' => [
'indexer_2' => [
Expand Down Expand Up @@ -405,7 +411,10 @@ public function executeWithIndexDataProvider()
public function testExecuteWithLocalizedException()
{
$this->configureAdminArea();
$indexerOne = $this->getIndexerMock(['reindexAll', 'getStatus'], ['indexer_id' => 'indexer_1']);
$indexerOne = $this->getIndexerMock(
['reindexAll', 'getStatus'],
['indexer_id' => 'indexer_1', 'title' => self::STUB_INDEXER_NAME]
);
$localizedException = new LocalizedException(new Phrase('Some Exception Message'));
$indexerOne->expects($this->once())->method('reindexAll')->will($this->throwException($localizedException));
$this->initIndexerCollectionByItems([$indexerOne]);
Expand All @@ -414,7 +423,10 @@ public function testExecuteWithLocalizedException()
$commandTester->execute(['index' => ['indexer_1']]);
$actualValue = $commandTester->getDisplay();
$this->assertSame(Cli::RETURN_FAILURE, $commandTester->getStatusCode());
$this->assertStringStartsWith('Some Exception Message', $actualValue);
$this->assertStringStartsWith(
self::STUB_INDEXER_NAME . ' index exception: Some Exception Message',
$actualValue
);
}

public function testExecuteWithException()
Expand All @@ -433,7 +445,7 @@ public function testExecuteWithException()
$commandTester->execute(['index' => ['indexer_1']]);
$actualValue = $commandTester->getDisplay();
$this->assertSame(Cli::RETURN_FAILURE, $commandTester->getStatusCode());
$this->assertStringStartsWith('Title_indexer_1' . ' indexer process unknown error:', $actualValue);
$this->assertStringStartsWith('Title_indexer_1' . ' index process unknown error:', $actualValue);
}

public function testExecuteWithExceptionInGetIndexers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ public function testTableSelection($period, $expectedTable, $dateFrom, $dateTo,
$this->assertArrayHasKey('tableName', $from[$dbTableName]);
} else {
$union = $this->_collection->getSelect()->getPart('union');
$count = count($union);
if ($period !== null && $dateFrom !== null && $dateTo !== null && $period != 'month') {
$count = count($union);
if ($period == 'year') {
if ($dbTableName == "report_viewed_product_aggregated_daily") {
$this->assertEquals($count, 2);
$this->assertEquals(2, $count);
}
if ($dbTableName == "report_viewed_product_aggregated_yearly") {
$this->assertEquals($count, 3);
$this->assertEquals(3, $count);
}
} else {
$this->assertEquals($count, 3);
$this->assertEquals(3, $count);
}
} else {
$this->assertEquals(count($union), 2);
$this->assertEquals(2, $count);
}
}
}
Expand All @@ -98,8 +98,8 @@ public function testTableSelection($period, $expectedTable, $dateFrom, $dateTo,
*/
public function tableForPeriodDataProvider()
{
$dateNow = date('Y-m-d', time());
$dateYearAgo = date('Y-m-d', strtotime($dateNow . ' -1 year'));
$dateFrom = '2019-10-15';
$dateYearBefore = date('Y-m-d', strtotime($dateFrom . ' -1 year'));
return [
[
'period' => 'year',
Expand All @@ -111,32 +111,32 @@ public function tableForPeriodDataProvider()
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_yearly',
'date_from' => $dateYearAgo,
'date_to' => $dateNow,
'date_from' => $dateYearBefore,
'date_to' => $dateFrom,
],
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_yearly',
'date_from' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => null,
],
[
'period' => 'month',
'table' => 'report_viewed_product_aggregated_monthly',
'date_from' => null,
'date_to' => $dateNow,
'date_to' => $dateFrom,
],
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_yearly',
'date_from' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => null,
],
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_yearly',
'date_from' => null,
'date_to' => $dateNow,
'date_to' => $dateFrom,
],
[
'period' => 'month',
Expand All @@ -147,19 +147,19 @@ public function tableForPeriodDataProvider()
[
'period' => 'month',
'table' => 'report_viewed_product_aggregated_monthly',
'date_from' => $dateYearAgo,
'date_to' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => $dateYearBefore,
],
[
'period' => 'month',
'table' => 'report_viewed_product_aggregated_monthly',
'date_from' => null,
'date_to' => $dateYearAgo,
'date_to' => $dateYearBefore,
],
[
'period' => 'month',
'table' => 'report_viewed_product_aggregated_monthly',
'date_from' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => null,
],
[
Expand All @@ -177,32 +177,32 @@ public function tableForPeriodDataProvider()
[
'period' => null,
'table' => 'report_viewed_product_aggregated_daily',
'date_from' => $dateYearAgo,
'date_to' => $dateNow,
'date_from' => $dateYearBefore,
'date_to' => $dateFrom,
],
[
'period' => null,
'table' => 'report_viewed_product_aggregated_daily',
'date_from' => $dateNow,
'date_to' => $dateNow,
'date_from' => $dateFrom,
'date_to' => $dateFrom,
],
[
'period' => 'day',
'table' => 'report_viewed_product_aggregated_daily',
'date_from' => $dateYearAgo,
'date_to' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => $dateYearBefore,
],
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_daily',
'date_from' => $dateYearAgo,
'date_to' => $dateYearAgo,
'date_from' => $dateYearBefore,
'date_to' => $dateYearBefore,
],
[
'period' => 'year',
'table' => 'report_viewed_product_aggregated_daily',
'date_from' => null,
'date_to' => $dateYearAgo,
'date_to' => $dateYearBefore,
],
[
'period' => null,
Expand Down