24

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?

22

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
    Ahh, much quicker :) – Clive Oct 3 '12 at 14:49
  • 5
    There is an option in VBO to "Save content", which will do the same without having to write your own PHP. – stevenw00 Jan 20 '14 at 5:29
  • I couldn't find the "Save Content" option, but the php method you mentioned worked great! Thanks! – hockey2112 May 7 '14 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... – Bisonbleu Oct 28 '14 at 14:35
14

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);
12

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.

  • 5
    Worked 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' – 2pha Mar 18 '15 at 8:12
  • 1
    Brilliant solution, runs in the background so no chance of a timeout or killing a sites performance – Daniel Waters Aug 12 '15 at 13:43
5

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.

Drupal Resave All Nodes form screenshot


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).

2

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.