Skip to content

Commit 8958b13

Browse files
author
Magento CICD
authored
merge magento/2.2-develop into magento-mpi/MPI-PR-Regression2
2 parents f342ff4 + 1e87722 commit 8958b13

File tree

99 files changed

+2007
-837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2007
-837
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
}

app/code/Magento/Catalog/Controller/Adminhtml/Category.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ abstract class Category extends \Magento\Backend\App\Action
1818
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
1919

2020
/**
21-
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
21+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
2222
*/
23-
private $dateTimeFilter;
23+
protected $dateFilter;
24+
25+
/**
26+
* @param \Magento\Backend\App\Action\Context $context
27+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
28+
*/
29+
public function __construct(
30+
\Magento\Backend\App\Action\Context $context,
31+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
32+
) {
33+
$this->dateFilter = $dateFilter;
34+
parent::__construct($context);
35+
}
2436

2537
/**
2638
* Initialize requested category and put it into registry.
@@ -125,20 +137,6 @@ protected function ajaxRequestResponse($category, $resultPage)
125137
return $resultJson;
126138
}
127139

128-
/**
129-
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
130-
*
131-
* @deprecated 101.0.0
132-
*/
133-
private function getDateTimeFilter()
134-
{
135-
if ($this->dateTimeFilter === null) {
136-
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
137-
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
138-
}
139-
return $this->dateTimeFilter;
140-
}
141-
142140
/**
143141
* Datetime data preprocessing
144142
*
@@ -154,7 +152,7 @@ protected function dateTimePreprocessing($category, $postData)
154152
foreach ($attributes as $attrKey => $attribute) {
155153
if ($attribute->getBackend()->getType() == 'datetime') {
156154
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
157-
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
155+
$dateFieldFilters[$attrKey] = $this->dateFilter;
158156
}
159157
}
160158
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
6161
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
6262
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
6363
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
64+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
6465
* @param StoreManagerInterface $storeManager
6566
* @param \Magento\Eav\Model\Config $eavConfig
6667
*/
@@ -69,10 +70,11 @@ public function __construct(
6970
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
7071
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
7172
\Magento\Framework\View\LayoutFactory $layoutFactory,
73+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
7274
StoreManagerInterface $storeManager,
7375
\Magento\Eav\Model\Config $eavConfig = null
7476
) {
75-
parent::__construct($context);
77+
parent::__construct($context, $dateFilter);
7678
$this->resultRawFactory = $resultRawFactory;
7779
$this->resultJsonFactory = $resultJsonFactory;
7880
$this->layoutFactory = $layoutFactory;

app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function syncData($indexer, $destinationTable, $ids)
143143
protected function processRelations($indexer, $ids, $onlyParents = false)
144144
{
145145
$parentIds = $indexer->getRelationsByChild($ids);
146-
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($ids);
146+
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($parentIds);
147147
return array_unique(array_merge($ids, $childIds, $parentIds));
148148
}
149149
}
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
}

0 commit comments

Comments
 (0)