Skip to content

Commit 2e763db

Browse files
authored
Merge branch '2.4-develop' into functional-mainline-pr-ce-new
2 parents 4ac233f + 174b645 commit 2e763db

File tree

55 files changed

+2845
-280
lines changed

Some content is hidden

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

55 files changed

+2845
-280
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ***********************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\AdvancedSearch\Model\DataProvider;
20+
21+
use Magento\Search\Model\Autocomplete\DataProviderInterface;
22+
use Magento\Search\Model\Autocomplete\ItemFactory;
23+
use Magento\Search\Model\QueryFactory;
24+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
25+
use Magento\AdvancedSearch\Model\SuggestedQueries;
26+
use Magento\CatalogSearch\Model\Autocomplete\DataProvider;
27+
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
28+
use Magento\Store\Model\ScopeInterface;
29+
30+
class AutocompleteSuggestions implements DataProviderInterface
31+
{
32+
/**
33+
* @var QueryFactory
34+
*/
35+
private $queryFactory;
36+
37+
/**
38+
* @var ItemFactory
39+
*/
40+
private $itemFactory;
41+
42+
/**
43+
* @var SuggestedQueries
44+
*/
45+
private $suggestedQueries;
46+
47+
/**
48+
* @var DataProvider
49+
*/
50+
private $dataProvider;
51+
52+
/**
53+
* @var ScopeConfig
54+
*/
55+
private $scopeConfig;
56+
57+
/**
58+
* @param QueryFactory $queryFactory
59+
* @param ItemFactory $itemFactory
60+
* @param ScopeConfig $scopeConfig
61+
* @param SuggestedQueries $suggestedQueries
62+
* @param DataProvider $dataProvider
63+
*/
64+
public function __construct(
65+
QueryFactory $queryFactory,
66+
ItemFactory $itemFactory,
67+
ScopeConfig $scopeConfig,
68+
SuggestedQueries $suggestedQueries,
69+
DataProvider $dataProvider
70+
) {
71+
$this->queryFactory = $queryFactory;
72+
$this->itemFactory = $itemFactory;
73+
$this->suggestedQueries = $suggestedQueries;
74+
$this->dataProvider = $dataProvider;
75+
$this->scopeConfig = $scopeConfig;
76+
}
77+
78+
/**
79+
* @inheritdoc
80+
*/
81+
public function getItems()
82+
{
83+
$result = [];
84+
if ($this->scopeConfig->isSetFlag(
85+
SuggestedQueriesInterface::SEARCH_SUGGESTION_ENABLED,
86+
ScopeInterface::SCOPE_STORE
87+
)) {
88+
// populate with search suggestions
89+
$query = $this->queryFactory->get();
90+
$suggestions = $this->suggestedQueries->getItems($query);
91+
foreach ($suggestions as $suggestion) {
92+
$resultItem = $this->itemFactory->create([
93+
'title' => $suggestion->getQueryText(),
94+
'num_results' => $suggestion->getResultsCount(),
95+
]);
96+
$result[] = $resultItem;
97+
}
98+
} else {
99+
// populate with autocomplete
100+
$result = $this->dataProvider->getItems();
101+
}
102+
return $result;
103+
}
104+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2023 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ***********************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\AdvancedSearch\Test\Unit\Model\DataProvider;
20+
21+
use Magento\AdvancedSearch\Model\DataProvider\AutocompleteSuggestions;
22+
use Magento\Search\Model\Autocomplete\ItemFactory;
23+
use Magento\Search\Model\QueryFactory;
24+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
25+
use Magento\AdvancedSearch\Model\SuggestedQueries;
26+
use Magento\CatalogSearch\Model\Autocomplete\DataProvider;
27+
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
28+
use Magento\Store\Model\ScopeInterface;
29+
use Magento\Search\Model\Query;
30+
use PHPUnit\Framework\MockObject\MockObject;
31+
use PHPUnit\Framework\TestCase;
32+
33+
class AutocompleteSuggestionsTest extends TestCase
34+
{
35+
/**
36+
* @var AutocompleteSuggestions
37+
*/
38+
private $model;
39+
40+
/**
41+
* @var QueryFactory|MockObject
42+
*/
43+
private $queryFactory;
44+
45+
/**
46+
* @var ItemFactory|MockObject
47+
*/
48+
private $itemFactory;
49+
50+
/**
51+
* @var SuggestedQueries|MockObject
52+
*/
53+
private $suggestedQueries;
54+
55+
/**
56+
* @var DataProvider|MockObject
57+
*/
58+
private $dataProvider;
59+
60+
/**
61+
* @var ScopeConfig|MockObject
62+
*/
63+
private $scopeConfig;
64+
65+
/**
66+
* @var Query|MockObject
67+
*/
68+
private $query;
69+
70+
protected function setUp(): void
71+
{
72+
$this->queryFactory = $this->getMockBuilder(QueryFactory::class)
73+
->disableOriginalConstructor()
74+
->getMock();
75+
$this->itemFactory = $this->getMockBuilder(ItemFactory::class)
76+
->disableOriginalConstructor()
77+
->getMock();
78+
$this->suggestedQueries = $this->getMockBuilder(SuggestedQueries::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
$this->dataProvider = $this->getMockBuilder(DataProvider::class)
82+
->disableOriginalConstructor()
83+
->getMock();
84+
$this->scopeConfig = $this->getMockBuilder(ScopeConfig::class)
85+
->getMockForAbstractClass();
86+
$this->query = $this->getMockBuilder(Query::class)
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$this->queryFactory->expects($this->any())
90+
->method('get')
91+
->willReturn($this->query);
92+
93+
$this->model = new AutocompleteSuggestions(
94+
$this->queryFactory,
95+
$this->itemFactory,
96+
$this->scopeConfig,
97+
$this->suggestedQueries,
98+
$this->dataProvider
99+
);
100+
}
101+
102+
public function testGetItemsWithEnabledSuggestions(): void
103+
{
104+
$this->scopeConfig->expects($this->once())
105+
->method('isSetFlag')
106+
->with(SuggestedQueriesInterface::SEARCH_SUGGESTION_ENABLED, ScopeInterface::SCOPE_STORE)
107+
->willReturn(true);
108+
$this->suggestedQueries->expects($this->once())
109+
->method('getItems')
110+
->with($this->query)
111+
->willReturn([]);
112+
$this->dataProvider->expects($this->never())
113+
->method('getItems');
114+
$this->assertEquals([], $this->model->getItems());
115+
}
116+
117+
public function testGetItemsWithDisabledSuggestions(): void
118+
{
119+
$this->scopeConfig->expects($this->once())
120+
->method('isSetFlag')
121+
->with(SuggestedQueriesInterface::SEARCH_SUGGESTION_ENABLED, ScopeInterface::SCOPE_STORE)
122+
->willReturn(false);
123+
$this->suggestedQueries->expects($this->never())
124+
->method('getItems');
125+
$this->dataProvider->expects($this->once())
126+
->method('getItems')
127+
->willReturn([]);
128+
$this->assertEquals([], $this->model->getItems());
129+
}
130+
}

app/code/Magento/AdvancedSearch/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@
4040
</arguments>
4141
</type>
4242
<preference for="Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProviderInterface" type="Magento\AdvancedSearch\Model\Adapter\DataMapper\AdditionalFieldsProvider" />
43+
<type name="Magento\Search\Model\Autocomplete">
44+
<arguments>
45+
<argument name="dataProviders" xsi:type="array">
46+
<item name="10" xsi:type="object">Magento\AdvancedSearch\Model\DataProvider\AutocompleteSuggestions</item>
47+
</argument>
48+
</arguments>
49+
</type>
4350
</config>

app/code/Magento/Catalog/Model/Product/Image.php

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
1212
use Magento\Framework\App\Filesystem\DirectoryList;
1313
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\Exception\FileSystemException;
1415
use Magento\Framework\Image as MagentoImage;
1516
use Magento\Framework\Serialize\SerializerInterface;
1617

@@ -45,7 +46,8 @@ class Image extends \Magento\Framework\Model\AbstractModel
4546
* Default quality value (for JPEG images only).
4647
*
4748
* @var int
48-
* @deprecated 103.0.1 use config setting with path self::XML_PATH_JPEG_QUALITY
49+
* @deprecated 103.0.1
50+
* @see Use config setting with path self::XML_PATH_JPEG_QUALITY
4951
*/
5052
protected $_quality = null;
5153

@@ -101,7 +103,8 @@ class Image extends \Magento\Framework\Model\AbstractModel
101103

102104
/**
103105
* @var int
104-
* @deprecated unused
106+
* @deprecated
107+
* @see Not used anymore
105108
*/
106109
protected $_angle;
107110

@@ -307,7 +310,8 @@ public function getHeight()
307310
*
308311
* @param int $quality
309312
* @return $this
310-
* @deprecated 103.0.1 use config setting with path self::XML_PATH_JPEG_QUALITY
313+
* @deprecated 103.0.1
314+
* @see Use config setting with path self::XML_PATH_JPEG_QUALITY
311315
*/
312316
public function setQuality($quality)
313317
{
@@ -457,6 +461,7 @@ public function getBaseFile()
457461
* Get new file
458462
*
459463
* @deprecated 102.0.0
464+
* @see Image::getBaseFile
460465
* @return bool|string
461466
*/
462467
public function getNewFile()
@@ -836,38 +841,16 @@ public function getWatermarkHeight()
836841
public function clearCache()
837842
{
838843
$directory = $this->_catalogProductMediaConfig->getBaseMediaPath() . '/cache';
839-
$directoryToDelete = $directory;
840-
// Fixes issue when deleting cache directory at the same time that images are being
841-
// lazy-loaded on storefront leading to new directories and files generation in the cache directory
842-
// that would prevent deletion of the cache directory.
843-
// RCA: the method delete() recursively enumerates and delete all subdirectories and files before deleting
844-
// the target directory, which gives other processes time to create directories and files in the same directory.
845-
// Solution: Rename the directory to simulate deletion and delete the destination directory afterward
846844

845+
// If the directory cannot be deleted, it is likely because it is not empty anymore due to lazy loading from
846+
// the storefront triggering new cache file creation.
847+
// This is expected behavior and is not a cause for concern. Deletable files were deleted as expected.
847848
try {
848-
//generate name in format: \.[0-9A-ZA-z-_]{3} (e.g .QX3)
849-
$tmpDirBasename = strrev(strtr(base64_encode(random_bytes(2)), '+/=', '-_.'));
850-
$tmpDirectory = $this->_catalogProductMediaConfig->getBaseMediaPath() . '/' . $tmpDirBasename;
851-
//delete temporary directory if exists
852-
if ($this->_mediaDirectory->isDirectory($tmpDirectory)) {
853-
$this->_mediaDirectory->delete($tmpDirectory);
854-
}
855-
//rename the directory to simulate deletion and delete the destination directory
856-
if ($this->_mediaDirectory->isDirectory($directory) &&
857-
true === $this->_mediaDirectory->getDriver()->rename(
858-
$this->_mediaDirectory->getAbsolutePath($directory),
859-
$this->_mediaDirectory->getAbsolutePath($tmpDirectory)
860-
)
861-
) {
862-
$directoryToDelete = $tmpDirectory;
863-
}
864-
} catch (\Throwable $exception) {
865-
//ignore exceptions thrown during renaming
866-
$directoryToDelete = $directory;
849+
$this->_mediaDirectory->delete($directory);
850+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
851+
} catch (FileSystemException $e) {
867852
}
868853

869-
$this->_mediaDirectory->delete($directoryToDelete);
870-
871854
$this->_coreFileStorageDatabase->deleteFolder($this->_mediaDirectory->getAbsolutePath($directory));
872855
$this->clearImageInfoFromCache();
873856
}

0 commit comments

Comments
 (0)