77
88namespace Magento \MediaGalleryRenditions \Model ;
99
10+ use Magento \Framework \App \Filesystem \DirectoryList ;
11+ use Magento \Framework \Filesystem ;
1012use Magento \Framework \Image \AdapterFactory ;
13+ use Magento \MediaGalleryApi \Api \Data \AssetInterface ;
1114use Magento \MediaGalleryRenditionsApi \Api \GenerateRenditionsInterface ;
1215use Magento \MediaGalleryRenditionsApi \Api \GetRenditionPathInterface ;
1316use 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 }
0 commit comments