I made some mistakes configuring a certain content type on my site. To fix these mistakes, I made a rule that performs some actions "when existing content is updated." However, I don't want to go through my site and manually save all the nodes again one by one. Is there a way to use Rules or Views Bulk Operations to quickly re-save all the nodes?
5 Answers
VBO has an "Execute PHP code" action. Run it, and input "node_save($entity);" (without the quotes) in the textbox. That will do the trick, while handling the timeouts for you.
-
1
-
5There is an option in VBO to "Save content", which will do the same without having to write your own PHP. Jan 20, 2014 at 5:29
-
I couldn't find the "Save Content" option, but the php method you mentioned worked great! Thanks! May 7, 2014 at 23:36
-
Tried both php and vbo methods without success. In my usecase, only a manual Save properly updates the labels for a tablefield. Strange... Oct 28, 2014 at 14:35
I don't know about rules or VBO but you could use a short code snippet to get the same result:
$nids = db_query('SELECT nid FROM {node}')->fetchCol();
foreach (node_load_multiple($nids) as $node) {
node_save($node);
}
If you've got a lot of nodes that might take a bit of time so if your server allows it it'd be a good idea to extend the time limit at the start of that code, perhaps to unlimited if this is a one off:
set_time_limit(0);
You can use the node_mass_update() function:
module_load_include('inc', 'node', 'node.admin');
$nids = db_query('SELECT nid FROM {node}')->fetchCol();
node_mass_update($nids, array());
It's very good as you don't need to care about the time limit. Batch process for nodes update will start automatically if there are more than 10 nodes.
-
5Worked perfectly on over 200,000 nodes. Handles the batch for you. If you have the devel module enabled you can simply paste the above code at the page '/devel/php'– 2phaMar 18, 2015 at 8:12
-
1Brilliant solution, runs in the background so no chance of a timeout or killing a sites performance Aug 12, 2015 at 13:43
Update: I just created Resave All Nodes. For now it only contains a form to trigger a batch process to resave all nodes of selected node types. Currently in alpha. I plan to add a Drush command (beta) and some tests (stable) as well.
There's Resave Nodes. It's intended to used on cron runs. But you can also trigger it manually. Simply choose which content type's nodes should be resaved.
Before you can run the manual resave by hitting "Resave Nodes Now" you once have to "Save Configuration" (chose a cron type and content type).
Go to admin/content and filter by your content type - published only. Select all and then select "change value" from the operations drop down. Click 'execute'. On the next page, select 'status' from the properties and leave published. Click 'next' All the published nodes will resave with no changes.
Repeat for unpublished nodes (but select unpublished as the property).