Flush image styles when replace is used

Created on 9 February 2024, 5 months 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

Needs review

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 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom oldspot
Production build 0.69.0 2024