Skip to content

Commit 77930ad

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-93085' into 2.1.15-bugfixes-010818
2 parents b694eb3 + 97ae703 commit 77930ad

File tree

4 files changed

+63
-4
lines changed

4 files changed

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ class ValidateFactory
1313
*/
1414
public function create()
1515
{
16-
return new \Zend_Validate();
16+
return new ExistingValidate();
1717
}
1818
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ public function validate($processingParams, $option)
164164
$filePath = $dispersion;
165165

166166
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
167-
$fileHash = $this->random->getRandomString(32);
168-
$filePath .= '/' . $fileHash;
167+
$fileHash = hash(
168+
'md5',
169+
$tmpDirectory->readFile(
170+
$tmpDirectory->getRelativePath($fileInfo['tmp_name'])
171+
)
172+
);
173+
$fileRandomName = $this->random->getRandomString(32);
174+
$filePath .= '/' . $fileRandomName;
169175
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
170176

171177
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));

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

Lines changed: 4 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
/**
@@ -90,7 +93,7 @@ public function validate($optionValue, $option)
9093
}
9194

9295
$result = false;
93-
if ($validatorChain->isValid($this->fileFullPath)) {
96+
if ($validatorChain->isValid($this->fileFullPath, $optionValue['title'])) {
9497
$result = $this->rootDirectory->isReadable($this->fileRelativePath)
9598
&& isset($optionValue['secret_key'])
9699
&& $this->buildSecretKey($this->fileRelativePath) == $optionValue['secret_key'];

0 commit comments

Comments
 (0)