Skip to content

Commit f38ee6c

Browse files
Feedback changes
1 parent be69d98 commit f38ee6c

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

MediaGalleryIntegration/Plugin/SaveBaseCategoryImageInformation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ public function afterMoveFileFromTmp(ImageUploader $subject, string $imagePath):
9999
$this->deleteAssetsByPaths->execute([$tmpAssets[0]->getPath()]);
100100
}
101101

102-
$this->saveAsset->execute([$this->createAssetFromFile->execute($file)]);
102+
$createAsset = $this->createAssetFromFile->execute($file);
103+
$this->saveAsset->execute([$createAsset]);
103104
$this->storage->resizeFile($absolutePath);
104-
$this->generateRenditions->execute([$file]);
105+
$this->generateRenditions->execute([$createAsset]);
105106
return $imagePath;
106107
}
107108
}

MediaGalleryIntegration/Plugin/SaveImageInformation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ public function afterSave(Uploader $subject, array $result): array
110110
if (!$this->isApplicable($file->getPathName())) {
111111
return $result;
112112
}
113-
$this->saveAsset->execute([$this->createAssetFromFile->execute($file)]);
113+
$createAsset = $this->createAssetFromFile->execute($file);
114+
$this->saveAsset->execute([$createAsset]);
114115
$this->storage->resizeFile($result['path'] . DIRECTORY_SEPARATOR . $result['file']);
115-
$this->generateRenditions->execute([$file]);
116+
$this->generateRenditions->execute([$createAsset]);
116117
return $result;
117118
}
118119

MediaGalleryRenditions/Model/GenerateRenditions.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\MediaGalleryRenditions\Model;
99

10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem;
1012
use Magento\Framework\Image\AdapterFactory;
13+
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1114
use Magento\MediaGalleryRenditionsApi\Api\GenerateRenditionsInterface;
1215
use Magento\MediaGalleryRenditionsApi\Api\GetRenditionPathInterface;
1316
use Magento\MediaGalleryRenditionsApi\Model\ConfigInterface;
@@ -34,39 +37,47 @@ class GenerateRenditions implements GenerateRenditionsInterface
3437
* @var CreateAssetFromFile
3538
*/
3639
private $createAssetFromFile;
40+
/**
41+
* @var Filesystem
42+
*/
43+
private $filesystem;
3744

3845
/**
3946
* GenerateRenditions constructor.
4047
* @param AdapterFactory $imageFactory
4148
* @param GetRenditionPathInterface $getRenditionPath
4249
* @param CreateAssetFromFile $createAssetFromFile
50+
* @param Filesystem $filesystem
4351
* @param ConfigInterface $config
4452
*/
4553
public function __construct(
4654
AdapterFactory $imageFactory,
4755
GetRenditionPathInterface $getRenditionPath,
4856
CreateAssetFromFile $createAssetFromFile,
57+
Filesystem $filesystem,
4958
ConfigInterface $config
5059
) {
5160
$this->imageFactory = $imageFactory;
5261
$this->config = $config;
5362
$this->getRenditionPath = $getRenditionPath;
5463
$this->createAssetFromFile = $createAssetFromFile;
64+
$this->filesystem = $filesystem;
5565
}
5666

5767
/**
5868
* @inheritDoc
5969
*/
60-
public function execute(array $files): void
70+
public function execute(array $assets): void
6171
{
62-
foreach ($files as $file) {
63-
$path = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFileName();
64-
$asset = $this->createAssetFromFile->execute($file);
72+
/* @var $asset AssetInterface */
73+
foreach ($assets as $asset) {
74+
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
75+
$path = $mediaDirectory->getAbsolutePath($asset->getPath());
6576
if (!$this->isResizeable($asset->getHeight(), $asset->getWidth())) {
6677
continue;
6778
}
6879
$renditionDirectoryPath = $this->getRenditionPath->execute($asset);
69-
$renditionImagePath = $renditionDirectoryPath . DIRECTORY_SEPARATOR . $file->getFileName();
80+
$renditionImagePath = $renditionDirectoryPath . $asset->getPath();
7081
$image = $this->imageFactory->create();
7182
$image->open($path);
7283
$image->keepAspectRatio(true);
@@ -82,7 +93,7 @@ public function execute(array $files): void
8293
* @param int $width
8394
* @return bool
8495
*/
85-
private function isResizeable(int $height, int $width) :bool
96+
private function isResizeable(int $height, int $width): bool
8697
{
8798
return $width > $this->getResizedWidth() || $height > $this->getResizedHeight();
8899
}
@@ -92,7 +103,7 @@ private function isResizeable(int $height, int $width) :bool
92103
*
93104
* @return int
94105
*/
95-
private function getResizedWidth() :int
106+
private function getResizedWidth(): int
96107
{
97108
return $this->config->getWidth();
98109
}

MediaGalleryRenditionsApi/Api/GenerateRenditionsInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ interface GenerateRenditionsInterface
1414
/**
1515
* Generate Renditions image
1616
*
17-
* @param array $paths
17+
* @param array $assets
1818
* @throws LocalizedException
1919
*/
20-
public function execute(array $paths): void;
20+
public function execute(array $assets): void;
2121
}

MediaGallerySynchronization/Model/SynchronizeFiles.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ public function __construct(
9090
public function execute(array $files): void
9191
{
9292
$assets = $this->getExistingAssets($files);
93-
$this->generateRenditions->execute($files);
9493
foreach ($files as $file) {
94+
$createAsset = $this->createAssetFromFile->execute($file);
9595
$path = $this->getFilePath($file);
9696
$time = $this->getFileModificationTime($file);
97+
$this->generateRenditions->execute([$createAsset]);
9798
if (isset($assets[$path]) && $time === $assets[$path]) {
9899
continue;
99100
}
100101
try {
101-
$this->saveAsset->execute([$this->createAssetFromFile->execute($file)]);
102+
$this->saveAsset->execute([$createAsset]);
102103
} catch (\Exception $exception) {
103104
$this->log->critical($exception);
104105
$failedFiles[] = $file->getFilename();

0 commit comments

Comments
 (0)