Skip to content

Commit daf96d6

Browse files
committed
Merge remote-tracking branch 'mainline/2.4-develop' into 2.4-develop-pr46
2 parents 53821f5 + 8c95f07 commit daf96d6

File tree

28 files changed

+213
-87
lines changed

28 files changed

+213
-87
lines changed

app/code/Magento/Analytics/etc/config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@
2323
<token/>
2424
</general>
2525
</analytics>
26+
<system>
27+
<media_storage_configuration>
28+
<allowed_resources>
29+
<analytics_folder>analytics</analytics_folder>
30+
</allowed_resources>
31+
</media_storage_configuration>
32+
</system>
2633
</default>
2734
</config>

app/code/Magento/AwsS3/Driver/AwsS3.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
304304
* Resolves relative path.
305305
*
306306
* @param string $path Absolute path
307+
* @param bool $fixPath
307308
* @return string Relative path
308309
*/
309310
private function normalizeRelativePath(string $path, bool $fixPath = false): string
@@ -358,7 +359,7 @@ public function isFile($path): bool
358359
return false;
359360
}
360361

361-
$path = $this->normalizeRelativePath($path, true);;
362+
$path = $this->normalizeRelativePath($path, true);
362363

363364
if ($this->adapter->has($path) && ($meta = $this->adapter->getMetadata($path))) {
364365
return ($meta['type'] ?? null) === self::TYPE_FILE;

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function createConfigured(
8686
throw new DriverException(__('Bucket and region are required values'));
8787
}
8888

89+
if (!empty($config['http_handler'])) {
90+
$config['http_handler'] = $this->objectManager->create($config['http_handler'])($config);
91+
}
92+
8993
$client = new S3Client($config);
9094
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);
9195

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\AwsS3\Model;
9+
10+
use Aws\Handler\GuzzleV6\GuzzleHandler;
11+
use GuzzleHttp\Client;
12+
use GuzzleHttp\HandlerStack;
13+
use GuzzleHttp\MessageFormatter;
14+
use GuzzleHttp\Middleware;
15+
use Magento\Framework\App\Filesystem\DirectoryList;
16+
use Magento\Framework\Exception\FileSystemException;
17+
use Magento\Framework\Filesystem;
18+
use Monolog\Handler\StreamHandler;
19+
use Monolog\Logger;
20+
21+
final class HttpLoggerHandler
22+
{
23+
/**
24+
* @var Filesystem\Directory\WriteInterface
25+
*/
26+
private $directory;
27+
28+
/**
29+
* @var string
30+
*/
31+
private $file;
32+
33+
/**
34+
* @param Filesystem $filesystem
35+
* @param string $file
36+
* @throws FileSystemException
37+
*/
38+
public function __construct(
39+
Filesystem $filesystem,
40+
$file = 'debug/s3.log'
41+
) {
42+
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
43+
$this->file = $file;
44+
}
45+
46+
public function __invoke()
47+
{
48+
$this->directory->create(pathinfo($this->file, PATHINFO_DIRNAME));
49+
$localStream = $this->directory->getDriver()->fileOpen($this->directory->getAbsolutePath($this->file), 'a');
50+
$streamHandler = new StreamHandler($localStream, Logger::DEBUG, true, null, true);
51+
$logger = new \Monolog\Logger('S3', [$streamHandler]);
52+
$stack = HandlerStack::create();
53+
$stack->push(
54+
Middleware::log(
55+
$logger,
56+
new MessageFormatter('{code}:{method}:{target} {error}')
57+
)
58+
);
59+
return new GuzzleHandler(new Client(['handler' => $stack]));
60+
}
61+
}

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
namespace Magento\Catalog\Model\Product;
77

88
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
9+
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
910
use Magento\Catalog\Model\View\Asset\ImageFactory;
1011
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
1112
use Magento\Framework\App\Filesystem\DirectoryList;
1213
use Magento\Framework\App\ObjectManager;
13-
use Magento\Framework\Exception\FileSystemException;
1414
use Magento\Framework\Image as MagentoImage;
1515
use Magento\Framework\Serialize\SerializerInterface;
16-
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
17-
use Magento\Framework\Filesystem\Driver\File as FilesystemDriver;
1816

1917
/**
2018
* Image operations
@@ -202,11 +200,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
202200
*/
203201
private $serializer;
204202

205-
/**
206-
* @var FilesystemDriver
207-
*/
208-
private $filesystemDriver;
209-
210203
/**
211204
* Constructor
212205
*
@@ -227,7 +220,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
227220
* @param array $data
228221
* @param SerializerInterface $serializer
229222
* @param ParamsBuilder $paramsBuilder
230-
* @param FilesystemDriver $filesystemDriver
231223
* @throws \Magento\Framework\Exception\FileSystemException
232224
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
233225
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
@@ -249,8 +241,7 @@ public function __construct(
249241
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
250242
array $data = [],
251243
SerializerInterface $serializer = null,
252-
ParamsBuilder $paramsBuilder = null,
253-
FilesystemDriver $filesystemDriver = null
244+
ParamsBuilder $paramsBuilder = null
254245
) {
255246
$this->_storeManager = $storeManager;
256247
$this->_catalogProductMediaConfig = $catalogProductMediaConfig;
@@ -265,7 +256,6 @@ public function __construct(
265256
$this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory;
266257
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
267258
$this->paramsBuilder = $paramsBuilder ?: ObjectManager::getInstance()->get(ParamsBuilder::class);
268-
$this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance()->get(FilesystemDriver::class);
269259
}
270260

271261
/**
@@ -675,12 +665,7 @@ public function getDestinationSubdir()
675665
public function isCached()
676666
{
677667
$path = $this->imageAsset->getPath();
678-
try {
679-
$isCached = is_array($this->loadImageInfoFromCache($path)) || $this->filesystemDriver->isExists($path);
680-
} catch (FileSystemException $e) {
681-
$isCached = false;
682-
}
683-
return $isCached;
668+
return is_array($this->loadImageInfoFromCache($path)) || $this->_mediaDirectory->isExist($path);
684669
}
685670

686671
/**
@@ -952,7 +937,7 @@ private function getImageSize($imagePath)
952937
*/
953938
private function saveImageInfoToCache(array $imageInfo, string $imagePath)
954939
{
955-
$imagePath = $this->cachePrefix . $imagePath;
940+
$imagePath = $this->cachePrefix . $imagePath;
956941
$this->_cacheManager->save(
957942
$this->serializer->serialize($imageInfo),
958943
$imagePath,
@@ -968,7 +953,7 @@ private function saveImageInfoToCache(array $imageInfo, string $imagePath)
968953
*/
969954
private function loadImageInfoFromCache(string $imagePath)
970955
{
971-
$imagePath = $this->cachePrefix . $imagePath;
956+
$imagePath = $this->cachePrefix . $imagePath;
972957
$cacheData = $this->_cacheManager->load($imagePath);
973958
if (!$cacheData) {
974959
return false;

app/code/Magento/Customer/etc/config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,12 @@
103103
<section_data_lifetime>60</section_data_lifetime>
104104
</online_customers>
105105
</customer>
106+
<system>
107+
<media_storage_configuration>
108+
<allowed_resources>
109+
<customer_address_folder>customer_address</customer_address_folder>
110+
</allowed_resources>
111+
</media_storage_configuration>
112+
</system>
106113
</default>
107114
</config>

app/code/Magento/Eav/Model/Attribute/Data/Image.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Eav\Model\Attribute\Data;
77

8+
use Magento\Framework\Filesystem\ExtendedDriverInterface;
9+
810
/**
911
* EAV Entity Attribute Image File Data Model
1012
*
@@ -21,24 +23,30 @@ class Image extends \Magento\Eav\Model\Attribute\Data\File
2123
* @return array
2224
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2325
* @SuppressWarnings(PHPMD.NPathComplexity)
26+
* @throws \Magento\Framework\Exception\LocalizedException
2427
*/
2528
protected function _validateByRules($value)
2629
{
2730
$label = __($this->getAttribute()->getStoreLabel());
2831
$rules = $this->getAttribute()->getValidateRules();
32+
$localStorage = !$this->_directory->getDriver() instanceof ExtendedDriverInterface;
33+
$imageProp = $localStorage
34+
? @getimagesize($value['tmp_name'])
35+
: $this->_directory->getDriver()->getMetadata($value['tmp_name']);
36+
$allowImageTypes = ['gif', 'jpg', 'jpeg', 'png'];
37+
if (!isset($imageProp['extension']) && isset($imageProp[2])) {
38+
$extensionsMap = [1 => 'gif', 2 => 'jpg', 3 => 'png'];
39+
$imageProp['extension'] = $extensionsMap[$imageProp[2]] ?? null;
40+
}
2941

30-
$imageProp = @getimagesize($value['tmp_name']);
31-
32-
$allowImageTypes = [1 => 'gif', 2 => 'jpg', 3 => 'png'];
33-
34-
if (!isset($allowImageTypes[$imageProp[2]])) {
42+
if (!\in_array($imageProp['extension'], $allowImageTypes, true)) {
3543
return [__('"%1" is not a valid image format', $label)];
3644
}
3745

3846
// modify image name
3947
$extension = pathinfo($value['name'], PATHINFO_EXTENSION);
40-
if ($extension != $allowImageTypes[$imageProp[2]]) {
41-
$value['name'] = pathinfo($value['name'], PATHINFO_FILENAME) . '.' . $allowImageTypes[$imageProp[2]];
48+
if ($extension !== $imageProp['extension']) {
49+
$value['name'] = pathinfo($value['name'], PATHINFO_FILENAME) . '.' . $imageProp['extension'];
4250
}
4351

4452
$errors = [];
@@ -49,17 +57,17 @@ protected function _validateByRules($value)
4957
}
5058
}
5159

52-
if (!empty($rules['max_image_width'])) {
53-
if ($rules['max_image_width'] < $imageProp[0]) {
54-
$r = $rules['max_image_width'];
55-
$errors[] = __('"%1" width exceeds allowed value of %2 px.', $label, $r);
56-
}
60+
$imageWidth = $imageProp['extra']['image-width'] ?? $imageProp[0];
61+
if (!empty($rules['max_image_width']) && !empty($imageWidth)
62+
&& ($rules['max_image_width'] < $imageWidth)) {
63+
$r = $rules['max_image_width'];
64+
$errors[] = __('"%1" width exceeds allowed value of %2 px.', $label, $r);
5765
}
58-
if (!empty($rules['max_image_height'])) {
59-
if ($rules['max_image_height'] < $imageProp[1]) {
60-
$r = $rules['max_image_height'];
61-
$errors[] = __('"%1" height exceeds allowed value of %2 px.', $label, $r);
62-
}
66+
$imageHeight = $imageProp['extra']['image-height'] ?? $imageProp[1];
67+
if (!empty($rules['max_image_height']) && !empty($imageHeight)
68+
&& ($rules['max_image_height'] < $imageHeight)) {
69+
$r = $rules['max_image_height'];
70+
$errors[] = __('"%1" height exceeds allowed value of %2 px.', $label, $r);
6371
}
6472

6573
return $errors;

app/code/Magento/ImportExport/Block/Adminhtml/Import/Edit/Form.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ protected function _prepareForm()
248248
.', e.g. <i>product_images</i>, <i>import_images/batch1</i>.<br><br>'
249249
.'For example, in case <i>product_images</i>, files should be placed into '
250250
.'<i>&lt;Magento root directory&gt;/'
251+
.$this->imagesDirectoryProvider->getDirectoryRelativePath() . '/product_images</i> folder.<br>'
252+
.'<br>If remote storage is enabled, in case <i>product_images</i>, files should be placed into '
253+
.'<i>&lt;Remote Storage&gt;/'
251254
.$this->imagesDirectoryProvider->getDirectoryRelativePath() . '/product_images</i> folder.',
252255
['i', 'br']
253256
)

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public function execute()
7070

7171
return $resultRedirect;
7272
}
73-
$directoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_EXPORT);
73+
$directoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
7474
try {
75-
$directoryWrite->delete($directoryWrite->getAbsolutePath($fileName));
75+
$directoryWrite->delete($directoryWrite->getAbsolutePath() . 'export/' . $fileName);
7676
$this->messageManager->addSuccessMessage(__('File %1 deleted', $fileName));
7777
} catch (ValidatorException $exception) {
7878
$this->messageManager->addErrorMessage(

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ public function execute()
6767
return $resultRedirect;
6868
}
6969
try {
70-
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_EXPORT);
71-
if ($directory->isFile($fileName)) {
70+
$path = 'export/' . $fileName;
71+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
72+
if ($directory->isFile($path)) {
7273
return $this->fileFactory->create(
73-
$fileName,
74-
$directory->readFile($fileName),
75-
DirectoryList::VAR_EXPORT
74+
$path,
75+
$directory->readFile($path),
76+
DirectoryList::VAR_IMPORT_EXPORT
7677
);
7778
}
7879
$this->messageManager->addErrorMessage(__('%1 is not a valid file', $fileName));

app/code/Magento/ImportExport/Controller/Adminhtml/History/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function execute()
6262
$this->fileFactory->create(
6363
$fileName,
6464
null,
65-
DirectoryList::VAR_DIR,
65+
DirectoryList::VAR_IMPORT_EXPORT,
6666
'application/octet-stream',
6767
$reportHelper->getReportSize($fileName)
6868
);

app/code/Magento/ImportExport/Controller/Adminhtml/Import/Download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function execute()
109109
$this->fileFactory->create(
110110
$fileName,
111111
null,
112-
DirectoryList::VAR_DIR,
112+
DirectoryList::VAR_IMPORT_EXPORT,
113113
'application/octet-stream',
114114
$fileSize
115115
);

app/code/Magento/ImportExport/Helper/Report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
\Magento\Framework\Filesystem $filesystem
4141
) {
4242
$this->timeZone = $timeZone;
43-
$this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
43+
$this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
4444
parent::__construct($context);
4545
}
4646

app/code/Magento/ImportExport/Model/AbstractModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(
5656
array $data = []
5757
) {
5858
$this->_logger = $logger;
59-
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
59+
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
6060
parent::__construct($data);
6161
}
6262

app/code/Magento/ImportExport/Model/Export/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class AbstractAdapter
4646
public function __construct(
4747
\Magento\Framework\Filesystem $filesystem,
4848
$destination = null,
49-
$destinationDirectoryCode = DirectoryList::VAR_DIR
49+
$destinationDirectoryCode = DirectoryList::VAR_IMPORT_EXPORT
5050
) {
5151
$this->_directoryHandle = $filesystem->getDirectoryWrite($destinationDirectoryCode);
5252
if (!$destination) {

app/code/Magento/ImportExport/Model/Export/Consumer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function process(ExportInfoInterface $exportInfo)
7070
try {
7171
$data = $this->exportManager->export($exportInfo);
7272
$fileName = $exportInfo->getFileName();
73-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_EXPORT);
74-
$directory->writeFile($fileName, $data);
73+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
74+
$directory->writeFile('export/' . $fileName, $data);
7575

7676
$this->notifier->addMajor(
7777
__('Your export file is ready'),

app/code/Magento/ImportExport/Model/Report/Csv.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function createReport(
8383
}
8484
}
8585

86-
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
86+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
8787
$outputFileName = $this->generateOutputFileName($originalFileName);
8888
$directory->writeFile(Import::IMPORT_HISTORY_DIR . $outputFileName, $outputCsv->getContents());
8989

@@ -136,7 +136,7 @@ protected function createSourceCsvModel($sourceFile)
136136
return $this->sourceCsvFactory->create(
137137
[
138138
'file' => $sourceFile,
139-
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR),
139+
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT),
140140
'delimiter' => $this->reportHelper->getDelimiter(),
141141
]
142142
);

0 commit comments

Comments
 (0)