Skip to content

Commit 597ce75

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into NORD-PR-PAT
2 parents c082110 + fb6faf5 commit 597ce75

File tree

51 files changed

+2407
-347
lines changed

Some content is hidden

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

51 files changed

+2407
-347
lines changed

app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CacheInvalidate\Observer;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\Event\ObserverInterface;
910

1011
class InvalidateVarnishObserver implements ObserverInterface
@@ -21,6 +22,13 @@ class InvalidateVarnishObserver implements ObserverInterface
2122
*/
2223
protected $purgeCache;
2324

25+
/**
26+
* Invalidation tags resolver
27+
*
28+
* @var \Magento\Framework\App\Cache\Tag\Resolver
29+
*/
30+
private $tagResolver;
31+
2432
/**
2533
* @param \Magento\PageCache\Model\Config $config
2634
* @param \Magento\CacheInvalidate\Model\PurgeCache $purgeCache
@@ -42,18 +50,35 @@ public function __construct(
4250
*/
4351
public function execute(\Magento\Framework\Event\Observer $observer)
4452
{
53+
$object = $observer->getEvent()->getObject();
54+
if (!is_object($object)) {
55+
return;
56+
}
4557
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
46-
$object = $observer->getEvent()->getObject();
47-
if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
48-
$tags = [];
49-
$pattern = "((^|,)%s(,|$))";
50-
foreach ($object->getIdentities() as $tag) {
51-
$tags[] = sprintf($pattern, $tag);
52-
}
53-
if (!empty($tags)) {
54-
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
55-
}
58+
$bareTags = $this->getTagResolver()->getTags($object);
59+
60+
$tags = [];
61+
$pattern = "((^|,)%s(,|$))";
62+
foreach ($bareTags as $tag) {
63+
$tags[] = sprintf($pattern, $tag);
64+
}
65+
if (!empty($tags)) {
66+
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
5667
}
68+
69+
}
70+
}
71+
72+
/**
73+
* @deprecated
74+
* @return \Magento\Framework\App\Cache\Tag\Resolver
75+
*/
76+
private function getTagResolver()
77+
{
78+
if ($this->tagResolver === null) {
79+
$this->tagResolver = \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
5781
}
82+
return $this->tagResolver;
5883
}
5984
}

app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CacheInvalidate\Test\Unit\Observer;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
810
class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
911
{
1012
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver */
@@ -22,11 +24,16 @@ class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
2224
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\DataObject\ */
2325
protected $observerObject;
2426

27+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Tag\Resolver */
28+
private $tagResolver;
29+
2530
/**
2631
* Set up all mocks and data for test
2732
*/
2833
protected function setUp()
2934
{
35+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
3037
$this->configMock = $this->getMock(
3138
\Magento\PageCache\Model\Config::class,
3239
['getType', 'isEnabled'],
@@ -39,6 +46,10 @@ protected function setUp()
3946
$this->configMock,
4047
$this->purgeCache
4148
);
49+
50+
$this->tagResolver = $this->getMock(\Magento\Framework\App\Cache\Tag\Resolver::class, [], [], '', false);
51+
$helper->setBackwardCompatibleProperty($this->model, 'tagResolver', $this->tagResolver);
52+
4253
$this->observerMock = $this->getMock(
4354
\Magento\Framework\Event\Observer::class,
4455
['getEvent'],
@@ -65,10 +76,12 @@ public function testInvalidateVarnish()
6576
)->will(
6677
$this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
6778
);
79+
6880
$eventMock = $this->getMock(\Magento\Framework\Event::class, ['getObject'], [], '', false);
6981
$eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->observerObject));
7082
$this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
71-
$this->observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
83+
$this->tagResolver->expects($this->once())->method('getTags')->with($this->observerObject)
84+
->will($this->returnValue($tags));
7285
$this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with($pattern);
7386

7487
$this->model->execute($this->observerMock);

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class Category extends \Magento\Backend\App\Action
3131
*/
3232
protected function _initCategory($getRootInstead = false)
3333
{
34-
$categoryId = (int)$this->getRequest()->getParam('id', false);
34+
$categoryId = $this->resolveCategoryId();
3535
$storeId = (int)$this->getRequest()->getParam('store');
3636
$category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
3737
$category->setStoreId($storeId);
@@ -62,6 +62,18 @@ protected function _initCategory($getRootInstead = false)
6262
return $category;
6363
}
6464

65+
/**
66+
* Resolve Category Id (from get or from post)
67+
*
68+
* @return int
69+
*/
70+
private function resolveCategoryId()
71+
{
72+
$categoryId = (int)$this->getRequest()->getParam('id', false);
73+
74+
return $categoryId ?: (int)$this->getRequest()->getParam('entity_id', false);
75+
}
76+
6577
/**
6678
* Build response for ajax request
6779
*

app/code/Magento/Catalog/Helper/Product/Compare.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ public function getRemoveUrl()
228228
*/
229229
public function getPostDataRemove($product)
230230
{
231-
$listCleanUrl = $this->getEncodedUrl($this->_getUrl('catalog/product_compare'));
232231
$data = [
233-
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $listCleanUrl,
234-
'product' => $product->getId()
232+
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
233+
'product' => $product->getId(),
235234
];
236235
return $this->postHelper->getPostData($this->getRemoveUrl(), $data);
237236
}
@@ -253,9 +252,8 @@ public function getClearListUrl()
253252
*/
254253
public function getPostDataClearList()
255254
{
256-
$refererUrl = $this->_getRequest()->getServer('HTTP_REFERER');
257255
$params = [
258-
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($refererUrl)
256+
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
259257
];
260258
return $this->postHelper->getPostData($this->getClearListUrl(), $params);
261259
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
99
{
10+
/**
11+
* Whether to use main or temporary index table
12+
*
13+
* @var bool
14+
*/
15+
protected $useTempTable = false;
16+
1017
/**
1118
* Refresh entities index
1219
*

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,22 @@ protected function initializeProductData(array $productData, $createNew)
313313
*/
314314
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
315315
{
316+
$websiteIds = $product->getWebsiteIds();
317+
316318
if (!$this->storeManager->hasSingleStore()) {
317-
if ($this->storeManager->getStore()->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
318-
$websiteIds = array_keys($this->storeManager->getWebsites());
319-
} else {
320-
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
321-
}
319+
$websiteIds = array_unique(
320+
array_merge(
321+
$websiteIds,
322+
[$this->storeManager->getStore()->getWebsiteId()]
323+
)
324+
);
325+
}
322326

323-
$product->setWebsiteIds(array_unique(array_merge($product->getWebsiteIds(), $websiteIds)));
327+
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
328+
$websiteIds = array_keys($this->storeManager->getWebsites());
324329
}
330+
331+
$product->setWebsiteIds($websiteIds);
325332
}
326333

327334
/**

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class Category extends AbstractResource
3333
*/
3434
protected $_categoryProductTable;
3535

36+
/**
37+
* @var array[]
38+
*/
39+
private $entitiesWhereAttributesIs;
40+
3641
/**
3742
* Id of 'is_active' category attribute
3843
*
@@ -573,22 +578,29 @@ public function getIsActiveAttributeId()
573578
*/
574579
public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
575580
{
576-
$linkField = $this->getLinkField();
577-
$bind = ['attribute_id' => $attribute->getId(), 'value' => $expectedValue];
578-
$selectEntities = $this->getConnection()->select()->from(
579-
['ce' => $this->getTable('catalog_category_entity')],
580-
['entity_id']
581-
)->joinLeft(
582-
['ci' => $attribute->getBackend()->getTable()],
583-
"ci.{$linkField} = ce.{$linkField} AND attribute_id = :attribute_id",
584-
['value']
585-
)->where(
586-
'ci.value = :value'
587-
)->where(
588-
'ce.entity_id IN (?)',
589-
$entityIdsFilter
590-
);
591-
return $this->getConnection()->fetchCol($selectEntities, $bind);
581+
$entityIdsFilterHash = md5(serialize($entityIdsFilter));
582+
583+
if (!isset($this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue])) {
584+
$linkField = $this->getLinkField();
585+
$bind = ['attribute_id' => $attribute->getId(), 'value' => $expectedValue];
586+
$selectEntities = $this->getConnection()->select()->from(
587+
['ce' => $this->getTable('catalog_category_entity')],
588+
['entity_id']
589+
)->joinLeft(
590+
['ci' => $attribute->getBackend()->getTable()],
591+
"ci.{$linkField} = ce.{$linkField} AND attribute_id = :attribute_id",
592+
['value']
593+
)->where(
594+
'ci.value = :value'
595+
)->where(
596+
'ce.entity_id IN (?)',
597+
$entityIdsFilter
598+
);
599+
$this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue] =
600+
$this->getConnection()->fetchCol($selectEntities, $bind);
601+
}
602+
603+
return $this->entitiesWhereAttributesIs[$entityIdsFilterHash][$attribute->getId()][$expectedValue];
592604
}
593605

594606
/**

app/code/Magento/Catalog/Model/ResourceModel/MaxHeapTableSizeProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Framework\App\ResourceConnection;
99

10+
/**
11+
* @deprecated
12+
*/
1013
class MaxHeapTableSizeProcessor
1114
{
1215
/**

app/code/Magento/Catalog/Plugin/Model/Indexer/Category/Product/MaxHeapTableSizeProcessorOnFullReindex.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Catalog\Model\ResourceModel\MaxHeapTableSizeProcessor;
1111
use Psr\Log\LoggerInterface;
1212

13+
/**
14+
* @deprecated
15+
*/
1316
class MaxHeapTableSizeProcessorOnFullReindex
1417
{
1518
/**

0 commit comments

Comments
 (0)