Skip to content

Commit 1904a1f

Browse files
committed
ACP2E-2970: Old media gallery fails to render images when a 0-byte image is placed in the directory
1 parent cf6f6af commit 1904a1f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
1414
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\Data\Collection;
1516
use Magento\Framework\Exception\LocalizedException;
1617

1718
/**
@@ -289,6 +290,7 @@ protected function createSubDirectories($path)
289290
*
290291
* @return array
291292
* @deprecated
293+
* @see isDirectoryAllowed
292294
*/
293295
protected function getConditionsForExcludeDirs()
294296
{
@@ -317,6 +319,7 @@ protected function getConditionsForExcludeDirs()
317319
* @param array $conditions
318320
* @return \Magento\Framework\Data\Collection\Filesystem
319321
* @deprecated
322+
* @see \Magento\Framework\Data\Collection\Filesystem::setDirsFilter
320323
*/
321324
protected function removeItemFromCollection($collection, $conditions)
322325
{
@@ -415,7 +418,7 @@ public function getFilesCollection($path, $type = null)
415418
$mimeType = $itemStats['mimetype'] ?? $this->mime->getMimeType($item->getFilename());
416419
$item->setMimeType($mimeType);
417420

418-
if ($this->isImage($item->getBasename()) && $item->getSize() > 0) {
421+
if ($this->isImageValid($item)) {
419422
$thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
420423
// generate thumbnail "on the fly" if it does not exists
421424
if (!$thumbUrl) {
@@ -1064,4 +1067,15 @@ private function getAllowedDirMask(string $path)
10641067

10651068
return '/^(' . implode('|', array_unique(array_column($allowedDirs, $subfolderLevel - 1))) . ')$/';
10661069
}
1070+
1071+
/**
1072+
* Checks if the file is an image and has a size greater than 0 to validate it can be processes in the gallery.
1073+
*
1074+
* @param Collection $item
1075+
* @return bool
1076+
*/
1077+
private function isImageValid($item)
1078+
{
1079+
return $this->isImage($item->getBasename()) && $item->getSize() > 0;
1080+
}
10671081
}

0 commit comments

Comments
 (0)