script to convert nodes of one CT to another

Public

This script bootstraps Drupal to fetch all nodes of doc CT to convert to type map

Get raw version
php
  1. <?php
  2. require 'includes/bootstrap.inc';
  3. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  4. set_time_limit(6000);
  5. $node_nid = array();
  6. $query = db_query("SELECT node.nid as nid FROM {node} JOIN {term_node} ON {node}.nid = {term_node}.nid AND {node}.vid = {term_node}.vid WHERE {term_node}.tid = %d AND {node}.type = 'document'", 295);
  7.  
  8. while ($row = db_fetch_object($query)) {
  9. $node_d = node_load($row->nid);
  10. $node_nid[] = $node_d->nid;
  11. $fid_q = db_query("SELECT f.fid as doc_fid FROM {upload} u JOIN {files} f ON u.fid = f.fid WHERE u.nid = %d", $node_d->nid);
  12. while ($result_file = db_fetch_object($fid_q)) {
  13. $fid = $result_file->doc_fid;
  14. }
  15. $desc = db_result(db_query("SELECT description FROM {upload} WHERE nid = %d", $node_d->nid));
  16. db_query("UPDATE {node} SET {node}.type = 'map' WHERE {node}.nid = %d AND {node}.vid = %d", $node_d->nid, $node_d->vid);
  17. db_query("INSERT INTO {content_type_map} VALUES (%d, %d, %d, %d, '%s')", $node_d->vid, $node_d->nid, $fid, 1, $desc);
  18. }
  19. foreach ($node_nid as $n_id) {
  20. $node_detail = node_load($n_id);
  21. print $node_detail->title . ' has been updated<br />';
  22. }
  23. print '<br />' . count($node_nid) . ' nodes are affected';
  24. ?>