Skip to content

Commit 1eaac8f

Browse files
Merge remote-tracking branch 'jackalopes/MAGETWO-71369-full-reindex' into BundledPR-Sep8
2 parents 3520171 + 66f43eb commit 1eaac8f

File tree

10 files changed

+187
-170
lines changed

10 files changed

+187
-170
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Indexer/Product/Price/Plugin/Import.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@
77

88
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;
99

10-
class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\AbstractPlugin
10+
class Import
1111
{
12+
/**
13+
* @var \Magento\Framework\Indexer\IndexerRegistry
14+
*/
15+
private $indexerRegistry;
16+
17+
/**
18+
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
19+
*/
20+
public function __construct(\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry)
21+
{
22+
$this->indexerRegistry = $indexerRegistry;
23+
}
24+
1225
/**
1326
* After import handler
1427
*
@@ -18,9 +31,7 @@ class Import extends \Magento\Catalog\Model\Indexer\Product\Price\Plugin\Abstrac
1831
*/
1932
public function afterSaveAdvancedPricing(AdvancedPricing $subject)
2033
{
21-
if (!$this->getPriceIndexer()->isScheduled()) {
22-
$this->invalidateIndexer();
23-
}
34+
$this->invalidateIndexer();
2435
}
2536

2637
/**
@@ -32,18 +43,19 @@ public function afterSaveAdvancedPricing(AdvancedPricing $subject)
3243
*/
3344
public function afterDeleteAdvancedPricing(AdvancedPricing $subject)
3445
{
35-
if (!$this->getPriceIndexer()->isScheduled()) {
36-
$this->invalidateIndexer();
37-
}
46+
$this->invalidateIndexer();
3847
}
3948

4049
/**
41-
* Get price indexer
50+
* Invalidate indexer
4251
*
43-
* @return \Magento\Framework\Indexer\IndexerInterface
52+
* @return void
4453
*/
45-
protected function getPriceIndexer()
54+
private function invalidateIndexer()
4655
{
47-
return $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
56+
$priceIndexer = $this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID);
57+
if (!$priceIndexer->isScheduled()) {
58+
$priceIndexer->invalidate();
59+
}
4860
}
4961
}

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Indexer/Product/Price/Plugin/ImportTest.php

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ class ImportTest extends \PHPUnit\Framework\TestCase
1313
/**
1414
* @var \Magento\Framework\Indexer\IndexerInterface |\PHPUnit_Framework_MockObject_MockObject
1515
*/
16-
protected $indexer;
16+
private $indexer;
1717

1818
/**
1919
* @var Import |\PHPUnit_Framework_MockObject_MockObject
2020
*/
21-
protected $import;
21+
private $import;
2222

2323
/**
2424
* @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing|\PHPUnit_Framework_MockObject_MockObject
2525
*/
26-
protected $advancedPricing;
26+
private $advancedPricing;
27+
28+
/**
29+
* @var \Magento\Framework\Indexer\IndexerRegistry|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $indexerRegistry;
2732

2833
protected function setUp()
2934
{
@@ -33,29 +38,58 @@ protected function setUp()
3338
'',
3439
false
3540
);
36-
$this->import = $this->createPartialMock(
37-
\Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import::class,
38-
['getPriceIndexer', 'invalidateIndexer']
41+
$this->indexerRegistry = $this->createMock(
42+
\Magento\Framework\Indexer\IndexerRegistry::class
43+
);
44+
$this->import = new \Magento\AdvancedPricingImportExport\Model\Indexer\Product\Price\Plugin\Import(
45+
$this->indexerRegistry
3946
);
4047
$this->advancedPricing = $this->createMock(
4148
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
4249
);
43-
$this->import->expects($this->any())->method('getPriceIndexer')->willReturn($this->indexer);
50+
$this->indexerRegistry->expects($this->any())
51+
->method('get')
52+
->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)
53+
->willReturn($this->indexer);
4454
}
4555

46-
public function testAfterSaveAdvancedPricing()
56+
public function testAfterSaveReindexIsOnSave()
4757
{
48-
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
49-
$this->import->expects($this->once())->method('invalidateIndexer');
58+
$this->indexer->expects($this->once())
59+
->method('isScheduled')
60+
->willReturn(false);
61+
$this->indexer->expects($this->once())
62+
->method('invalidate');
63+
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
64+
}
5065

66+
public function testAfterSaveReindexIsOnSchedule()
67+
{
68+
$this->indexer->expects($this->once())
69+
->method('isScheduled')
70+
->willReturn(true);
71+
$this->indexer->expects($this->never())
72+
->method('invalidate');
5173
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
5274
}
5375

54-
public function testAfterDeleteAdvancedPricing()
76+
public function testAfterDeleteReindexIsOnSave()
5577
{
56-
$this->indexer->expects($this->once())->method('isScheduled')->willReturn(false);
57-
$this->import->expects($this->once())->method('invalidateIndexer');
78+
$this->indexer->expects($this->once())
79+
->method('isScheduled')
80+
->willReturn(false);
81+
$this->indexer->expects($this->once())
82+
->method('invalidate');
83+
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
84+
}
5885

86+
public function testAfterDeleteReindexIsOnSchedule()
87+
{
88+
$this->indexer->expects($this->once())
89+
->method('isScheduled')
90+
->willReturn(true);
91+
$this->indexer->expects($this->never())
92+
->method('invalidate');
5993
$this->import->afterSaveAdvancedPricing($this->advancedPricing);
6094
}
6195
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Indexer\Product\Price;
7+
8+
use Magento\Customer\Api\Data\GroupInterface;
9+
use Magento\Framework\Indexer\IndexerRegistry;
10+
11+
/**
12+
* Invalidate price index
13+
*/
14+
class InvalidateIndex implements UpdateIndexInterface
15+
{
16+
/**
17+
* @var IndexerRegistry
18+
*/
19+
private $indexerRegistry;
20+
21+
/**
22+
* Constructor
23+
*
24+
* @param IndexerRegistry $indexerRegistry
25+
*/
26+
public function __construct(
27+
IndexerRegistry $indexerRegistry
28+
) {
29+
$this->indexerRegistry = $indexerRegistry;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*/
36+
public function update(GroupInterface $group, $isGroupNew)
37+
{
38+
$this->indexerRegistry->get(Processor::INDEXER_ID)->invalidate();
39+
}
40+
}

app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/AbstractPlugin.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/code/Magento/Catalog/Model/Indexer/Product/Price/Plugin/CustomerGroup.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,44 @@
66
namespace Magento\Catalog\Model\Indexer\Product\Price\Plugin;
77

88
use Magento\Customer\Api\GroupRepositoryInterface;
9+
use Magento\Customer\Api\Data\GroupInterface;
10+
use \Magento\Catalog\Model\Indexer\Product\Price\UpdateIndexInterface;
911

10-
class CustomerGroup extends AbstractPlugin
12+
class CustomerGroup
1113
{
1214
/**
13-
* Invalidate the indexer after the group is saved.
14-
*
15-
* @param GroupRepositoryInterface $subject
16-
* @param string $result
17-
* @return string
18-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
15+
* @var UpdateIndexInterface
1916
*/
20-
public function afterSave(GroupRepositoryInterface $subject, $result)
21-
{
22-
$this->invalidateIndexer();
23-
return $result;
24-
}
17+
private $updateIndex;
2518

2619
/**
27-
* Invalidate the indexer after the group is deleted.
20+
* Constructor
2821
*
29-
* @param GroupRepositoryInterface $subject
30-
* @param string $result
31-
* @return string
32-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
22+
* @param UpdateIndexInterface $updateIndex
3323
*/
34-
public function afterDelete(GroupRepositoryInterface $subject, $result)
35-
{
36-
$this->invalidateIndexer();
37-
return $result;
24+
public function __construct(
25+
UpdateIndexInterface $updateIndex
26+
) {
27+
$this->updateIndex = $updateIndex;
3828
}
3929

4030
/**
41-
* Invalidate the indexer after the group is deleted.
31+
* Update price index after customer group saved
4232
*
4333
* @param GroupRepositoryInterface $subject
44-
* @param string $result
45-
* @return string
34+
* @param \Closure $proceed
35+
* @param GroupInterface $result
36+
* @return GroupInterface
4637
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4738
*/
48-
public function afterDeleteById(GroupRepositoryInterface $subject, $result)
49-
{
50-
$this->invalidateIndexer();
51-
return $result;
39+
public function aroundSave(
40+
GroupRepositoryInterface $subject,
41+
\Closure $proceed,
42+
GroupInterface $group
43+
) {
44+
$isGroupNew = !$group->getId();
45+
$group = $proceed($group);
46+
$this->updateIndex->update($group, $isGroupNew);
47+
return $group;
5248
}
5349
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Indexer\Product\Price;
7+
8+
use Magento\Customer\Api\Data\GroupInterface;
9+
10+
/**
11+
* Defines strategy for updating price index
12+
*
13+
* @api
14+
*/
15+
interface UpdateIndexInterface
16+
{
17+
/**
18+
* Update price index
19+
*
20+
* @param GroupInterface $group
21+
* @param bool $isGroupNew
22+
* @return void
23+
*/
24+
public function update(GroupInterface $group, $isGroupNew);
25+
}

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Plugin/CustomerGroupTest.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)