Drupal: How To Renew Site Nodes
You may need to resave nodes on your site in the following cases:
- You need to re-create a teaser which is generated automatically when saving a node after a number of symbols in that teaser has been changed.
- You need to generate all values of calculated CCK fields for all nodes after installation of CCK Computed Field module.
- XML Sitemap module shows incorrect paths (system paths (like ‘node/123′) instead of friendly URLs (like ‘/sohranit-statiu’)) after manipulations with URL in Pathauto or Path modules. When nodes are resaved, XML Sitemap uses friendly URLs instead of system ones.
Solution:
Note: if you use this code, ‘modified’ date will be changed (in contrast to ‘created’) for site nodes.
Please run the following PHP code on the site to renew (resave) site:
Drupal 5
The code resaves nodes of a certain 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 resaved.';
?>
Drupal 6
The code resaves 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 resaved.';
?>
Resave nodes of a certain type:
<?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.’ nodes .';
?>
Good luck!