Skip to content

Commit 766772b

Browse files
committed
Merge remote-tracking branch 'upstream/2.3.0-release' into 2.3.0-release-sync
2 parents f710f9b + 4220e6e commit 766772b

File tree

365 files changed

+8000
-3296
lines changed

Some content is hidden

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

365 files changed

+8000
-3296
lines changed

app/code/Magento/Backend/view/adminhtml/web/js/validate-store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ define([
6767
* 'Confirm' action handler.
6868
*/
6969
confirm: function () {
70+
$('body').trigger('processStart');
7071
dataPost().postData(requestData);
7172
}
7273
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public function __construct(array $blackList = [])
2727

2828
/**
2929
* Delete custom attribute
30-
* @param array $attributes
30+
*
31+
* @param array $attributes set objects attributes @example ['attribute_code'=>'attribute_object']
3132
* @return array
3233
*/
3334
public function execute(array $attributes): array
3435
{
35-
return array_diff($attributes, $this->blackList);
36+
return array_diff_key($attributes, array_flip($this->blackList));
3637
}
3738
}

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,17 @@ protected function _getResource()
512512
protected function getCustomAttributesCodes()
513513
{
514514
if ($this->customAttributesCodes === null) {
515-
$this->customAttributesCodes = array_keys($this->eavConfig->getEntityAttributes(
516-
self::ENTITY,
517-
$this
518-
));
519-
520-
$this->customAttributesCodes = $this->filterCustomAttribute->execute($this->customAttributesCodes);
521-
$this->customAttributesCodes = array_diff($this->customAttributesCodes, ProductInterface::ATTRIBUTES);
515+
$this->customAttributesCodes = array_diff(
516+
array_keys(
517+
$this->filterCustomAttribute->execute(
518+
$this->eavConfig->getEntityAttributes(
519+
self::ENTITY,
520+
$this
521+
)
522+
)
523+
),
524+
ProductInterface::ATTRIBUTES
525+
);
522526
}
523527

524528
return $this->customAttributesCodes;
@@ -596,7 +600,6 @@ public function getPrice()
596600
* @see \Magento\Catalog\Model\Product\Visibility
597601
*
598602
* @return int
599-
* @codeCoverageIgnoreStart
600603
*/
601604
public function getVisibility()
602605
{
@@ -1053,7 +1056,7 @@ public function reindex()
10531056
*
10541057
* Register indexing event before delete product
10551058
*
1056-
* @return $this
1059+
* @return \Magento\Catalog\Model\Product
10571060
* @throws \Magento\Framework\Exception\LocalizedException
10581061
*/
10591062
public function beforeDelete()
@@ -1567,6 +1570,7 @@ public function hasGalleryAttribute()
15671570
* @param bool $move if true, it will move source file
15681571
* @param bool $exclude mark image as disabled in product page view
15691572
* @return \Magento\Catalog\Model\Product
1573+
* @throws \Magento\Framework\Exception\LocalizedException
15701574
*/
15711575
public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
15721576
{
@@ -1818,7 +1822,7 @@ public function formatUrlKey($str)
18181822
/**
18191823
* Save current attribute with code $code and assign new value
18201824
*
1821-
* @param string $code Attribute code
1825+
* @param string $code Attribute code
18221826
* @param mixed $value New attribute value
18231827
* @param int $store Store ID
18241828
* @return void
@@ -2230,9 +2234,9 @@ public function getPreconfiguredValues()
22302234
}
22312235

22322236
/**
2233-
* Prepare product custom options
2237+
* Prepare product custom options.
22342238
*
2235-
* To be sure that all product custom options does not has ID and has product instance.
2239+
* To be sure that all product custom options does not has ID and has product instance
22362240
*
22372241
* @return \Magento\Catalog\Model\Product
22382242
*/
@@ -2568,7 +2572,7 @@ public function setTypeId($typeId)
25682572
/**
25692573
* @inheritdoc
25702574
*
2571-
* @return \Magento\Catalog\Api\Data\ProductExtensionInterface
2575+
* @return \Magento\Framework\Api\ExtensionAttributesInterface
25722576
*/
25732577
public function getExtensionAttributes()
25742578
{
@@ -2609,7 +2613,7 @@ protected function convertToMediaGalleryInterface(array $mediaGallery)
26092613
}
26102614

26112615
/**
2612-
* Returns media gallery entries
2616+
* Get media gallery entries
26132617
*
26142618
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]|null
26152619
* @throws \Magento\Framework\Exception\LocalizedException
@@ -2671,7 +2675,7 @@ public function setId($value)
26712675
}
26722676

26732677
/**
2674-
* Returns link repository instance
2678+
* Get link repository
26752679
*
26762680
* @return ProductLinkRepositoryInterface
26772681
*/
@@ -2685,7 +2689,7 @@ private function getLinkRepository()
26852689
}
26862690

26872691
/**
2688-
* Returns media gallery processor instance
2692+
* Get media gallery processor
26892693
*
26902694
* @return Product\Gallery\Processor
26912695
*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\Product\Option\Type\File;
10+
11+
/**
12+
* Validator for existing (already saved) files.
13+
*/
14+
class ExistingValidate extends \Zend_Validate
15+
{
16+
/**
17+
* @inheritDoc
18+
*
19+
* @param string $value File's full path.
20+
* @param string|null $originalName Original file's name (when uploaded).
21+
*/
22+
public function isValid($value, string $originalName = null)
23+
{
24+
$this->_messages = [];
25+
$this->_errors = [];
26+
27+
if (!is_string($value)) {
28+
$this->_messages[] = __('Full file path is expected.')->render();
29+
return false;
30+
}
31+
32+
$result = true;
33+
$fileInfo = null;
34+
if ($originalName) {
35+
$fileInfo = ['name' => $originalName];
36+
}
37+
foreach ($this->_validators as $element) {
38+
$validator = $element['instance'];
39+
if ($validator->isValid($value, $fileInfo)) {
40+
continue;
41+
}
42+
$result = false;
43+
$messages = $validator->getMessages();
44+
$this->_messages = array_merge($this->_messages, $messages);
45+
$this->_errors = array_merge($this->_errors, array_keys($messages));
46+
if ($element['breakChainOnFailure']) {
47+
break;
48+
}
49+
}
50+
return $result;
51+
}
52+
}

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidateFactory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66

77
namespace Magento\Catalog\Model\Product\Option\Type\File;
88

9+
/**
10+
* Class ValidateFactory. Creates Validator with type "ExistingValidate"
11+
*/
912
class ValidateFactory
1013
{
1114
/**
15+
* Main factory method
16+
*
1217
* @return \Zend_Validate
1318
*/
1419
public function create()
1520
{
16-
return new \Zend_Validate();
21+
return new ExistingValidate();
1722
}
1823
}

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Catalog\Model\Product\Exception as ProductException;
1212
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Math\Random;
14+
use Magento\Framework\App\ObjectManager;
1315

1416
/**
17+
* Validator class. Represents logic for validation file given from product option
18+
*
1519
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1620
*/
1721
class ValidatorFile extends Validator
@@ -63,28 +67,41 @@ class ValidatorFile extends Validator
6367
protected $isImageValidator;
6468

6569
/**
70+
* @var Random
71+
*/
72+
private $random;
73+
74+
/**
75+
* Constructor method
76+
*
6677
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
6778
* @param \Magento\Framework\Filesystem $filesystem
6879
* @param \Magento\Framework\File\Size $fileSize
6980
* @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
7081
* @param \Magento\Framework\Validator\File\IsImage $isImageValidator
82+
* @param Random|null $random
7183
* @throws \Magento\Framework\Exception\FileSystemException
7284
*/
7385
public function __construct(
7486
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
7587
\Magento\Framework\Filesystem $filesystem,
7688
\Magento\Framework\File\Size $fileSize,
7789
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
78-
\Magento\Framework\Validator\File\IsImage $isImageValidator
90+
\Magento\Framework\Validator\File\IsImage $isImageValidator,
91+
Random $random = null
7992
) {
8093
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
8194
$this->filesystem = $filesystem;
8295
$this->httpFactory = $httpFactory;
8396
$this->isImageValidator = $isImageValidator;
97+
$this->random = $random
98+
?? ObjectManager::getInstance()->get(Random::class);
8499
parent::__construct($scopeConfig, $filesystem, $fileSize);
85100
}
86101

87102
/**
103+
* Setter method for the product
104+
*
88105
* @param Product $product
89106
* @return $this
90107
*/
@@ -95,6 +112,8 @@ public function setProduct(Product $product)
95112
}
96113

97114
/**
115+
* Validation method
116+
*
98117
* @param \Magento\Framework\DataObject $processingParams
99118
* @param \Magento\Catalog\Model\Product\Option $option
100119
* @return array
@@ -154,16 +173,15 @@ public function validate($processingParams, $option)
154173
$userValue = [];
155174

156175
if ($upload->isUploaded($file) && $upload->isValid($file)) {
157-
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
158-
159176
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
160177
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
161178

162179
$filePath = $dispersion;
163180

164181
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
165182
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
166-
$filePath .= '/' . $fileHash . '.' . $extension;
183+
$fileRandomName = $this->random->getRandomString(32);
184+
$filePath .= '/' .$fileRandomName;
167185
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
168186

169187
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));
@@ -243,6 +261,8 @@ protected function initFilesystem()
243261
}
244262

245263
/**
264+
* Validate contents length method
265+
*
246266
* @return bool
247267
* @todo need correctly name
248268
*/

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorInfo.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Catalog\Model\Product\Option\Type\File;
88

9+
/**
10+
* Validator for existing files.
11+
*/
912
class ValidatorInfo extends Validator
1013
{
1114
/**
@@ -34,6 +37,8 @@ class ValidatorInfo extends Validator
3437
protected $fileRelativePath;
3538

3639
/**
40+
* Construct method
41+
*
3742
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3843
* @param \Magento\Framework\Filesystem $filesystem
3944
* @param \Magento\Framework\File\Size $fileSize
@@ -53,6 +58,8 @@ public function __construct(
5358
}
5459

5560
/**
61+
* Setter method for property "useQuotePath"
62+
*
5663
* @param mixed $useQuotePath
5764
* @return $this
5865
*/
@@ -63,6 +70,8 @@ public function setUseQuotePath($useQuotePath)
6370
}
6471

6572
/**
73+
* Validate method for the option value depends on an option
74+
*
6675
* @param array $optionValue
6776
* @param \Magento\Catalog\Model\Product\Option $option
6877
* @return bool
@@ -90,7 +99,7 @@ public function validate($optionValue, $option)
9099
}
91100

92101
$result = false;
93-
if ($validatorChain->isValid($this->fileFullPath)) {
102+
if ($validatorChain->isValid($this->fileFullPath, $optionValue['title'])) {
94103
$result = $this->rootDirectory->isReadable($this->fileRelativePath)
95104
&& isset($optionValue['secret_key'])
96105
&& $this->buildSecretKey($this->fileRelativePath) == $optionValue['secret_key'];
@@ -109,6 +118,8 @@ public function validate($optionValue, $option)
109118
}
110119

111120
/**
121+
* Method for creation secret key for the given file
122+
*
112123
* @param string $fileRelativePath
113124
* @return string
114125
*/
@@ -118,6 +129,8 @@ protected function buildSecretKey($fileRelativePath)
118129
}
119130

120131
/**
132+
* Calculates path for the file
133+
*
121134
* @param array $optionValue
122135
* @return void
123136
*/

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductAttributeActionGroup.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@
4242
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute"/>
4343
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the product attribute." stepKey="successMessage"/>
4444
</actionGroup>
45+
<actionGroup name="deleteProductAttribute" extends="navigateToCreatedProductAttribute">
46+
<click selector="{{AttributePropertiesSection.DeleteAttribute}}" stepKey="deleteAttribute"/>
47+
<click selector="{{ModalConfirmationSection.OkButton}}" stepKey="ClickOnDeleteButton"/>
48+
<waitForPageLoad stepKey="waitForPageLoad"/>
49+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}"
50+
stepKey="waitForSuccessMessage"/>
51+
</actionGroup>
4552
</actionGroups>

0 commit comments

Comments
 (0)