From 90215616b1d6c3679729dd5a92de5c245b2f15aa Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 5 Nov 2017 20:51:31 +0000 Subject: [PATCH 01/18] Add command to view mview state and queue This is similar to the magerun1 command here: https://github.com/netz98/n98-magerun/pull/891 I like the ability to view the mview queue in realtime as its being processed, it can be quite helpful when debugging indexing issues. This command will actually show how many items are in the list pending processing, as well information from the `mview_state` table. ``` php bin/magento indexer:status:mview +---------------------------+----------+--------+---------------------+------------+---------+ | ID | Mode | Status | Updated | Version ID | Backlog | +---------------------------+----------+--------+---------------------+------------+---------+ | catalog_category_product | enabled | idle | 2017-11-02 10:00:00 | 1 | 0 | | catalog_product_attribute | enabled | idle | 2017-11-02 10:00:00 | 1 | 1 | | catalog_product_category | disabled | idle | 2017-11-02 10:00:00 | 1 | 0 | | catalog_product_price | enabled | idle | 2017-11-02 10:00:00 | 1 | 0 | +---------------------------+----------+--------+---------------------+------------+---------+ ``` I'll point this PR into 2.1.x and raise a separate PR to pop it into 2.2.x. --- .../Command/IndexerStatusMviewCommand.php | 95 +++++++ .../Command/IndexerStatusMviewCommandTest.php | 233 ++++++++++++++++++ app/code/Magento/Indexer/etc/di.xml | 1 + 3 files changed, 329 insertions(+) create mode 100644 app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php create mode 100644 app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php new file mode 100644 index 0000000000000..4fb0c0bcb5649 --- /dev/null +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -0,0 +1,95 @@ +mviewIndexersCollection = $collection; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('indexer:status:mview') + ->setDescription('Shows status of Mview Indexers and their queue status'); + + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + try { + $table = $this->getHelperSet()->get('table'); + $table->setHeaders(['ID', 'Mode', 'Status', 'Updated', 'Version ID', 'Backlog']); + + $rows = []; + + /** @var \Magento\Framework\Mview\View $indexer */ + foreach ($this->mviewIndexersCollection as $indexer) { + $state = $indexer->getState(); + $changelog = $indexer->getChangelog(); + + try { + $currentVersionId = $changelog->getVersion(); + } catch (View\ChangelogTableNotExistsException $e) { + continue; + } + + $pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId)); + + $pendingString = "$pendingCount"; + if ($pendingCount <= 0) { + $pendingString = "$pendingCount"; + } + + $rows[] = [ + $indexer->getData('view_id'), + $state->getData('mode'), + $state->getData('status'), + $state->getData('updated'), + $state->getData('version_id'), + $pendingString, + ]; + } + + usort($rows, function($a, $b) { + return $a[0] <=> $b[0]; + }); + + $table->addRows($rows); + $table->render($output); + + return \Magento\Framework\Console\Cli::RETURN_SUCCESS; + } catch (\Exception $e) { + $output->writeln('' . $e->getMessage() . ''); + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { + $output->writeln($e->getTraceAsString()); + } + + return \Magento\Framework\Console\Cli::RETURN_FAILURE; + } + } +} diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php new file mode 100644 index 0000000000000..7266d009a5ee7 --- /dev/null +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -0,0 +1,233 @@ +objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + /** @var \Magento\Framework\Mview\View\Collection $collection */ + $this->collection = $this->objectManager->getObject(Mview\View\Collection::class); + + $reflectedCollection = new \ReflectionObject($this->collection); + $isLoadedProperty = $reflectedCollection->getProperty('_isCollectionLoaded'); + $isLoadedProperty->setAccessible(true); + $isLoadedProperty->setValue($this->collection, true); + + $this->command = $this->objectManager->getObject( + IndexerStatusMviewCommand::class, + ['collection' => $this->collection] + ); + + /** @var HelperSet $helperSet */ + $helperSet = $this->objectManager->getObject( + HelperSet::class, + ['helpers' => [$this->objectManager->getObject(TableHelper::class)]] + ); + + //Inject table helper for output + $this->command->setHelperSet($helperSet); + } + + public function testExecute() + { + $mviews = [ + [ + 'view' => [ + 'view_id' => 'catalog_category_product', + 'mode' => 'enabled', + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + 'version_id' => 100, + ], + 'changelog' => [ + 'version_id' => 110 + ], + ], + [ + 'view' => [ + 'view_id' => 'catalog_product_category', + 'mode' => 'disabled', + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + 'version_id' => 100, + ], + 'changelog' => [ + 'version_id' => 200 + ], + ], + [ + 'view' => [ + 'view_id' => 'catalog_product_attribute', + 'mode' => 'enabled', + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + 'version_id' => 100, + ], + 'changelog' => [ + 'version_id' => 100 + ], + ], + ]; + + foreach ($mviews as $data) { + $this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'])); + } + + /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ + $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) + ->disableOriginalConstructor() + ->getMock(); + + $changelog->expects($this->any()) + ->method('getVersion') + ->willThrowException( + new Mview\View\ChangelogTableNotExistsException(new \Magento\Framework\Phrase("Do not render")) + ); + + /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $notInitiatedMview */ + $notInitiatedMview = $this->getMockBuilder(\Magento\Framework\Mview\View::class) + ->disableOriginalConstructor() + ->getMock(); + + $notInitiatedMview->expects($this->any()) + ->method('getChangelog') + ->willReturn($changelog); + + $this->collection->addItem($notInitiatedMview); + + $tester = new CommandTester($this->command); + $this->assertEquals(Cli::RETURN_SUCCESS, $tester->execute([])); + + $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay())); + $this->assertCount(7, $linesOutput, 'There should be 7 lines output. 3 Spacers, 1 header, 3 content.'); + $this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 7 should be spacer lines"); + $this->assertEquals($linesOutput[2], $linesOutput[6], "Lines 0, 2, 6 should be spacer lines"); + + $headerValues = array_values(array_filter(explode('|', $linesOutput[1]))); + $this->assertEquals('ID', trim($headerValues[0])); + $this->assertEquals('Mode', trim($headerValues[1])); + $this->assertEquals('Status', trim($headerValues[2])); + $this->assertEquals('Updated', trim($headerValues[3])); + $this->assertEquals('Version ID', trim($headerValues[4])); + $this->assertEquals('Backlog', trim($headerValues[5])); + + $catalogCategoryProductMviewData = array_values(array_filter(explode('|', $linesOutput[3]))); + $this->assertEquals('catalog_category_product', trim($catalogCategoryProductMviewData[0])); + $this->assertEquals('enabled', trim($catalogCategoryProductMviewData[1])); + $this->assertEquals('idle', trim($catalogCategoryProductMviewData[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($catalogCategoryProductMviewData[3])); + $this->assertEquals('100', trim($catalogCategoryProductMviewData[4])); + $this->assertEquals('10', trim($catalogCategoryProductMviewData[5])); + unset($catalogCategoryProductMviewData); + + $catalogProductAttributeMviewData = array_values(array_filter(explode('|', $linesOutput[4]))); + $this->assertEquals('catalog_product_attribute', trim($catalogProductAttributeMviewData[0])); + $this->assertEquals('enabled', trim($catalogProductAttributeMviewData[1])); + $this->assertEquals('idle', trim($catalogProductAttributeMviewData[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($catalogProductAttributeMviewData[3])); + $this->assertEquals('100', trim($catalogProductAttributeMviewData[4])); + $this->assertEquals('0', trim($catalogProductAttributeMviewData[5])); + unset($catalogProductAttributeMviewData); + + $catalogCategoryProductMviewData = array_values(array_filter(explode('|', $linesOutput[5]))); + $this->assertEquals('catalog_product_category', trim($catalogCategoryProductMviewData[0])); + $this->assertEquals('disabled', trim($catalogCategoryProductMviewData[1])); + $this->assertEquals('idle', trim($catalogCategoryProductMviewData[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($catalogCategoryProductMviewData[3])); + $this->assertEquals('100', trim($catalogCategoryProductMviewData[4])); + $this->assertEquals('100', trim($catalogCategoryProductMviewData[5])); + unset($catalogCategoryProductMviewData); + } + + /** + * @param array $viewData + * @param array $changelogData + * @return Mview\View|Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject + */ + protected function generateMviewStub(array $viewData, array $changelogData) + { + /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ + $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) + ->disableOriginalConstructor() + ->getMock(); + + $list = []; + if ($changelogData['version_id'] !== $viewData['version_id']) { + $list = range($viewData['version_id']+1, $changelogData['version_id']); + } + + $changelog->expects($this->any()) + ->method('getList') + ->willReturn($list); + + $changelog->expects($this->any()) + ->method('getVersion') + ->willReturn($changelogData['version_id']); + + /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ + $stub = $this->getMockBuilder(\Magento\Framework\Mview\View::class) + ->disableOriginalConstructor() + ->setMethods(['getChangelog', 'getState']) + ->getMock(); + + $stub->expects($this->any()) + ->method('getChangelog') + ->willReturn($changelog); + + $stub->expects($this->any()) + ->method('getState') + ->willReturnSelf(); + + $stub->setData($viewData); + + return $stub; + } + + public function testExecuteExceptionNoVerbosity() + { + /** @var \Magento\Framework\Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ + $stub = $this->getMockBuilder(Mview\View::class) + ->disableOriginalConstructor() + ->getMock(); + + $stub->expects($this->any()) + ->method('getChangelog') + ->willThrowException(new \Exception("Dummy test exception")); + + $this->collection->addItem($stub); + + $tester = new CommandTester($this->command); + $this->assertEquals(Cli::RETURN_FAILURE, $tester->execute([])); + $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay())); + $this->assertEquals('Dummy test exception', $linesOutput[0]); + } +} diff --git a/app/code/Magento/Indexer/etc/di.xml b/app/code/Magento/Indexer/etc/di.xml index 610f08fac3a05..266cf72c50dbf 100644 --- a/app/code/Magento/Indexer/etc/di.xml +++ b/app/code/Magento/Indexer/etc/di.xml @@ -51,6 +51,7 @@ Magento\Indexer\Console\Command\IndexerSetModeCommand Magento\Indexer\Console\Command\IndexerShowModeCommand Magento\Indexer\Console\Command\IndexerStatusCommand + Magento\Indexer\Console\Command\IndexerStatusMviewCommand Magento\Indexer\Console\Command\IndexerResetStateCommand From 1e34fde22bf5ceba0ddedf425de9edfb9f50b3b0 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 5 Nov 2017 21:23:23 +0000 Subject: [PATCH 02/18] Make indexer status mview 5.5 compatible --- .../Command/IndexerStatusMviewCommand.php | 4 +- .../Command/IndexerStatusMviewCommandTest.php | 54 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index 4fb0c0bcb5649..61461a0ba610c 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -75,8 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output) ]; } - usort($rows, function($a, $b) { - return $a[0] <=> $b[0]; + usort($rows, function ($a, $b) { + return strcmp($a[0], $b[0]); }); $table->addRows($rows); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index 7266d009a5ee7..e6a782cba92fd 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -13,6 +13,9 @@ use Magento\Store\Model\Website; use Magento\Framework\Console\Cli; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class IndexerStatusMviewCommandTest extends \PHPUnit_Framework_TestCase { /** @@ -101,28 +104,7 @@ public function testExecute() foreach ($mviews as $data) { $this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'])); } - - /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ - $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) - ->disableOriginalConstructor() - ->getMock(); - - $changelog->expects($this->any()) - ->method('getVersion') - ->willThrowException( - new Mview\View\ChangelogTableNotExistsException(new \Magento\Framework\Phrase("Do not render")) - ); - - /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $notInitiatedMview */ - $notInitiatedMview = $this->getMockBuilder(\Magento\Framework\Mview\View::class) - ->disableOriginalConstructor() - ->getMock(); - - $notInitiatedMview->expects($this->any()) - ->method('getChangelog') - ->willReturn($changelog); - - $this->collection->addItem($notInitiatedMview); + $this->collection->addItem($this->getNeverEnabledMviewIndexerWithNoTable()); $tester = new CommandTester($this->command); $this->assertEquals(Cli::RETURN_SUCCESS, $tester->execute([])); @@ -212,6 +194,34 @@ protected function generateMviewStub(array $viewData, array $changelogData) return $stub; } + /** + * @return Mview\View|\PHPUnit_Framework_MockObject_MockObject + */ + protected function getNeverEnabledMviewIndexerWithNoTable() + { + /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ + $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) + ->disableOriginalConstructor() + ->getMock(); + + $changelog->expects($this->any()) + ->method('getVersion') + ->willThrowException( + new Mview\View\ChangelogTableNotExistsException(new \Magento\Framework\Phrase("Do not render")) + ); + + /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $notInitiatedMview */ + $notInitiatedMview = $this->getMockBuilder(\Magento\Framework\Mview\View::class) + ->disableOriginalConstructor() + ->getMock(); + + $notInitiatedMview->expects($this->any()) + ->method('getChangelog') + ->willReturn($changelog); + + return $notInitiatedMview; + } + public function testExecuteExceptionNoVerbosity() { /** @var \Magento\Framework\Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ From 6d3bffa4a4487c1ffd5b0e859c61aec13e10bbd4 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 6 Nov 2017 17:55:45 +0000 Subject: [PATCH 03/18] Use factories/interfaces correctly --- .../Command/IndexerStatusMviewCommand.php | 33 ++++++++++-------- .../Command/IndexerStatusMviewCommandTest.php | 34 +++++++++++++++---- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index 61461a0ba610c..cb60d4f31da7f 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -9,19 +9,22 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Command\Command; use Magento\Framework\Mview\View; +use Magento\Framework\Mview\View\CollectionFactory; +use Magento\Framework\Console\Cli; /** * Command for displaying status of mview indexers. */ class IndexerStatusMviewCommand extends Command { - /** @var \Magento\Framework\Mview\View\CollectionInterface $mviewIndexersCollection */ - private $mviewIndexersCollection; + /** @var \Magento\Framework\Mview\View\CollectionInterface $mviewCollection */ + private $mviewCollection; public function __construct( - \Magento\Framework\Mview\View\CollectionInterface $collection + CollectionFactory $collectionFactory ) { - $this->mviewIndexersCollection = $collection; + $this->mviewCollection = $collectionFactory->create(); + parent::__construct(); } @@ -47,10 +50,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $rows = []; - /** @var \Magento\Framework\Mview\View $indexer */ - foreach ($this->mviewIndexersCollection as $indexer) { - $state = $indexer->getState(); - $changelog = $indexer->getChangelog(); + /** @var \Magento\Framework\Mview\View $view */ + foreach ($this->mviewCollection as $view) { + $state = $view->getState(); + $changelog = $view->getChangelog(); try { $currentVersionId = $changelog->getVersion(); @@ -66,11 +69,11 @@ protected function execute(InputInterface $input, OutputInterface $output) } $rows[] = [ - $indexer->getData('view_id'), - $state->getData('mode'), - $state->getData('status'), - $state->getData('updated'), - $state->getData('version_id'), + $view->getId(), + $state->getMode(), + $state->getStatus(), + $state->getUpdated(), + $state->getVersionId(), $pendingString, ]; } @@ -82,14 +85,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $table->addRows($rows); $table->render($output); - return \Magento\Framework\Console\Cli::RETURN_SUCCESS; + return Cli::RETURN_SUCCESS; } catch (\Exception $e) { $output->writeln('' . $e->getMessage() . ''); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($e->getTraceAsString()); } - return \Magento\Framework\Console\Cli::RETURN_FAILURE; + return Cli::RETURN_FAILURE; } } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index e6a782cba92fd..43ffed3fd1e93 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Helper\TableHelper; use Magento\Store\Model\Website; use Magento\Framework\Console\Cli; +use Magento\Framework\Mview\View\CollectionFactory; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -45,9 +46,15 @@ protected function setUp() $isLoadedProperty->setAccessible(true); $isLoadedProperty->setValue($this->collection, true); + $collectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $collectionFactory->method('create') + ->willReturn($this->collection); + $this->command = $this->objectManager->getObject( IndexerStatusMviewCommand::class, - ['collection' => $this->collection] + ['collectionFactory' => $collectionFactory] ); /** @var HelperSet $helperSet */ @@ -66,6 +73,8 @@ public function testExecute() [ 'view' => [ 'view_id' => 'catalog_category_product', + ], + 'state' => [ 'mode' => 'enabled', 'status' => 'idle', 'updated' => '2017-01-01 11:11:11', @@ -78,6 +87,8 @@ public function testExecute() [ 'view' => [ 'view_id' => 'catalog_product_category', + ], + 'state' => [ 'mode' => 'disabled', 'status' => 'idle', 'updated' => '2017-01-01 11:11:11', @@ -90,6 +101,8 @@ public function testExecute() [ 'view' => [ 'view_id' => 'catalog_product_attribute', + ], + 'state' => [ 'mode' => 'enabled', 'status' => 'idle', 'updated' => '2017-01-01 11:11:11', @@ -102,7 +115,7 @@ public function testExecute() ]; foreach ($mviews as $data) { - $this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'])); + $this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'], $data['state'])); } $this->collection->addItem($this->getNeverEnabledMviewIndexerWithNoTable()); @@ -153,9 +166,10 @@ public function testExecute() /** * @param array $viewData * @param array $changelogData + * @param array $stateData * @return Mview\View|Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject */ - protected function generateMviewStub(array $viewData, array $changelogData) + protected function generateMviewStub(array $viewData, array $changelogData, array $stateData) { /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) @@ -163,8 +177,8 @@ protected function generateMviewStub(array $viewData, array $changelogData) ->getMock(); $list = []; - if ($changelogData['version_id'] !== $viewData['version_id']) { - $list = range($viewData['version_id']+1, $changelogData['version_id']); + if ($changelogData['version_id'] !== $stateData['version_id']) { + $list = range($stateData['version_id']+1, $changelogData['version_id']); } $changelog->expects($this->any()) @@ -175,6 +189,14 @@ protected function generateMviewStub(array $viewData, array $changelogData) ->method('getVersion') ->willReturn($changelogData['version_id']); + /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stub */ + $state = $this->getMockBuilder(\Magento\Indexer\Model\Mview\View\State::class) + ->disableOriginalConstructor() + ->setMethods(['loadByView']) + ->getMock(); + + $state->setData($stateData); + /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ $stub = $this->getMockBuilder(\Magento\Framework\Mview\View::class) ->disableOriginalConstructor() @@ -187,7 +209,7 @@ protected function generateMviewStub(array $viewData, array $changelogData) $stub->expects($this->any()) ->method('getState') - ->willReturnSelf(); + ->willReturn($state); $stub->setData($viewData); From dede2d1f42f64875e63d5a410f0934781be9414c Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 7 Nov 2017 17:32:41 +0000 Subject: [PATCH 04/18] Update code style --- .../Command/IndexerStatusMviewCommand.php | 4 +- .../Command/IndexerStatusMviewCommandTest.php | 52 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index cb60d4f31da7f..5451df34645e9 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -78,8 +78,8 @@ protected function execute(InputInterface $input, OutputInterface $output) ]; } - usort($rows, function ($a, $b) { - return strcmp($a[0], $b[0]); + usort($rows, function ($comp1, $comp2) { + return strcmp($comp1[0], $comp2[0]); }); $table->addRows($rows); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index 43ffed3fd1e93..b58596be70c48 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -135,32 +135,32 @@ public function testExecute() $this->assertEquals('Version ID', trim($headerValues[4])); $this->assertEquals('Backlog', trim($headerValues[5])); - $catalogCategoryProductMviewData = array_values(array_filter(explode('|', $linesOutput[3]))); - $this->assertEquals('catalog_category_product', trim($catalogCategoryProductMviewData[0])); - $this->assertEquals('enabled', trim($catalogCategoryProductMviewData[1])); - $this->assertEquals('idle', trim($catalogCategoryProductMviewData[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($catalogCategoryProductMviewData[3])); - $this->assertEquals('100', trim($catalogCategoryProductMviewData[4])); - $this->assertEquals('10', trim($catalogCategoryProductMviewData[5])); - unset($catalogCategoryProductMviewData); - - $catalogProductAttributeMviewData = array_values(array_filter(explode('|', $linesOutput[4]))); - $this->assertEquals('catalog_product_attribute', trim($catalogProductAttributeMviewData[0])); - $this->assertEquals('enabled', trim($catalogProductAttributeMviewData[1])); - $this->assertEquals('idle', trim($catalogProductAttributeMviewData[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($catalogProductAttributeMviewData[3])); - $this->assertEquals('100', trim($catalogProductAttributeMviewData[4])); - $this->assertEquals('0', trim($catalogProductAttributeMviewData[5])); - unset($catalogProductAttributeMviewData); - - $catalogCategoryProductMviewData = array_values(array_filter(explode('|', $linesOutput[5]))); - $this->assertEquals('catalog_product_category', trim($catalogCategoryProductMviewData[0])); - $this->assertEquals('disabled', trim($catalogCategoryProductMviewData[1])); - $this->assertEquals('idle', trim($catalogCategoryProductMviewData[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($catalogCategoryProductMviewData[3])); - $this->assertEquals('100', trim($catalogCategoryProductMviewData[4])); - $this->assertEquals('100', trim($catalogCategoryProductMviewData[5])); - unset($catalogCategoryProductMviewData); + $categoryProduct = array_values(array_filter(explode('|', $linesOutput[3]))); + $this->assertEquals('catalog_category_product', trim($categoryProduct[0])); + $this->assertEquals('enabled', trim($categoryProduct[1])); + $this->assertEquals('idle', trim($categoryProduct[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($categoryProduct[3])); + $this->assertEquals('100', trim($categoryProduct[4])); + $this->assertEquals('10', trim($categoryProduct[5])); + unset($categoryProduct); + + $productAttribute = array_values(array_filter(explode('|', $linesOutput[4]))); + $this->assertEquals('catalog_product_attribute', trim($productAttribute[0])); + $this->assertEquals('enabled', trim($productAttribute[1])); + $this->assertEquals('idle', trim($productAttribute[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($productAttribute[3])); + $this->assertEquals('100', trim($productAttribute[4])); + $this->assertEquals('0', trim($productAttribute[5])); + unset($productAttribute); + + $productCategory = array_values(array_filter(explode('|', $linesOutput[5]))); + $this->assertEquals('catalog_product_category', trim($productCategory[0])); + $this->assertEquals('disabled', trim($productCategory[1])); + $this->assertEquals('idle', trim($productCategory[2])); + $this->assertEquals('2017-01-01 11:11:11', trim($productCategory[3])); + $this->assertEquals('100', trim($productCategory[4])); + $this->assertEquals('100', trim($productCategory[5])); + unset($productCategory); } /** From fa1b31087f22f5a4f593bb3ee18a154c71fc8965 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Wed, 8 Nov 2017 20:45:21 +0000 Subject: [PATCH 05/18] Remove the copyright year from file headers --- .../Indexer/Console/Command/IndexerStatusMviewCommand.php | 2 +- .../Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index 5451df34645e9..0efeef4a71be5 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -1,6 +1,6 @@ Date: Sat, 11 Nov 2017 12:58:43 +0000 Subject: [PATCH 06/18] Fix extends phpunit class --- .../Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index 6a2f215144f0d..292adb55c5533 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -17,7 +17,7 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class IndexerStatusMviewCommandTest extends \PHPUnit_Framework_TestCase +class IndexerStatusMviewCommandTest extends \PHPUnit\Framework\TestCase { /** * @var IndexerStatusMviewCommand From c80710a023a1ff6ca3c13f2cc3ba2a867e482638 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sat, 11 Nov 2017 13:03:32 +0000 Subject: [PATCH 07/18] Add mview getListSize command --- .../Command/IndexerStatusMviewCommand.php | 2 +- .../Command/IndexerStatusMviewCommandTest.php | 9 ++--- .../Framework/Mview/View/Changelog.php | 36 ++++++++++++++++--- .../Mview/View/ChangelogInterface.php | 9 +++++ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index 0efeef4a71be5..37caabc613e66 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) continue; } - $pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId)); + $pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId); $pendingString = "$pendingCount"; if ($pendingCount <= 0) { diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index 292adb55c5533..4ae3ca83870e7 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -176,14 +176,11 @@ protected function generateMviewStub(array $viewData, array $changelogData, arra ->disableOriginalConstructor() ->getMock(); - $list = []; - if ($changelogData['version_id'] !== $stateData['version_id']) { - $list = range($stateData['version_id']+1, $changelogData['version_id']); - } + $listSize = $changelogData['version_id'] - $stateData['version_id']; $changelog->expects($this->any()) - ->method('getList') - ->willReturn($list); + ->method('getListSize') + ->willReturn($listSize); $changelog->expects($this->any()) ->method('getVersion') diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 91caf66228360..4f648d6b7d6ae 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -127,14 +127,12 @@ public function clear($versionId) } /** - * Retrieve entity ids by range [$fromVersionId..$toVersionId] - * * @param int $fromVersionId * @param int $toVersionId - * @return int[] + * @return \Magento\Framework\DB\Select * @throws ChangelogTableNotExistsException */ - public function getList($fromVersionId, $toVersionId) + protected function getListSelect($fromVersionId, $toVersionId) { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { @@ -154,9 +152,39 @@ public function getList($fromVersionId, $toVersionId) (int)$toVersionId ); + return $select; + } + + /** + * Retrieve entity ids by range [$fromVersionId..$toVersionId] + * + * @param int $fromVersionId + * @param int $toVersionId + * @return int[] + * @throws ChangelogTableNotExistsException + */ + public function getList($fromVersionId, $toVersionId) + { + $select = $this->getListSelect($fromVersionId, $toVersionId); return $this->connection->fetchCol($select); } + /** + * Retrieve the count of entity ids in the range [$fromVersionId..$toVersionId] + * + * @param int $fromVersionId + * @param int $toVersionId + * @return int[] + * @throws ChangelogTableNotExistsException + */ + public function getListSize($fromVersionId, $toVersionId) + { + $countSelect = $this->getListSelect($fromVersionId, $toVersionId); + $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS); + $countSelect->columns(new \Zend_Db_Expr(("COUNT(DISTINCT " . $this->getColumnName() . ")"))); + return $this->connection->fetchOne($countSelect); + } + /** * Get maximum version_id from changelog * @return int diff --git a/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php b/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php index b00c1ca3a2e33..da115ecdb83ee 100644 --- a/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php +++ b/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php @@ -42,6 +42,15 @@ public function clear($versionId); */ public function getList($fromVersionId, $toVersionId); + /** + * Retrieve the count of entity ids in the range [$fromVersionId..$toVersionId] + * + * @param $fromVersionId + * @param $toVersionId + * @return mixed + */ + public function getListSize($fromVersionId, $toVersionId); + /** * Get maximum version_id from changelog * From 63ec3f762bc64680fb4cd52169c453711defc06d Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 12:21:01 +0000 Subject: [PATCH 08/18] Remove indexer:status:mview command --- .../Command/IndexerStatusMviewCommand.php | 98 ------- .../Command/IndexerStatusMviewCommandTest.php | 262 ------------------ 2 files changed, 360 deletions(-) delete mode 100644 app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php delete mode 100644 app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php deleted file mode 100644 index 37caabc613e66..0000000000000 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ /dev/null @@ -1,98 +0,0 @@ -mviewCollection = $collectionFactory->create(); - - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this->setName('indexer:status:mview') - ->setDescription('Shows status of Mview Indexers and their queue status'); - - parent::configure(); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - try { - $table = $this->getHelperSet()->get('table'); - $table->setHeaders(['ID', 'Mode', 'Status', 'Updated', 'Version ID', 'Backlog']); - - $rows = []; - - /** @var \Magento\Framework\Mview\View $view */ - foreach ($this->mviewCollection as $view) { - $state = $view->getState(); - $changelog = $view->getChangelog(); - - try { - $currentVersionId = $changelog->getVersion(); - } catch (View\ChangelogTableNotExistsException $e) { - continue; - } - - $pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId); - - $pendingString = "$pendingCount"; - if ($pendingCount <= 0) { - $pendingString = "$pendingCount"; - } - - $rows[] = [ - $view->getId(), - $state->getMode(), - $state->getStatus(), - $state->getUpdated(), - $state->getVersionId(), - $pendingString, - ]; - } - - usort($rows, function ($comp1, $comp2) { - return strcmp($comp1[0], $comp2[0]); - }); - - $table->addRows($rows); - $table->render($output); - - return Cli::RETURN_SUCCESS; - } catch (\Exception $e) { - $output->writeln('' . $e->getMessage() . ''); - if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { - $output->writeln($e->getTraceAsString()); - } - - return Cli::RETURN_FAILURE; - } - } -} diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php deleted file mode 100644 index 4ae3ca83870e7..0000000000000 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ /dev/null @@ -1,262 +0,0 @@ -objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - /** @var \Magento\Framework\Mview\View\Collection $collection */ - $this->collection = $this->objectManager->getObject(Mview\View\Collection::class); - - $reflectedCollection = new \ReflectionObject($this->collection); - $isLoadedProperty = $reflectedCollection->getProperty('_isCollectionLoaded'); - $isLoadedProperty->setAccessible(true); - $isLoadedProperty->setValue($this->collection, true); - - $collectionFactory = $this->getMockBuilder(CollectionFactory::class) - ->disableOriginalConstructor() - ->getMock(); - $collectionFactory->method('create') - ->willReturn($this->collection); - - $this->command = $this->objectManager->getObject( - IndexerStatusMviewCommand::class, - ['collectionFactory' => $collectionFactory] - ); - - /** @var HelperSet $helperSet */ - $helperSet = $this->objectManager->getObject( - HelperSet::class, - ['helpers' => [$this->objectManager->getObject(TableHelper::class)]] - ); - - //Inject table helper for output - $this->command->setHelperSet($helperSet); - } - - public function testExecute() - { - $mviews = [ - [ - 'view' => [ - 'view_id' => 'catalog_category_product', - ], - 'state' => [ - 'mode' => 'enabled', - 'status' => 'idle', - 'updated' => '2017-01-01 11:11:11', - 'version_id' => 100, - ], - 'changelog' => [ - 'version_id' => 110 - ], - ], - [ - 'view' => [ - 'view_id' => 'catalog_product_category', - ], - 'state' => [ - 'mode' => 'disabled', - 'status' => 'idle', - 'updated' => '2017-01-01 11:11:11', - 'version_id' => 100, - ], - 'changelog' => [ - 'version_id' => 200 - ], - ], - [ - 'view' => [ - 'view_id' => 'catalog_product_attribute', - ], - 'state' => [ - 'mode' => 'enabled', - 'status' => 'idle', - 'updated' => '2017-01-01 11:11:11', - 'version_id' => 100, - ], - 'changelog' => [ - 'version_id' => 100 - ], - ], - ]; - - foreach ($mviews as $data) { - $this->collection->addItem($this->generateMviewStub($data['view'], $data['changelog'], $data['state'])); - } - $this->collection->addItem($this->getNeverEnabledMviewIndexerWithNoTable()); - - $tester = new CommandTester($this->command); - $this->assertEquals(Cli::RETURN_SUCCESS, $tester->execute([])); - - $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay())); - $this->assertCount(7, $linesOutput, 'There should be 7 lines output. 3 Spacers, 1 header, 3 content.'); - $this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 7 should be spacer lines"); - $this->assertEquals($linesOutput[2], $linesOutput[6], "Lines 0, 2, 6 should be spacer lines"); - - $headerValues = array_values(array_filter(explode('|', $linesOutput[1]))); - $this->assertEquals('ID', trim($headerValues[0])); - $this->assertEquals('Mode', trim($headerValues[1])); - $this->assertEquals('Status', trim($headerValues[2])); - $this->assertEquals('Updated', trim($headerValues[3])); - $this->assertEquals('Version ID', trim($headerValues[4])); - $this->assertEquals('Backlog', trim($headerValues[5])); - - $categoryProduct = array_values(array_filter(explode('|', $linesOutput[3]))); - $this->assertEquals('catalog_category_product', trim($categoryProduct[0])); - $this->assertEquals('enabled', trim($categoryProduct[1])); - $this->assertEquals('idle', trim($categoryProduct[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($categoryProduct[3])); - $this->assertEquals('100', trim($categoryProduct[4])); - $this->assertEquals('10', trim($categoryProduct[5])); - unset($categoryProduct); - - $productAttribute = array_values(array_filter(explode('|', $linesOutput[4]))); - $this->assertEquals('catalog_product_attribute', trim($productAttribute[0])); - $this->assertEquals('enabled', trim($productAttribute[1])); - $this->assertEquals('idle', trim($productAttribute[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($productAttribute[3])); - $this->assertEquals('100', trim($productAttribute[4])); - $this->assertEquals('0', trim($productAttribute[5])); - unset($productAttribute); - - $productCategory = array_values(array_filter(explode('|', $linesOutput[5]))); - $this->assertEquals('catalog_product_category', trim($productCategory[0])); - $this->assertEquals('disabled', trim($productCategory[1])); - $this->assertEquals('idle', trim($productCategory[2])); - $this->assertEquals('2017-01-01 11:11:11', trim($productCategory[3])); - $this->assertEquals('100', trim($productCategory[4])); - $this->assertEquals('100', trim($productCategory[5])); - unset($productCategory); - } - - /** - * @param array $viewData - * @param array $changelogData - * @param array $stateData - * @return Mview\View|Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject - */ - protected function generateMviewStub(array $viewData, array $changelogData, array $stateData) - { - /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ - $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) - ->disableOriginalConstructor() - ->getMock(); - - $listSize = $changelogData['version_id'] - $stateData['version_id']; - - $changelog->expects($this->any()) - ->method('getListSize') - ->willReturn($listSize); - - $changelog->expects($this->any()) - ->method('getVersion') - ->willReturn($changelogData['version_id']); - - /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stub */ - $state = $this->getMockBuilder(\Magento\Indexer\Model\Mview\View\State::class) - ->disableOriginalConstructor() - ->setMethods(['loadByView']) - ->getMock(); - - $state->setData($stateData); - - /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ - $stub = $this->getMockBuilder(\Magento\Framework\Mview\View::class) - ->disableOriginalConstructor() - ->setMethods(['getChangelog', 'getState']) - ->getMock(); - - $stub->expects($this->any()) - ->method('getChangelog') - ->willReturn($changelog); - - $stub->expects($this->any()) - ->method('getState') - ->willReturn($state); - - $stub->setData($viewData); - - return $stub; - } - - /** - * @return Mview\View|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getNeverEnabledMviewIndexerWithNoTable() - { - /** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ - $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) - ->disableOriginalConstructor() - ->getMock(); - - $changelog->expects($this->any()) - ->method('getVersion') - ->willThrowException( - new Mview\View\ChangelogTableNotExistsException(new \Magento\Framework\Phrase("Do not render")) - ); - - /** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $notInitiatedMview */ - $notInitiatedMview = $this->getMockBuilder(\Magento\Framework\Mview\View::class) - ->disableOriginalConstructor() - ->getMock(); - - $notInitiatedMview->expects($this->any()) - ->method('getChangelog') - ->willReturn($changelog); - - return $notInitiatedMview; - } - - public function testExecuteExceptionNoVerbosity() - { - /** @var \Magento\Framework\Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */ - $stub = $this->getMockBuilder(Mview\View::class) - ->disableOriginalConstructor() - ->getMock(); - - $stub->expects($this->any()) - ->method('getChangelog') - ->willThrowException(new \Exception("Dummy test exception")); - - $this->collection->addItem($stub); - - $tester = new CommandTester($this->command); - $this->assertEquals(Cli::RETURN_FAILURE, $tester->execute([])); - $linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay())); - $this->assertEquals('Dummy test exception', $linesOutput[0]); - } -} From d3d300b33430353946f3373a4d64cac578715010 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 12:21:58 +0000 Subject: [PATCH 09/18] Update indexer:status to display schedule backlog --- .../Console/Command/IndexerStatusCommand.php | 89 +++++++-- .../Command/IndexerStatusCommandTest.php | 177 ++++++++++++++++-- 2 files changed, 234 insertions(+), 32 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 6590f6e0af99d..2d9c4bd3ccb28 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -7,6 +7,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Magento\Framework\Indexer; +use Magento\Framework\Mview; /** * Command for displaying status of indexers. @@ -30,21 +32,84 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $table = $this->getHelperSet()->get('table'); + $table->setHeaders(['Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']); + + $rows = []; + $indexers = $this->getIndexers($input); foreach ($indexers as $indexer) { - $status = 'unknown'; - switch ($indexer->getStatus()) { - case \Magento\Framework\Indexer\StateInterface::STATUS_VALID: - $status = 'Ready'; - break; - case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID: - $status = 'Reindex required'; - break; - case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING: - $status = 'Processing'; - break; + $view = $indexer->getView(); + + $rowData = [ + 'Title' => $indexer->getTitle(), + 'Status' => $this->getStatus($indexer), + 'Update On' => $indexer->isScheduled() ? 'Schedule' : 'Save', + 'Schedule Status' => '', + 'Updated' => '', + ]; + + if ($indexer->isScheduled()) { + $state = $view->getState(); + $rowData['Schedule Status'] = "{$state->getStatus()} ({$this->getPendingCount($view)} in backlog)"; + $rowData['Updated'] = $state->getUpdated(); } - $output->writeln(sprintf('%-50s ', $indexer->getTitle() . ':') . $status); + + $rows[] = $rowData; + } + + usort($rows, function ($comp1, $comp2) { + return strcmp($comp1['Title'], $comp2['Title']); + }); + + $table->addRows($rows); + $table->render($output); + } + + /** + * @param Indexer\IndexerInterface $indexer + * @return string + */ + protected function getStatus(Indexer\IndexerInterface $indexer) + { + $status = 'unknown'; + switch ($indexer->getStatus()) { + case \Magento\Framework\Indexer\StateInterface::STATUS_VALID: + $status = 'Ready'; + break; + case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID: + $status = 'Reindex required'; + break; + case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING: + $status = 'Processing'; + break; } + return $status; + } + + /** + * @param Mview\ViewInterface $view + * @return string + */ + protected function getPendingCount(Mview\ViewInterface $view) + { + $changelog = $view->getChangelog(); + + try { + $currentVersionId = $changelog->getVersion(); + } catch (Mview\View\ChangelogTableNotExistsException $e) { + return ''; + } + + $state = $view->getState(); + + $pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId); + + $pendingString = "$pendingCount"; + if ($pendingCount <= 0) { + $pendingString = "$pendingCount"; + } + + return $pendingString; } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 6eb7f7562b9cc..58a0a5b750709 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -8,6 +8,8 @@ use Magento\Framework\Indexer\StateInterface; use Magento\Indexer\Console\Command\IndexerStatusCommand; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Helper\TableHelper; class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup { @@ -18,35 +20,132 @@ class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup */ private $command; + /** + * @param \PHPUnit_Framework_MockObject_MockObject $indexerMock + * @param array $data + * @return mixed + */ + protected function attachViewToIndexerMock($indexerMock, array $data) + { + /** @var \Magento\Framework\Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ + $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) + ->disableOriginalConstructor() + ->getMock(); + + $changelog->expects($this->any()) + ->method('getListSize') + ->willReturn($data['view']['changelog']['list_size']); + + /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stateMock */ + $stateMock = $this->getMockBuilder(\Magento\Indexer\Model\Mview\View\State::class) + ->disableOriginalConstructor() + ->setMethods(null) + ->getMock(); + + $stateMock->addData($data['view']['state']); + + /** @var \Magento\Framework\Mview\View|\PHPUnit_Framework_MockObject_MockObject $viewMock */ + $viewMock = $this->getMockBuilder(\Magento\Framework\Mview\View::class) + ->disableOriginalConstructor() + ->setMethods(['getChangelog', 'getState']) + ->getMock(); + + $viewMock->expects($this->any()) + ->method('getState') + ->willReturn($stateMock); + $viewMock->expects($this->any()) + ->method('getChangelog') + ->willReturn($changelog); + + $indexerMock->method('getView') + ->willReturn($viewMock); + + return $indexerMock; + } + /** * @param array $indexers - * @param array $statuses + * * @dataProvider executeAllDataProvider */ - public function testExecuteAll(array $indexers, array $statuses) + public function testExecuteAll(array $indexers) { $this->configureAdminArea(); $indexerMocks = []; foreach ($indexers as $indexerData) { $indexerMock = $this->getIndexerMock( - ['getStatus'], + ['getStatus', 'isScheduled', 'getState', 'getView'], $indexerData ); + $indexerMock->method('getStatus') - ->willReturn($statuses[$indexerData['indexer_id']]); + ->willReturn($indexerData['status']); + $indexerMock->method('isScheduled') + ->willReturn($indexerData['is_scheduled']); + + if ($indexerData['is_scheduled']) { + $this->attachViewToIndexerMock($indexerMock, $indexerData); + } + $indexerMocks[] = $indexerMock; + } $this->initIndexerCollectionByItems($indexerMocks); $this->command = new IndexerStatusCommand($this->objectManagerFactory); + + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->command->setHelperSet( + $objectManager->getObject( + HelperSet::class, + ['helpers' => [$objectManager->getObject(TableHelper::class)]] + ) + ); + + $commandTester = new CommandTester($this->command); $commandTester->execute([]); - $actualValue = $commandTester->getDisplay(); - $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Ready' . PHP_EOL - . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Reindex required' . PHP_EOL - . sprintf('%-50s ', 'Title_indexerThree' . ':') . 'Processing' . PHP_EOL - . sprintf('%-50s ', 'Title_indexerFour' . ':') . 'unknown' . PHP_EOL; - $this->assertStringStartsWith($expectedValue, $actualValue); + $linesOutput = array_filter(explode(PHP_EOL, $commandTester->getDisplay())); + + $this->assertCount(8, $linesOutput, 'There should be 8 lines output. 3 Spacers, 1 header, 4 content.'); + $this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 7 should be spacer lines"); + $this->assertEquals($linesOutput[2], $linesOutput[7], "Lines 0, 2, 6 should be spacer lines"); + + $headerValues = array_values(array_filter(explode('|', $linesOutput[1]))); + $this->assertEquals('Title', trim($headerValues[0])); + $this->assertEquals('Status', trim($headerValues[1])); + $this->assertEquals('Update On', trim($headerValues[2])); + $this->assertEquals('Schedule Status', trim($headerValues[3])); + $this->assertEquals('Schedule Updated', trim($headerValues[4])); + + $indexer1 = array_values(array_filter(explode('|', $linesOutput[3]))); + $this->assertEquals('Title_indexer1', trim($indexer1[0])); + $this->assertEquals('Ready', trim($indexer1[1])); + $this->assertEquals('Schedule', trim($indexer1[2])); + $this->assertEquals('idle (10 in backlog)', trim($indexer1[3])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer1[4])); + + $indexer2 = array_values(array_filter(explode('|', $linesOutput[4]))); + $this->assertEquals('Title_indexer2', trim($indexer2[0])); + $this->assertEquals('Reindex required', trim($indexer2[1])); + $this->assertEquals('Save', trim($indexer2[2])); + $this->assertEquals('', trim($indexer2[3])); + $this->assertEquals('', trim($indexer2[4])); + + $indexer3 = array_values(array_filter(explode('|', $linesOutput[5]))); + $this->assertEquals('Title_indexer3', trim($indexer3[0])); + $this->assertEquals('Processing', trim($indexer3[1])); + $this->assertEquals('Schedule', trim($indexer3[2])); + $this->assertEquals('idle (100 in backlog)', trim($indexer3[3])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer3[4])); + + $indexer4 = array_values(array_filter(explode('|', $linesOutput[6]))); + $this->assertEquals('Title_indexer4', trim($indexer4[0])); + $this->assertEquals('unknown', trim($indexer4[1])); + $this->assertEquals('Schedule', trim($indexer4[2])); + $this->assertEquals('running (20 in backlog)', trim($indexer4[3])); + $this->assertEquals('2017-01-01 11:11:11', trim($indexer4[4])); } /** @@ -59,27 +158,65 @@ public function executeAllDataProvider() 'indexers' => [ 'indexer_1' => [ 'indexer_id' => 'indexer_1', - 'title' => 'Title_indexerOne' + 'title' => 'Title_indexer1', + 'status' => StateInterface::STATUS_VALID, + 'is_scheduled' => true, + 'view' => [ + 'state' => [ + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + ], + 'changelog' => [ + 'list_size' => 10 + ] + ] ], 'indexer_2' => [ 'indexer_id' => 'indexer_2', - 'title' => 'Title_indexerTwo' + 'title' => 'Title_indexer2', + 'status' => StateInterface::STATUS_INVALID, + 'is_scheduled' => false, + 'view' => [ + 'state' => [ + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + ], + 'changelog' => [ + 'list_size' => 99999999 + ] + ] ], 'indexer_3' => [ 'indexer_id' => 'indexer_3', - 'title' => 'Title_indexerThree' + 'title' => 'Title_indexer3', + 'status' => StateInterface::STATUS_WORKING, + 'is_scheduled' => true, + 'view' => [ + 'state' => [ + 'status' => 'idle', + 'updated' => '2017-01-01 11:11:11', + ], + 'changelog' => [ + 'list_size' => 100 + ] + ] ], 'indexer_4' => [ 'indexer_id' => 'indexer_4', - 'title' => 'Title_indexerFour' + 'title' => 'Title_indexer4', + 'status' => null, + 'is_scheduled' => true, + 'view' => [ + 'state' => [ + 'status' => 'running', + 'updated' => '2017-01-01 11:11:11', + ], + 'changelog' => [ + 'list_size' => 20 + ] + ] ], ], - 'Statuses' => [ - 'indexer_1' => StateInterface::STATUS_VALID, - 'indexer_2' => StateInterface::STATUS_INVALID, - 'indexer_3' => StateInterface::STATUS_WORKING, - 'indexer_4' => null, - ] ], ]; } From c63330fad61b636b213db99cb7aaf619ec46bfd2 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 12:23:43 +0000 Subject: [PATCH 10/18] Remove status-mview from di.xml --- app/code/Magento/Indexer/etc/di.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Indexer/etc/di.xml b/app/code/Magento/Indexer/etc/di.xml index 266cf72c50dbf..610f08fac3a05 100644 --- a/app/code/Magento/Indexer/etc/di.xml +++ b/app/code/Magento/Indexer/etc/di.xml @@ -51,7 +51,6 @@ Magento\Indexer\Console\Command\IndexerSetModeCommand Magento\Indexer\Console\Command\IndexerShowModeCommand Magento\Indexer\Console\Command\IndexerStatusCommand - Magento\Indexer\Console\Command\IndexerStatusMviewCommand Magento\Indexer\Console\Command\IndexerResetStateCommand From 709f88a712652a8f0a70893cde610d5fe6abb3e8 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 17:54:07 +0000 Subject: [PATCH 11/18] Update method visibility --- .../Magento/Indexer/Console/Command/IndexerStatusCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 2d9c4bd3ccb28..f5237ea5d023b 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output) * @param Indexer\IndexerInterface $indexer * @return string */ - protected function getStatus(Indexer\IndexerInterface $indexer) + private function getStatus(Indexer\IndexerInterface $indexer) { $status = 'unknown'; switch ($indexer->getStatus()) { @@ -91,7 +91,7 @@ protected function getStatus(Indexer\IndexerInterface $indexer) * @param Mview\ViewInterface $view * @return string */ - protected function getPendingCount(Mview\ViewInterface $view) + private function getPendingCount(Mview\ViewInterface $view) { $changelog = $view->getChangelog(); From 831000b9263c1e11829fe0acf1769077f5205aab Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 17:54:36 +0000 Subject: [PATCH 12/18] Correctly assert table output --- .../Test/Unit/Console/Command/IndexerStatusCommandTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 58a0a5b750709..27c18b1f9350d 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -108,9 +108,12 @@ public function testExecuteAll(array $indexers) $linesOutput = array_filter(explode(PHP_EOL, $commandTester->getDisplay())); + $spacer = '+----------------+------------------+-----------+-------------------------+---------------------+'; + $this->assertCount(8, $linesOutput, 'There should be 8 lines output. 3 Spacers, 1 header, 4 content.'); - $this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 7 should be spacer lines"); - $this->assertEquals($linesOutput[2], $linesOutput[7], "Lines 0, 2, 6 should be spacer lines"); + $this->assertEquals($linesOutput[0], $spacer, "Lines 0, 2, 7 should be spacer lines"); + $this->assertEquals($linesOutput[2], $spacer, "Lines 0, 2, 7 should be spacer lines"); + $this->assertEquals($linesOutput[7], $spacer, "Lines 0, 2, 7 should be spacer lines"); $headerValues = array_values(array_filter(explode('|', $linesOutput[1]))); $this->assertEquals('Title', trim($headerValues[0])); From 62e67e1a654708bdb553b6489fb4199636575e9d Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 17:55:58 +0000 Subject: [PATCH 13/18] Code style fixes --- .../Test/Unit/Console/Command/IndexerStatusCommandTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 27c18b1f9350d..1a4894faf4a91 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -88,8 +88,8 @@ public function testExecuteAll(array $indexers) } $indexerMocks[] = $indexerMock; - } + $this->initIndexerCollectionByItems($indexerMocks); $this->command = new IndexerStatusCommand($this->objectManagerFactory); @@ -101,8 +101,7 @@ public function testExecuteAll(array $indexers) ['helpers' => [$objectManager->getObject(TableHelper::class)]] ) ); - - + $commandTester = new CommandTester($this->command); $commandTester->execute([]); From 4af04b1c43ea8b1198ba5027500552c88a09737c Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sun, 3 Dec 2017 17:57:34 +0000 Subject: [PATCH 14/18] Add ChangelogCounterInterface --- .../Framework/Mview/View/Changelog.php | 4 ++-- .../Mview/View/ChangelogCounterInterface.php | 22 +++++++++++++++++++ .../Mview/View/ChangelogInterface.php | 9 -------- 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 4f648d6b7d6ae..6d75ee27be14a 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -8,7 +8,7 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Phrase; -class Changelog implements ChangelogInterface +class Changelog implements ChangelogInterface, ChangelogCounterInterface { /** * Suffix for changelog table @@ -132,7 +132,7 @@ public function clear($versionId) * @return \Magento\Framework\DB\Select * @throws ChangelogTableNotExistsException */ - protected function getListSelect($fromVersionId, $toVersionId) + private function getListSelect($fromVersionId, $toVersionId) { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { diff --git a/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php b/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php new file mode 100644 index 0000000000000..5d92ad1c3de79 --- /dev/null +++ b/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php @@ -0,0 +1,22 @@ + Date: Mon, 4 Dec 2017 09:19:14 +0200 Subject: [PATCH 15/18] Add command to view mview state and queue Use private method visibility instead of protected in test --- .../Test/Unit/Console/Command/IndexerStatusCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 1a4894faf4a91..45b3ec3471b09 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -25,7 +25,7 @@ class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup * @param array $data * @return mixed */ - protected function attachViewToIndexerMock($indexerMock, array $data) + private function attachViewToIndexerMock($indexerMock, array $data) { /** @var \Magento\Framework\Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) From ca50c9d411090af4e4f554d16325e8469a83930a Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 4 Dec 2017 19:06:22 +0000 Subject: [PATCH 16/18] Remove backwards breaking ChangelogCounterInterface --- .../Framework/Mview/View/Changelog.php | 18 +-------------- .../Mview/View/ChangelogCounterInterface.php | 22 ------------------- 2 files changed, 1 insertion(+), 39 deletions(-) delete mode 100644 lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 6d75ee27be14a..3b0b1bedeec22 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -8,7 +8,7 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Phrase; -class Changelog implements ChangelogInterface, ChangelogCounterInterface +class Changelog implements ChangelogInterface { /** * Suffix for changelog table @@ -169,22 +169,6 @@ public function getList($fromVersionId, $toVersionId) return $this->connection->fetchCol($select); } - /** - * Retrieve the count of entity ids in the range [$fromVersionId..$toVersionId] - * - * @param int $fromVersionId - * @param int $toVersionId - * @return int[] - * @throws ChangelogTableNotExistsException - */ - public function getListSize($fromVersionId, $toVersionId) - { - $countSelect = $this->getListSelect($fromVersionId, $toVersionId); - $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS); - $countSelect->columns(new \Zend_Db_Expr(("COUNT(DISTINCT " . $this->getColumnName() . ")"))); - return $this->connection->fetchOne($countSelect); - } - /** * Get maximum version_id from changelog * @return int diff --git a/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php b/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php deleted file mode 100644 index 5d92ad1c3de79..0000000000000 --- a/lib/internal/Magento/Framework/Mview/View/ChangelogCounterInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - Date: Mon, 4 Dec 2017 19:08:45 +0000 Subject: [PATCH 17/18] Replace getListSize with getList This is not so performant, but as discussed in github it'll do for now. --- .../Indexer/Console/Command/IndexerStatusCommand.php | 2 +- .../Test/Unit/Console/Command/IndexerStatusCommandTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index f5237ea5d023b..22acdc6f82bbc 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -103,7 +103,7 @@ private function getPendingCount(Mview\ViewInterface $view) $state = $view->getState(); - $pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId); + $pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId)); $pendingString = "$pendingCount"; if ($pendingCount <= 0) { diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index 45b3ec3471b09..31513da018c6b 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -27,14 +27,14 @@ class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup */ private function attachViewToIndexerMock($indexerMock, array $data) { - /** @var \Magento\Framework\Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */ + /** @var \Magento\Framework\Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $changelog */ $changelog = $this->getMockBuilder(\Magento\Framework\Mview\View\Changelog::class) ->disableOriginalConstructor() ->getMock(); $changelog->expects($this->any()) - ->method('getListSize') - ->willReturn($data['view']['changelog']['list_size']); + ->method('getList') + ->willReturn(range(0, $data['view']['changelog']['list_size']-1)); /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stateMock */ $stateMock = $this->getMockBuilder(\Magento\Indexer\Model\Mview\View\State::class) From 3d34bc85aacd57275c5dccc67d9f4a99bfac0374 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Mon, 4 Dec 2017 19:11:34 +0000 Subject: [PATCH 18/18] Remove changes to Changelog --- .../Framework/Mview/View/Changelog.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 3b0b1bedeec22..91caf66228360 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -127,12 +127,14 @@ public function clear($versionId) } /** + * Retrieve entity ids by range [$fromVersionId..$toVersionId] + * * @param int $fromVersionId * @param int $toVersionId - * @return \Magento\Framework\DB\Select + * @return int[] * @throws ChangelogTableNotExistsException */ - private function getListSelect($fromVersionId, $toVersionId) + public function getList($fromVersionId, $toVersionId) { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { @@ -152,20 +154,6 @@ private function getListSelect($fromVersionId, $toVersionId) (int)$toVersionId ); - return $select; - } - - /** - * Retrieve entity ids by range [$fromVersionId..$toVersionId] - * - * @param int $fromVersionId - * @param int $toVersionId - * @return int[] - * @throws ChangelogTableNotExistsException - */ - public function getList($fromVersionId, $toVersionId) - { - $select = $this->getListSelect($fromVersionId, $toVersionId); return $this->connection->fetchCol($select); }