I tested out, this module can only replace a file. Will you, in the future, add replace an image function too?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | duplicate-managed-files.png | 81.45 KB | flyke |
I tested out, this module can only replace a file. Will you, in the future, add replace an image function too?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | duplicate-managed-files.png | 81.45 KB | flyke |
Comments
Comment #2
zyzero1987 commentedI tried to replace an image, the origin file entity detail has been changed to the replaced image info, but the link is still remaining with the origin file link.
Comment #3
zyzero1987 commentedI found out what's going on, NVM, Great Job for this module.
Comment #4
temkin commentedComment #5
flyke commentedI had the same problem.
When you replace an image file, the replacement is not immediatly visible because the generated image style image is still from the original image.
You can flush a certain image style, like 'medium' like this:
drush image:flush mediumWould be nice if this module has an option to do that automatically, so that replacing an image will be immediatly visible on the website.
Comment #6
flyke commentedSo I solved this by adding a submit handler.
The submit handler creates an image style uri of the image for each existing image style.
This does not mean that if that image style image did not exist that it will be created.
At first, for each generated image style uri, I checked if the file existed and if it did, I did:
\Drupal::service('file_system')->unlink($style_path);However, I got notices that the file did not exist in many cases, so the file_exists was not working properly.
I had better success using the image.factory service to get the image from the generated image style.
I then checked if it was valid and then just saved it, that successfully recreated the image in all existing image styles for me:
But after more testing I found out that for some reason, I did not even had to check and re-save.
As long is I called $style->buildUri the images would be refreshed. So my working code now is this:
Comment #7
bbralaPerhaps you can create a patch that adds this check and such to the module? Sounds like something that might be helpfull.
Comment #8
flyke commentedHi,
I have still been working on this and I changed my strategy and code.
I use the media_pdf_thumbnail module and I also wanted that when you replace a PDF file, the thumbnail images get refreshed too.
the logic is now: always trigger a custom submit handler.
In it, load all Media items that reference our replaced file.
Simply save those Media items. that will automatically regenerate a thumbnail if it was a PDF file.
But not the derived images, so delete existing derived images so the image style images will be regenerated.
Comment #9
flyke commentedBy the way,
I am still trying to finetune this because each time I replace a PDF (probably when Media save is triggered) the system seems to create a new File (see screenshot). This is for sure not in the scope of this issue, and might be an issue for the media_pdf_preview module, but I'm trying to find and integrate a fix in the code above.