diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml
index 5da824d2ccdb9..981af5b5abb4a 100644
--- a/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml
+++ b/app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml
@@ -27,7 +27,7 @@
-
+
diff --git a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php
index fffa4503e14a7..c7207c853b95e 100644
--- a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php
+++ b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php
@@ -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
@@ -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'];
@@ -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;
}
@@ -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()) {
@@ -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));
}
/**
@@ -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));
}
/**
diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php
index bdfeff8a89eb9..3a1bf113b942a 100644
--- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php
+++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php
@@ -22,6 +22,7 @@
*/
class IndexerReindexCommandTest extends AbstractIndexerCommandCommonSetup
{
+ const STUB_INDEXER_NAME = 'Indexer Name';
/**
* Command being tested
*
@@ -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]
)
]
);
@@ -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
+ );
}
/**
@@ -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());
@@ -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' => [
@@ -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]);
@@ -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()
@@ -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()
diff --git a/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Report/Product/Viewed/CollectionTest.php b/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Report/Product/Viewed/CollectionTest.php
index fff057fd05688..18b6aa6405663 100644
--- a/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Report/Product/Viewed/CollectionTest.php
+++ b/dev/tests/integration/testsuite/Magento/Reports/Model/ResourceModel/Report/Product/Viewed/CollectionTest.php
@@ -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);
}
}
}
@@ -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',
@@ -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',
@@ -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,
],
[
@@ -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,