Skip to content

Commit 2ca596f

Browse files
committed
Merge remote-tracking branch 'upstream/2.4-develop' into B2B-1663
2 parents f5c8189 + afd9589 commit 2ca596f

File tree

71 files changed

+2025
-164
lines changed

Some content is hidden

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

71 files changed

+2025
-164
lines changed

app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function execute()
3434
/** @var $export \Magento\ImportExport\Model\Export */
3535
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3636
$export->setData($data);
37-
$export->filterAttributeCollection(
38-
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
37+
$attrFilterBlock->prepareCollection(
38+
$export->filterAttributeCollection($export->getEntityAttributeCollection())
3939
);
4040
return $resultLayout;
4141
} catch (\Exception $e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
/**
11+
* Class Composite validates if urlKey doesn't matches frontName or restricted words(endpoint names)
12+
*/
13+
class CompositeUrlKey implements UrlKeyValidatorInterface
14+
{
15+
/**
16+
* @var UrlKeyValidatorInterface[]
17+
*/
18+
private $validators;
19+
20+
/**
21+
* @param array $validators
22+
*/
23+
public function __construct(
24+
array $validators = []
25+
) {
26+
$this->validators = $validators;
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function validate(string $urlKey): array
33+
{
34+
$errors = [];
35+
foreach ($this->validators as $validator) {
36+
$errors[] = $validator->validate($urlKey);
37+
}
38+
39+
return array_merge([], ...$errors);
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
use Magento\Backend\App\Area\FrontNameResolver;
11+
12+
/**
13+
* Class FrontName validates if urlKey doesn't matches frontName
14+
*/
15+
class FrontName implements UrlKeyValidatorInterface
16+
{
17+
/**
18+
* @var FrontNameResolver
19+
*/
20+
private $frontNameResolver;
21+
22+
/**
23+
* @param FrontNameResolver $frontNameResolver
24+
*/
25+
public function __construct(
26+
FrontNameResolver $frontNameResolver
27+
) {
28+
$this->frontNameResolver = $frontNameResolver;
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function validate(string $urlKey): array
35+
{
36+
$errors = [];
37+
$frontName = $this->frontNameResolver->getFrontName();
38+
if ($urlKey == $frontName) {
39+
$errors[] = __(
40+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
41+
$urlKey,
42+
$frontName
43+
);
44+
}
45+
46+
return $errors;
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
use Magento\Framework\Validator\UrlKey;
11+
12+
/**
13+
* Class RestrictedWords validates if urlKey doesn't matches restricted words(endpoint names)
14+
*/
15+
class RestrictedWords implements UrlKeyValidatorInterface
16+
{
17+
/**
18+
* @var UrlKey
19+
*/
20+
private $urlKey;
21+
22+
/**
23+
* @param UrlKey $urlKey
24+
*/
25+
public function __construct(
26+
UrlKey $urlKey
27+
) {
28+
$this->urlKey = $urlKey;
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function validate(string $urlKey): array
35+
{
36+
$errors = [];
37+
if (!$this->urlKey->isValid($urlKey)) {
38+
$errors[] = __(
39+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
40+
$urlKey,
41+
implode(', ', $this->urlKey->getRestrictedValues())
42+
);
43+
}
44+
45+
return $errors;
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Model\Validator\UrlKey;
9+
10+
/**
11+
* Interface UrlKeyValidatorInterface is responsive for validating urlKeys
12+
*/
13+
interface UrlKeyValidatorInterface
14+
{
15+
/**
16+
* Validates urlKey
17+
*
18+
* @param string $urlKey
19+
* @return array
20+
*/
21+
public function validate(string $urlKey): array;
22+
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,12 @@
188188
<argument name="anchorRenderer" xsi:type="object">Magento\Backend\Block\AnchorRenderer</argument>
189189
</arguments>
190190
</type>
191+
<type name="Magento\Backend\Model\Validator\UrlKey\CompositeUrlKey">
192+
<arguments>
193+
<argument name="validators" xsi:type="array">
194+
<item name="frontNameValidator" xsi:type="object">Magento\Backend\Model\Validator\UrlKey\FrontName</item>
195+
<item name="restrictedWordsValidator" xsi:type="object">Magento\Backend\Model\Validator\UrlKey\RestrictedWords</item>
196+
</argument>
197+
</arguments>
198+
</type>
191199
</config>

app/code/Magento/Backend/i18n/en_US.csv

+1
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,4 @@ Pagination,Pagination
466466
"Theme Name","Theme Name"
467467
"Use URL parameter to enable template path hints for Storefront","Use URL parameter to enable template path hints for Storefront"
468468
"Add the following parameter to the URL to show template hints ?templatehints=[parameter_value]","Add the following parameter to the URL to show template hints ?templatehints=[parameter_value]"
469+
"URL key "%1" matches a reserved endpoint name (%2). Use another URL key.","URL key "%1" matches a reserved endpoint name (%2). Use another URL key."

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Model;
78

89
use Magento\Framework\App\Filesystem\DirectoryList;
9-
use Magento\Framework\Exception\LocalizedException;
10-
use Magento\Framework\File\Uploader;
1110
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\File\Name;
1313
use Magento\Framework\Filesystem;
1414
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -211,7 +211,7 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
211211
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);
212212

213213
try {
214-
$this->coreFileStorageDatabase->copyFile(
214+
$this->coreFileStorageDatabase->renameFile(
215215
$baseTmpImagePath,
216216
$baseImagePath
217217
);

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,17 @@ public function processFileQueue()
504504
/** @var $uploader \Zend_File_Transfer_Adapter_Http */
505505
$uploader = $queueOptions['uploader'] ?? null;
506506
$isUploaded = false;
507-
if ($uploader && $uploader->isValid()) {
507+
if ($uploader && $uploader->isValid($src)) {
508+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
508509
$path = pathinfo($dst, PATHINFO_DIRNAME);
509510
$uploader = $this->uploaderFactory->create(['fileId' => $src]);
510511
$uploader->setFilesDispersion(false);
511512
$uploader->setAllowRenameFiles(true);
513+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
512514
$isUploaded = $uploader->save($path, pathinfo($dst, PATHINFO_FILENAME));
513515
}
514516

515517
if (empty($src) || empty($dst) || !$isUploaded) {
516-
/**
517-
* @todo: show invalid option
518-
*/
519-
if (isset($queueOptions['option'])) {
520-
$queueOptions['option']->setIsValid(false);
521-
}
522518
throw new \Magento\Framework\Exception\LocalizedException(
523519
__('The file upload failed. Try to upload again.')
524520
);

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

+13-38
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\Exception\NoSuchEntityException;
1818
use Magento\Store\Model\Store;
19+
use Magento\Backend\Model\Validator\UrlKey\CompositeUrlKey;
1920

2021
/**
2122
* Class for set or update url path.
@@ -24,24 +25,17 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
2425
{
2526

2627
/**
27-
* Reserved endpoint names.
28-
*
29-
* @var string[]
30-
*/
31-
private $invalidValues = [];
32-
33-
/**
34-
* @var \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
28+
* @var CategoryUrlPathGenerator
3529
*/
3630
protected $categoryUrlPathGenerator;
3731

3832
/**
39-
* @var \Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider
33+
* @var ChildrenCategoriesProvider
4034
*/
4135
protected $childrenCategoriesProvider;
4236

4337
/**
44-
* @var \Magento\CatalogUrlRewrite\Service\V1\StoreViewService
38+
* @var StoreViewService
4539
*/
4640
protected $storeViewService;
4741

@@ -51,33 +45,29 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
5145
private $categoryRepository;
5246

5347
/**
54-
* @var \Magento\Backend\App\Area\FrontNameResolver
48+
* @var CompositeUrlKey
5549
*/
56-
private $frontNameResolver;
50+
private $compositeUrlValidator;
5751

5852
/**
5953
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
6054
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
61-
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
55+
* @param StoreViewService $storeViewService
6256
* @param CategoryRepositoryInterface $categoryRepository
63-
* @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
64-
* @param string[] $invalidValues
57+
* @param CompositeUrlKey $compositeUrlValidator
6558
*/
6659
public function __construct(
6760
CategoryUrlPathGenerator $categoryUrlPathGenerator,
6861
ChildrenCategoriesProvider $childrenCategoriesProvider,
6962
StoreViewService $storeViewService,
7063
CategoryRepositoryInterface $categoryRepository,
71-
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null,
72-
array $invalidValues = []
64+
CompositeUrlKey $compositeUrlValidator
7365
) {
7466
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
7567
$this->childrenCategoriesProvider = $childrenCategoriesProvider;
7668
$this->storeViewService = $storeViewService;
7769
$this->categoryRepository = $categoryRepository;
78-
$this->frontNameResolver = $frontNameResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
79-
->get(\Magento\Backend\App\Area\FrontNameResolver::class);
80-
$this->invalidValues = $invalidValues;
70+
$this->compositeUrlValidator = $compositeUrlValidator;
8171
}
8272

8373
/**
@@ -161,27 +151,12 @@ private function validateUrlKey(Category $category, ?string $urlKey): void
161151
throw new LocalizedException(__('Invalid URL key'));
162152
}
163153

164-
if (in_array($urlKey, $this->getInvalidValues())) {
165-
throw new LocalizedException(
166-
__(
167-
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
168-
$urlKey,
169-
implode(', ', $this->getInvalidValues())
170-
)
171-
);
154+
$errors = $this->compositeUrlValidator->validate($urlKey);
155+
if (!empty($errors)) {
156+
throw new LocalizedException($errors[0]);
172157
}
173158
}
174159

175-
/**
176-
* Get reserved endpoint names.
177-
*
178-
* @return array
179-
*/
180-
private function getInvalidValues()
181-
{
182-
return array_unique(array_merge($this->invalidValues, [$this->frontNameResolver->getFrontName()]));
183-
}
184-
185160
/**
186161
* Update url path for children category.
187162
*

0 commit comments

Comments
 (0)