Skip to content

Commit 96d6f5b

Browse files
authored
Merge pull request #5516 from magento-tsg/2.3-develop-pr117
[TSG] Fixes for 2.3 (pr117) (2.3-develop)
2 parents 7ca65cf + 6d0a7c4 commit 96d6f5b

File tree

23 files changed

+1652
-80
lines changed

23 files changed

+1652
-80
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminCleanStaticAndVarDirsActionGroup">
12+
<annotations>
13+
<description>Clean pub/static and var dirs.</description>
14+
</annotations>
15+
16+
<executeInSelenium function="function(\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
17+
$dirs = [
18+
MAGENTO_BP . '/pub/static',
19+
MAGENTO_BP . '/var',
20+
];
21+
22+
function deleteSubDirectories($dir)
23+
{
24+
$excludePatterns = ['#var\/.htaccess#', '#static\/.htaccess#'];
25+
$iterator = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
26+
$directories = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST);
27+
foreach($directories as $directory) {
28+
if ($directory->isDir()){
29+
deleteSubDirectories($directory->getPathname());
30+
rmdir($directory);
31+
} else {
32+
foreach ($excludePatterns as $pattern) {
33+
if (preg_match($pattern, $directory->getPathname())) {
34+
continue 2;
35+
}
36+
}
37+
unlink($directory->getPathname());
38+
}
39+
}
40+
}
41+
42+
foreach ($dirs as $dir) {
43+
if (!is_dir($dir)) {
44+
continue;
45+
}
46+
deleteSubDirectories($dir);
47+
}
48+
} " stepKey="cleanStaticAndVarDirs"/>
49+
</actionGroup>
50+
</actionGroups>

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Plugin/Attribute.php

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin;
77

88
use Magento\CatalogSearch\Model\Indexer\Fulltext;
9+
use Magento\Framework\Model\AbstractModel;
10+
use Magento\Catalog\Model\ResourceModel\Attribute as AttributeResourceModel;
11+
use Magento\Framework\Search\Request\Config;
12+
use Magento\Framework\Indexer\IndexerRegistry;
13+
use Magento\Catalog\Api\Data\EavAttributeInterface;
914

1015
/**
1116
* Catalog search indexer plugin for catalog attribute.
1217
*/
1318
class Attribute extends AbstractPlugin
1419
{
1520
/**
16-
* @var \Magento\Framework\Search\Request\Config
21+
* @var Config
1722
*/
1823
private $config;
1924

@@ -33,12 +38,12 @@ class Attribute extends AbstractPlugin
3338
private $saveIsNew;
3439

3540
/**
36-
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
37-
* @param \Magento\Framework\Search\Request\Config $config
41+
* @param IndexerRegistry $indexerRegistry
42+
* @param Config $config
3843
*/
3944
public function __construct(
40-
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
41-
\Magento\Framework\Search\Request\Config $config
45+
IndexerRegistry $indexerRegistry,
46+
Config $config
4247
) {
4348
parent::__construct($indexerRegistry);
4449
$this->config = $config;
@@ -47,36 +52,32 @@ public function __construct(
4752
/**
4853
* Check if indexer invalidation is needed on attribute save (searchable flag change)
4954
*
50-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $subject
51-
* @param \Magento\Framework\Model\AbstractModel $attribute
55+
* @param AttributeResourceModel $subject
56+
* @param AbstractModel $attribute
5257
*
5358
* @return void
5459
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5560
*/
5661
public function beforeSave(
57-
\Magento\Catalog\Model\ResourceModel\Attribute $subject,
58-
\Magento\Framework\Model\AbstractModel $attribute
62+
AttributeResourceModel $subject,
63+
AbstractModel $attribute
5964
) {
6065
$this->saveIsNew = $attribute->isObjectNew();
61-
$this->saveNeedInvalidation = (
62-
$attribute->dataHasChangedFor('is_searchable')
63-
|| $attribute->dataHasChangedFor('is_filterable')
64-
|| $attribute->dataHasChangedFor('is_visible_in_advanced_search')
65-
);
66+
$this->saveNeedInvalidation = $this->shouldInvalidateSearchIndex($attribute);
6667
}
6768

6869
/**
6970
* Invalidate indexer on attribute save (searchable flag change)
7071
*
71-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $subject
72-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $result
72+
* @param AttributeResourceModel $subject
73+
* @param AttributeResourceModel $result
7374
*
74-
* @return \Magento\Catalog\Model\ResourceModel\Attribute
75+
* @return AttributeResourceModel
7576
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7677
*/
7778
public function afterSave(
78-
\Magento\Catalog\Model\ResourceModel\Attribute $subject,
79-
\Magento\Catalog\Model\ResourceModel\Attribute $result
79+
AttributeResourceModel $subject,
80+
AttributeResourceModel $result
8081
) {
8182
if ($this->saveNeedInvalidation) {
8283
$this->indexerRegistry->get(Fulltext::INDEXER_ID)->invalidate();
@@ -91,35 +92,61 @@ public function afterSave(
9192
/**
9293
* Check if indexer invalidation is needed on searchable attribute delete
9394
*
94-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $subject
95-
* @param \Magento\Framework\Model\AbstractModel $attribute
95+
* @param AttributeResourceModel $subject
96+
* @param AbstractModel $attribute
9697
*
9798
* @return void
9899
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
99100
*/
100101
public function beforeDelete(
101-
\Magento\Catalog\Model\ResourceModel\Attribute $subject,
102-
\Magento\Framework\Model\AbstractModel $attribute
102+
AttributeResourceModel $subject,
103+
AbstractModel $attribute
103104
) {
104105
$this->deleteNeedInvalidation = !$attribute->isObjectNew() && $attribute->getIsSearchable();
105106
}
106107

107108
/**
108109
* Invalidate indexer on searchable attribute delete
109110
*
110-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $subject
111-
* @param \Magento\Catalog\Model\ResourceModel\Attribute $result
111+
* @param AttributeResourceModel $subject
112+
* @param AttributeResourceModel $result
112113
*
113-
* @return \Magento\Catalog\Model\ResourceModel\Attribute
114+
* @return AttributeResourceModel
114115
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
115116
*/
116117
public function afterDelete(
117-
\Magento\Catalog\Model\ResourceModel\Attribute $subject,
118-
\Magento\Catalog\Model\ResourceModel\Attribute $result
118+
AttributeResourceModel $subject,
119+
AttributeResourceModel $result
119120
) {
120121
if ($this->deleteNeedInvalidation) {
121122
$this->indexerRegistry->get(Fulltext::INDEXER_ID)->invalidate();
122123
}
123124
return $result;
124125
}
126+
127+
/**
128+
* Check if catalogsearch_fulltext index should be invalidated.
129+
*
130+
* @param AbstractModel $attribute
131+
* @return bool
132+
*/
133+
private function shouldInvalidateSearchIndex(
134+
AbstractModel $attribute
135+
):bool {
136+
$shouldInvalidate = false;
137+
$fields = [
138+
EavAttributeInterface::IS_SEARCHABLE,
139+
EavAttributeInterface::IS_FILTERABLE,
140+
EavAttributeInterface::IS_VISIBLE_IN_ADVANCED_SEARCH,
141+
];
142+
foreach ($fields as $field) {
143+
if ($this->saveIsNew && $attribute->getData($field)
144+
|| !$this->saveIsNew && $attribute->dataHasChangedFor($field)) {
145+
$shouldInvalidate = true;
146+
break;
147+
}
148+
}
149+
150+
return $shouldInvalidate;
151+
}
125152
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/Fulltext/Plugin/AttributeTest.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function setUp()
6464
);
6565
$this->attributeMock = $this->createPartialMock(
6666
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
67-
['dataHasChangedFor', 'isObjectNew', 'getIsSearchable']
67+
['dataHasChangedFor', 'isObjectNew', 'getIsSearchable', 'getData']
6868
);
6969
$this->config = $this->getMockBuilder(\Magento\Framework\Search\Request\Config::class)
7070
->disableOriginalConstructor()
@@ -85,7 +85,7 @@ public function testBeforeSave()
8585
->method('isObjectNew')
8686
->willReturn(true);
8787
$this->attributeMock->expects($this->once())
88-
->method('dataHasChangedFor')
88+
->method('getData')
8989
->with('is_searchable')
9090
->willReturn(true);
9191
$this->assertEquals(
@@ -102,29 +102,54 @@ public function testAfterSaveNoInvalidation()
102102
);
103103
}
104104

105-
public function testAfterSaveWithInvalidation()
105+
/**
106+
* Test afterSave with invalidation.
107+
*
108+
* @param bool $saveNeedInvalidation
109+
* @param bool $saveIsNew
110+
* @dataProvider afterSaveDataProvider
111+
*/
112+
public function testAfterSaveWithInvalidation(bool $saveNeedInvalidation, bool $saveIsNew)
106113
{
107114
$model = $this->objectManager->getObject(
108115
Attribute::class,
109116
[
110117
'indexerRegistry' => $this->indexerRegistryMock,
111118
'config' => $this->config,
112-
'saveNeedInvalidation' => true,
113-
'saveIsNew' => true
119+
'saveNeedInvalidation' => $saveNeedInvalidation,
120+
'saveIsNew' => $saveIsNew,
114121
]
115122
);
116123

117-
$this->indexerMock->expects($this->once())->method('invalidate');
118-
$this->prepareIndexer();
119-
$this->config->expects($this->once())
120-
->method('reset');
124+
if ($saveNeedInvalidation) {
125+
$this->indexerMock->expects($this->once())->method('invalidate');
126+
$this->prepareIndexer();
127+
}
128+
129+
if ($saveIsNew || $saveNeedInvalidation) {
130+
$this->config->expects($this->once())
131+
->method('reset');
132+
}
121133

122134
$this->assertEquals(
123135
$this->subjectMock,
124136
$model->afterSave($this->subjectMock, $this->subjectMock)
125137
);
126138
}
127139

140+
/**
141+
* @return array
142+
*/
143+
public function afterSaveDataProvider(): array
144+
{
145+
return [
146+
'save_new_with_invalidation' => ['saveNeedInvalidation' => true, 'isNew' => true],
147+
'save_new_without_invalidation' => ['saveNeedInvalidation' => false, 'isNew' => true],
148+
'update_existing_with_inalidation' => ['saveNeedInvalidation' => true, 'isNew' => false],
149+
'update_existing_without_inalidation' => ['saveNeedInvalidation' => false, 'isNew' => false],
150+
];
151+
}
152+
128153
public function testBeforeDelete()
129154
{
130155
$this->attributeMock->expects($this->once())

0 commit comments

Comments
 (0)