If two different images with the same filename are uploaded in the same subfolder (with the name in the format year_month), then the more recent image will overwrite the other image.

The suggested solution is to use the article's story ID as the subfolder name.

Comments

Antonín Slejška created an issue. See original summary.

berdir’s picture

Might be easier to just update \Drupal\ww_publish\Image::createMediaEntity() to use \Drupal\Core\File\FileSystemInterface::EXISTS_RENAME instead of REPLACE.

That said, shouldn't the filename always match the ID and already look up the existing media through that? If the ID's are not globally unique then the assumption in \Drupal\ww_publish\Image::getMediaEntity to reuse existing medias would not be correct?

antonín slejška’s picture

Status: Active » Fixed

Thank You, Sasha. It is the simplest solution.

It is possible to improve it in the future...

berdir’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Fixed » Patch (to be ported)

Would like to understand the scenario better before adding it to the 2.x branch, it's not clear to me yet how the filename can be the same but the media/file does not exist for it.

antonín slejška’s picture

Hi Sasha,
before the commit: if two different images (in two articles) with the same filename were uploaded, then two media entities were created, but both media entities have been related to (linked) the same file. The first uploaded file was replaced by the second uploaded file. Now it works as expected:

  • the first media entity is related to the first uploaded file, e.g.: my-image.jpg
  • the second media entity is related to the second uploaded and renamed file: my-image_0.jpg
berdir’s picture

Status: Patch (to be ported) » Fixed

Ah, I understand. I thought that the filename is the ID, but I forgot that we are renaming the file based on the name in the metadata, so I see, it could indeed be the same for different IDs. Yeah, this makes sense then. I cherry picked this commit to 2.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.