Skip to content

Commit

Permalink
update with 2.4-develop
Browse files Browse the repository at this point in the history
Merge branch '2.4-develop' into add-AdminSetSTockStatusActionGroup
  • Loading branch information
AnnaAPak committed Nov 27, 2020
2 parents b542bd8 + 8c95f07 commit 0b882f3
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 87 deletions.
7 changes: 7 additions & 0 deletions app/code/Magento/Analytics/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
<token/>
</general>
</analytics>
<system>
<media_storage_configuration>
<allowed_resources>
<analytics_folder>analytics</analytics_folder>
</allowed_resources>
</media_storage_configuration>
</system>
</default>
</config>
3 changes: 2 additions & 1 deletion app/code/Magento/AwsS3/Driver/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
* Resolves relative path.
*
* @param string $path Absolute path
* @param bool $fixPath
* @return string Relative path
*/
private function normalizeRelativePath(string $path, bool $fixPath = false): string
Expand Down Expand Up @@ -358,7 +359,7 @@ public function isFile($path): bool
return false;
}

$path = $this->normalizeRelativePath($path, true);;
$path = $this->normalizeRelativePath($path, true);

if ($this->adapter->has($path) && ($meta = $this->adapter->getMetadata($path))) {
return ($meta['type'] ?? null) === self::TYPE_FILE;
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/AwsS3/Driver/AwsS3Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function createConfigured(
throw new DriverException(__('Bucket and region are required values'));
}

if (!empty($config['http_handler'])) {
$config['http_handler'] = $this->objectManager->create($config['http_handler'])($config);
}

$client = new S3Client($config);
$adapter = new AwsS3Adapter($client, $config['bucket'], $prefix);

Expand Down
61 changes: 61 additions & 0 deletions app/code/Magento/AwsS3/Model/HttpLoggerHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AwsS3\Model;

use Aws\Handler\GuzzleV6\GuzzleHandler;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

final class HttpLoggerHandler
{
/**
* @var Filesystem\Directory\WriteInterface
*/
private $directory;

/**
* @var string
*/
private $file;

/**
* @param Filesystem $filesystem
* @param string $file
* @throws FileSystemException
*/
public function __construct(
Filesystem $filesystem,
$file = 'debug/s3.log'
) {
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->file = $file;
}

public function __invoke()
{
$this->directory->create(pathinfo($this->file, PATHINFO_DIRNAME));
$localStream = $this->directory->getDriver()->fileOpen($this->directory->getAbsolutePath($this->file), 'a');
$streamHandler = new StreamHandler($localStream, Logger::DEBUG, true, null, true);
$logger = new \Monolog\Logger('S3', [$streamHandler]);
$stack = HandlerStack::create();
$stack->push(
Middleware::log(
$logger,
new MessageFormatter('{code}:{method}:{target} {error}')
)
);
return new GuzzleHandler(new Client(['handler' => $stack]));
}
}
25 changes: 5 additions & 20 deletions app/code/Magento/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
use Magento\Catalog\Model\View\Asset\ImageFactory;
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Image as MagentoImage;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
use Magento\Framework\Filesystem\Driver\File as FilesystemDriver;

/**
* Image operations
Expand Down Expand Up @@ -202,11 +200,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
*/
private $serializer;

/**
* @var FilesystemDriver
*/
private $filesystemDriver;

/**
* Constructor
*
Expand All @@ -227,7 +220,6 @@ class Image extends \Magento\Framework\Model\AbstractModel
* @param array $data
* @param SerializerInterface $serializer
* @param ParamsBuilder $paramsBuilder
* @param FilesystemDriver $filesystemDriver
* @throws \Magento\Framework\Exception\FileSystemException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
Expand All @@ -249,8 +241,7 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
SerializerInterface $serializer = null,
ParamsBuilder $paramsBuilder = null,
FilesystemDriver $filesystemDriver = null
ParamsBuilder $paramsBuilder = null
) {
$this->_storeManager = $storeManager;
$this->_catalogProductMediaConfig = $catalogProductMediaConfig;
Expand All @@ -265,7 +256,6 @@ public function __construct(
$this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->paramsBuilder = $paramsBuilder ?: ObjectManager::getInstance()->get(ParamsBuilder::class);
$this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance()->get(FilesystemDriver::class);
}

/**
Expand Down Expand Up @@ -675,12 +665,7 @@ public function getDestinationSubdir()
public function isCached()
{
$path = $this->imageAsset->getPath();
try {
$isCached = is_array($this->loadImageInfoFromCache($path)) || $this->filesystemDriver->isExists($path);
} catch (FileSystemException $e) {
$isCached = false;
}
return $isCached;
return is_array($this->loadImageInfoFromCache($path)) || $this->_mediaDirectory->isExist($path);
}

/**
Expand Down Expand Up @@ -952,7 +937,7 @@ private function getImageSize($imagePath)
*/
private function saveImageInfoToCache(array $imageInfo, string $imagePath)
{
$imagePath = $this->cachePrefix . $imagePath;
$imagePath = $this->cachePrefix . $imagePath;
$this->_cacheManager->save(
$this->serializer->serialize($imageInfo),
$imagePath,
Expand All @@ -968,7 +953,7 @@ private function saveImageInfoToCache(array $imageInfo, string $imagePath)
*/
private function loadImageInfoFromCache(string $imagePath)
{
$imagePath = $this->cachePrefix . $imagePath;
$imagePath = $this->cachePrefix . $imagePath;
$cacheData = $this->_cacheManager->load($imagePath);
if (!$cacheData) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Customer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,12 @@
<section_data_lifetime>60</section_data_lifetime>
</online_customers>
</customer>
<system>
<media_storage_configuration>
<allowed_resources>
<customer_address_folder>customer_address</customer_address_folder>
</allowed_resources>
</media_storage_configuration>
</system>
</default>
</config>
42 changes: 25 additions & 17 deletions app/code/Magento/Eav/Model/Attribute/Data/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Eav\Model\Attribute\Data;

use Magento\Framework\Filesystem\ExtendedDriverInterface;

/**
* EAV Entity Attribute Image File Data Model
*
Expand All @@ -21,24 +23,30 @@ class Image extends \Magento\Eav\Model\Attribute\Data\File
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _validateByRules($value)
{
$label = __($this->getAttribute()->getStoreLabel());
$rules = $this->getAttribute()->getValidateRules();
$localStorage = !$this->_directory->getDriver() instanceof ExtendedDriverInterface;
$imageProp = $localStorage
? @getimagesize($value['tmp_name'])
: $this->_directory->getDriver()->getMetadata($value['tmp_name']);
$allowImageTypes = ['gif', 'jpg', 'jpeg', 'png'];
if (!isset($imageProp['extension']) && isset($imageProp[2])) {
$extensionsMap = [1 => 'gif', 2 => 'jpg', 3 => 'png'];
$imageProp['extension'] = $extensionsMap[$imageProp[2]] ?? null;
}

$imageProp = @getimagesize($value['tmp_name']);

$allowImageTypes = [1 => 'gif', 2 => 'jpg', 3 => 'png'];

if (!isset($allowImageTypes[$imageProp[2]])) {
if (!\in_array($imageProp['extension'], $allowImageTypes, true)) {
return [__('"%1" is not a valid image format', $label)];
}

// modify image name
$extension = pathinfo($value['name'], PATHINFO_EXTENSION);
if ($extension != $allowImageTypes[$imageProp[2]]) {
$value['name'] = pathinfo($value['name'], PATHINFO_FILENAME) . '.' . $allowImageTypes[$imageProp[2]];
if ($extension !== $imageProp['extension']) {
$value['name'] = pathinfo($value['name'], PATHINFO_FILENAME) . '.' . $imageProp['extension'];
}

$errors = [];
Expand All @@ -49,17 +57,17 @@ protected function _validateByRules($value)
}
}

if (!empty($rules['max_image_width'])) {
if ($rules['max_image_width'] < $imageProp[0]) {
$r = $rules['max_image_width'];
$errors[] = __('"%1" width exceeds allowed value of %2 px.', $label, $r);
}
$imageWidth = $imageProp['extra']['image-width'] ?? $imageProp[0];
if (!empty($rules['max_image_width']) && !empty($imageWidth)
&& ($rules['max_image_width'] < $imageWidth)) {
$r = $rules['max_image_width'];
$errors[] = __('"%1" width exceeds allowed value of %2 px.', $label, $r);
}
if (!empty($rules['max_image_height'])) {
if ($rules['max_image_height'] < $imageProp[1]) {
$r = $rules['max_image_height'];
$errors[] = __('"%1" height exceeds allowed value of %2 px.', $label, $r);
}
$imageHeight = $imageProp['extra']['image-height'] ?? $imageProp[1];
if (!empty($rules['max_image_height']) && !empty($imageHeight)
&& ($rules['max_image_height'] < $imageHeight)) {
$r = $rules['max_image_height'];
$errors[] = __('"%1" height exceeds allowed value of %2 px.', $label, $r);
}

return $errors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ protected function _prepareForm()
.', e.g. <i>product_images</i>, <i>import_images/batch1</i>.<br><br>'
.'For example, in case <i>product_images</i>, files should be placed into '
.'<i>&lt;Magento root directory&gt;/'
.$this->imagesDirectoryProvider->getDirectoryRelativePath() . '/product_images</i> folder.<br>'
.'<br>If remote storage is enabled, in case <i>product_images</i>, files should be placed into '
.'<i>&lt;Remote Storage&gt;/'
.$this->imagesDirectoryProvider->getDirectoryRelativePath() . '/product_images</i> folder.',
['i', 'br']
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function execute()

return $resultRedirect;
}
$directoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_EXPORT);
$directoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
try {
$directoryWrite->delete($directoryWrite->getAbsolutePath($fileName));
$directoryWrite->delete($directoryWrite->getAbsolutePath() . 'export/' . $fileName);
$this->messageManager->addSuccessMessage(__('File %1 deleted', $fileName));
} catch (ValidatorException $exception) {
$this->messageManager->addErrorMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public function execute()
return $resultRedirect;
}
try {
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_EXPORT);
if ($directory->isFile($fileName)) {
$path = 'export/' . $fileName;
$directory = $this->filesystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
if ($directory->isFile($path)) {
return $this->fileFactory->create(
$fileName,
$directory->readFile($fileName),
DirectoryList::VAR_EXPORT
$path,
$directory->readFile($path),
DirectoryList::VAR_IMPORT_EXPORT
);
}
$this->messageManager->addErrorMessage(__('%1 is not a valid file', $fileName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function execute()
$this->fileFactory->create(
$fileName,
null,
DirectoryList::VAR_DIR,
DirectoryList::VAR_IMPORT_EXPORT,
'application/octet-stream',
$reportHelper->getReportSize($fileName)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function execute()
$this->fileFactory->create(
$fileName,
null,
DirectoryList::VAR_DIR,
DirectoryList::VAR_IMPORT_EXPORT,
'application/octet-stream',
$fileSize
);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/ImportExport/Helper/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
\Magento\Framework\Filesystem $filesystem
) {
$this->timeZone = $timeZone;
$this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
parent::__construct($context);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/ImportExport/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
array $data = []
) {
$this->_logger = $logger;
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->_varDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
parent::__construct($data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractAdapter
public function __construct(
\Magento\Framework\Filesystem $filesystem,
$destination = null,
$destinationDirectoryCode = DirectoryList::VAR_DIR
$destinationDirectoryCode = DirectoryList::VAR_IMPORT_EXPORT
) {
$this->_directoryHandle = $filesystem->getDirectoryWrite($destinationDirectoryCode);
if (!$destination) {
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/ImportExport/Model/Export/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function process(ExportInfoInterface $exportInfo)
try {
$data = $this->exportManager->export($exportInfo);
$fileName = $exportInfo->getFileName();
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_EXPORT);
$directory->writeFile($fileName, $data);
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
$directory->writeFile('export/' . $fileName, $data);

$this->notifier->addMajor(
__('Your export file is ready'),
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/ImportExport/Model/Report/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function createReport(
}
}

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

Expand Down Expand Up @@ -136,7 +136,7 @@ protected function createSourceCsvModel($sourceFile)
return $this->sourceCsvFactory->create(
[
'file' => $sourceFile,
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR),
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT),
'delimiter' => $this->reportHelper->getDelimiter(),
]
);
Expand Down
Loading

0 comments on commit 0b882f3

Please sign in to comment.