Score:1

Need help regenerating images after image cache flush

in flag

TL;DR - Flushed image cache for an image style that is used in basically every blog. They are not regenerating on page load. They regenerate when i edit and save the node. Looking for ways to programmatically edit/save all the nodes.

Hello all,

As mentioned above i am trying to find a way to programmatically re-save nodes, or at least run the process that regenerates an image.

I recently did an image cache flush. In most cases this would be no problem. Image styles are re-generated on page load. Except, it seems, in my niche case.

I use the Insert Module for my writers to insert images into their articles. This is where i believe things are going wrong. The images aren't being regenerated unless you go into the node edit screen. Note: i just realized you don't have to save the node for the image reload to work, simply going to the edit page.

I have tried using the built in 'save many' functionality built into views. However, re saving the node this way doesn't solve the problem.

I also tried a module called 'Resave all nodes' and ultimately this didn't work either. Note: all this module essentially does is call $node::load(x); $node->save(); in batches.

So there must be some hook that is run once the edit page is opened. Is there a way to run all those processes without going to the edit page? Is there a way to see all the hooks being run once the edit page is opened?

My first solution is always brute-force. In this case i would use puppeteer or selinium and 'manually' go to the edit pages. I don't even have to let the page fully load. it seems i just need to an authorized request to the edit page and the image is reloaded.

But there must be a better way. Can anyone offer me some insight please?

Edit: To be clear, my setup uses the insert module linked above to insert images into article body fields. Images are hosted on s3

sonfd avatar
in flag
That's interesting. What happens if you get one of the image URLs from inspecting the page and visit the URL directly?
cn flag
Usually all you have to do to regenerate image styles is to visit the node (non-edit) page, so it's as simple as using wget to pull all the pages on your site. So there must be something unusual about your setup that is preventing that.
Joshua Jones avatar
in flag
@sonfd I just clarified in my original post. But i host my images on s3 using the s3fs module. so i get a 403 error because the image has not been regenerated.
Joshua Jones avatar
in flag
@PatrickKenny Agreed. However, i assume that my combination of the insert module and using s3fs as my file system for image/file hosting is to be blamed. Maybe just the insert module, as all the other images regenerated just fine. So i suppose my question still stands. Is there a way to run the hooks that are executed on the edit screen programmatically?
sonfd avatar
in flag
Have you cleared cache(s)?
leymannx avatar
ne flag
I created https://www.drupal.org/project/resave_all_nodes somewhen in the past. You can select a node type and then resave all nodes of that type in a batch. Might be of help?
leymannx avatar
ne flag
Wow, didn't know 5 months ago this has been added to Drush 11: `drush entity:save node --bundle=article` to re-save all nodes of type article.
id flag
Image variant generation is an automatic process on page load. Is the web server nginx?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.