Skip to content

Commit 3088085

Browse files
committed
ACP2E-2568: Image file is Case insensitive in Pagebuilder(Image not showing in Media Gallery when upload both lowercase and uppercase image with same name)
1 parent 9e2eb99 commit 3088085

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

app/code/Magento/MediaGallery/Model/ResourceModel/DeleteAssetsByPaths.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DeleteAssetsByPaths implements DeleteAssetsByPathsInterface
2020
{
2121
private const TABLE_MEDIA_GALLERY_ASSET = 'media_gallery_asset';
2222
private const MEDIA_GALLERY_ASSET_PATH = 'path';
23+
private const MEDIA_GALLERY_ASSET_ID = 'id';
2324

2425
/**
2526
* @var ResourceConnection
@@ -78,13 +79,39 @@ public function execute(array $paths): void
7879
* Delete assets from database based on the first part (beginning) of the path
7980
*
8081
* @param string $path
82+
* @throws \Zend_Db_Statement_Exception
8183
*/
8284
private function deleteAssetsByDirectoryPath(string $path): void
85+
{
86+
/** @var AdapterInterface $connection */
87+
$connection = $this->resourceConnection->getConnection();
88+
89+
$select = $connection->select()
90+
->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET))
91+
->where(self::MEDIA_GALLERY_ASSET_PATH . ' LIKE ?', $path . '%');
92+
93+
$assets = $connection->query($select)->fetchAll();
94+
95+
// Filter out assets with mixed case that doesn't match the paths
96+
foreach ($assets as $asset) {
97+
if (str_starts_with($asset[self::MEDIA_GALLERY_ASSET_PATH], $path)) {
98+
$this->deleteAssetById((int)$asset[self::MEDIA_GALLERY_ASSET_ID]);
99+
}
100+
}
101+
}
102+
103+
/**
104+
* Delete assets from database by asset id
105+
*
106+
* @param int $id
107+
* @return void
108+
*/
109+
private function deleteAssetById(int $id): void
83110
{
84111
/** @var AdapterInterface $connection */
85112
$connection = $this->resourceConnection->getConnection();
86113
$tableName = $this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET);
87-
$connection->delete($tableName, [self::MEDIA_GALLERY_ASSET_PATH . ' LIKE ?' => $path . '%']);
114+
$connection->delete($tableName, [self::MEDIA_GALLERY_ASSET_ID . ' = ?' => $id]);
88115
}
89116

90117
/**

app/code/Magento/MediaGallery/Model/ResourceModel/GetAssetsByPaths.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,29 @@ private function getAssetsData(array $paths): array
105105
$select = $connection->select()
106106
->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET))
107107
->where(self::MEDIA_GALLERY_ASSET_PATH . ' IN (?)', $paths);
108-
return $connection->query($select)->fetchAll();
108+
$assets = $connection->query($select)->fetchAll();
109+
110+
return $this->filterCaseSensitiveAssets($assets, $paths);
111+
}
112+
113+
/**
114+
* Filter out assets with mixed case that doesn't match the paths
115+
*
116+
* @param array $assets
117+
* @param array $paths
118+
* @return array
119+
*/
120+
private function filterCaseSensitiveAssets(array $assets, array $paths): array
121+
{
122+
$filteredAssets = [];
123+
foreach ($assets as $asset) {
124+
foreach ($paths as $path) {
125+
if ($asset[self::MEDIA_GALLERY_ASSET_PATH] === $path) {
126+
$filteredAssets[] = $asset;
127+
}
128+
}
129+
}
130+
131+
return $filteredAssets;
109132
}
110133
}

0 commit comments

Comments
 (0)