Drupal: Re-Save All Site Nodes
This article is about re-saving all nodes on your Drupal-based site. You can wish to re-save nodes in the following cases:
- After number of symbols in teaser has been changed, you need create again teaser which is generated automatically when node saving.
- You installed CCK Computed Field module and need to create again all values of CKK calculated fields for all nodes.
- After operations with URL in Pathauto or Path module, XML Sitemap module shows paths incorrectly – it shows system paths (like ‘node/123′) instead of NC(like ‘/sohranit-statiu’). When re-saving, XML Sitemap module uses NC instead of the system paths.
Solution
Attention: Date Modified (NOT Date Created) will be changed for site documents when using this code .
To update (re-save) site nodes, you should run the following code on your site:
Drupal 5
The code re-saves nodes of a specified type.
<?php
//Change type here
$type = ‘book';
$result = db_query("SELECT nid FROM {node} where type=’%s’", $type);
$count = 0;
while ($current_node = db_fetch_array($result)){
set_time_limit(0);
$current_node_id = node_load($current_node["nid"]);
node_save($current_node_id);
$count++;
}
echo ‘Done. ‘.$count.’ nodes were re-saved.';
?>
Drupal 6
The code re-saves all site nodes:
<?php
$result = db_query("SELECT nid FROM {node}");
$count = 0;
set_time_limit(0);
while ($current_node = db_fetch_array($result)) {
node_save(node_load($current_node["nid"]));
echo $current_node["nid"].'<br />';
$count++;
}
echo ‘Done. ‘.$count.’ nodes were re-saved.';
?>
Re-save nodes of a specified kind:
<?php
$result = db_query("SELECT nid, type FROM {node}");
$count = 0;
set_time_limit(0);
while ($current_node = db_fetch_array($result)) {
if ($current_node["type"] == ‘og_group’) {
node_save(node_load($current_node["nid"]));
echo $current_node["nid"].'<br />';
$count++;
}
}
echo ‘Done. ‘.$count.’ documents were re-saved.';
?>
I am getting a “call to undefined function db_query()” Any suggestions?
This code works fine, but you have to make sure that after you copy+paste you replace the angled single quotes with regular single quotes.
@brandon: You are probably using d7?