Flush image styles when replace is used

Created on 9 February 2024, about 1 year ago

Problem/Motivation

This might not apply to a normal 'migrate and forget it' situation, but in our case we have an ongoing product migration running hourly importing data from a 3rd party provider, and when images are updated they get 'replaced' correctly, however any previously generated image styles for the original image don't get replaced.
This means that while the underlying image is updated correctly, the frontend users seeing mostly thumbnails and other styles applied to it continue to see the previous image.

Steps to reproduce

  • Migrate an entity with an image field using the default EXISTS_REPLACE method
  • Visit entity page, generating a thumbnail or other style applied to it
  • Update the original image file
  • Re-run migration to update the image field
  • Verify original image is updated correctly on the entity
  • Visiti entity page, where the old thumbnail will still display

Proposed resolution

I've created a patch which runs image_path_flush($file->getFileUri()); when EXISTS_REPLACE method is used.

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇬🇧United Kingdom oldspot

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @oldspot
  • 🇬🇧United Kingdom oldspot

    Created MR with potential solution. This worked ok in the tests I've made.

    I checked with a normal non-image document too and that didn't cause any issues and simply skipped over the deletion since the 'derivative' files don't exist.

    The reason I didn't put it in the ImageImport plugin specifically is because you can still import images with the base FileImport plugin (as it was in our case).

  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 month ago
  • 🇫🇷France duaelfr Montpellier, France

    Thank you for your contribution on this module!

    I first thought it should be in the ImageImport plugin but I then saw your explanation and looked back at the code and saw how much more complicated it would be, so I think it's okay that way.
    The MR doesn't apply on 2.0.x, though, so it needs to be rerolled (and maybe even moved to 3.0.x).
  • 🇫🇷France duaelfr Montpellier, France

    Rerolled on 2.1.x (sadly this version has no release so we cannot tag the issue on it).
    Patch added for composer.

Production build 0.71.5 2024