Skip to content

Commit b15cf7c

Browse files
committed
ACP2E-2152: Error while making concurrent requests to rest/V1/products/<sku>/media
1 parent 197d1de commit b15cf7c

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

app/code/Magento/Catalog/Model/ProductRepository/MediaGalleryProcessor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ public function processMediaGallery(ProductInterface $product, array $mediaGalle
8989
$existingMediaGallery = $product->getMediaGallery('images');
9090
$newEntries = [];
9191
$entriesById = [];
92-
$addMedia = false;
9392
if (!empty($existingMediaGallery)) {
9493
foreach ($mediaGalleryEntries as $entry) {
9594
if (isset($entry['value_id'])) {
9695
$entriesById[$entry['value_id']] = $entry;
9796
} else {
9897
$newEntries[] = $entry;
99-
$addMedia = true;
10098
}
10199
}
102100
foreach ($existingMediaGallery as $key => &$existingEntry) {
@@ -116,7 +114,7 @@ public function processMediaGallery(ProductInterface $product, array $mediaGalle
116114
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
117115
$existingMediaGallery[$key] = array_merge($existingEntry, $updatedEntry);
118116
}
119-
} elseif ($addMedia && isset($existingEntry['value_id'])) {
117+
} elseif (!empty($newEntries) && isset($existingEntry['value_id'])) {
120118
//avoid deleting an exiting image while adding a new one
121119
unset($existingMediaGallery[$key]);
122120
} elseif ($this->canRemoveImage($product, $existingEntry)) {

0 commit comments

Comments
 (0)