magento/magento2#33031: Add product images import mode for CSV gallery replace - #41088
Open
swnsma wants to merge 4 commits into
Open
magento/magento2#33031: Add product images import mode for CSV gallery replace#41088swnsma wants to merge 4 commits into
swnsma wants to merge 4 commits into
Conversation
Add an opt-in Import job setting (add|replace, default add) so Add/Update product imports can remove gallery images not listed in additional_images without changing default append behaviour. Roles stay protected when their columns are omitted; replace is a no-op when additional_images is absent. Includes GraphQL cache invalidation, admin UI visibility, and tests.
|
Hi @swnsma. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Move replace-mode gallery reconciliation into MediaGalleryReplaceCoordinator and MediaGalleryReplaceRolePlan so Product import only drives the lifecycle (configure, plan roles, warm cache, register, keep paths, deferred removals). Protect multi-store image roles using pre-import values and CSV reassignments, accumulate keep/plan across bunches, unlink only after the full save loop, and skip unlinks for a SKU when any image upload fails so re-import can complete safely. Expand unit, integration, and MFTF coverage for these behaviours.
swnsma
force-pushed
the
magento/magento2#33031
branch
from
August 7, 2026 05:48
d9f3335 to
5f24e0d
Compare
…port When Product Images Import Mode is Replace, always drop orphan main gallery rows after unlinking. Optionally delete unused media files and resized cache via a Replace-only admin checkbox, matching Admin product image removal.
swnsma
marked this pull request as ready for review
August 7, 2026 07:11
Batch gallery path usage counts, reject path traversal before filesystem delete, and catch FileSystemException only when removing unused media.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #33031 by adding an opt-in Product Images Import Mode (
add|replace, defaultadd) on product CSV Add/Update imports, plus an optional Delete Unused Image Files checkbox for Replace mode.Product Images Import Mode
additional_images, gallery images not listed in that column are unlinked from the product.additional_imagesis omitted, replace does not drop gallery images.catalog_product_entity_media_gallerywithout product links) are always removed after unlink (core never rebinds them).Delete Unused Image Files (Replace only)
RemoveDeletedImagesFromCachepath as Admin product image remove.Implementation notes:
MediaGalleryReplaceCoordinator+ role plan).MediaGalleryCleanup(processor delegates).Fixed Issues (if relevant)
Manual testing scenarios
additional_images(Add/Update, mode Add) → image present.additional_imagesvalue and mode Add → old and new images both present (legacy behaviour).additional_imagescolumn → gallery extras are not removed.Automated tests / test matrix
MediaGalleryCleanupTest,MediaGalleryProcessorTest,MediaGalleryReplaceCoordinatorTestproduct-image-import-mode.test.js(mode + delete-unused visibility helpers)ProductImagesTest(full class, 20 tests)AdminProductImageImportModeVisibilityTest,AdminProductImageDeleteUnusedVisibilityTestEdge cases covered
additional_imagesunder Replace keeps image roles only; non-role extras unlinked.additional_imagescolumn under Replace does not drop gallery.additional_imageskeep-set is the union across rows/bunches.additional_imageswithout a default-store replace register does not wipe default gallery.Questions or comments
media_gallery_removed_skuson pure-replace removals.