Last updated November 4, 2011. Created by DarrellDuane on November 4, 2011.
Log in to edit this page.

This is a utility function which cleans up the variable table, removing entries for node types which no longer exist, and then goes on to set all node types to have revisioning enabled. This code also has a line which disables the default of new nodes to be not Promoted to Front Page , although it is currently commented out. It displays information about what it has done. The first line, a comment, can be used in phpMyAdmin to show what the current settings are for each content type. It is my hope that someday this code might be used as a start for building a full blown module that shows and allows easy editing, and bulk modifications of all settings for all CCK/node types on a site.

function bulk_enable_cck_revisions() {
  // select * from variable WHERE name LIKE 'node_options%' # sql to show status of all cck types, use this in phpMyAdmin or similar tool
  // first, clean up any old data in the variable table that's not needed any longer.
  $result = db_query("select name from variable WHERE name LIKE 'node_options%'");     # quick sql to show status of all cck types
  while($name = db_result($result)){
    $type = substr($name,13);
    $count = db_result(db_query("SELECT COUNT(*) FROM node_type WHERE type = '%s'", $type));
    if($count == 0){
      drupal_set_message("$type no longer exists.  Deleting node_option_$type from variable table");
      $sql = "DELETE FROM variable WHERE name = '$name'";
      db_query($sql);
    }
  }
  // now go through all of the current node types and enable revisions
  $result = db_query("SELECT type FROM node_type");
  while($type = db_result($result)){
    $node_options = variable_get('node_options_' . $type,array() );
    // $node_options = array_diff($node_options,array('promote'));  // makes nodes by default to be not promoted to front page.
    // uncomment the line above if you don't want any node types to promote nodes to front page by default
    if(array_search('revision', $node_options) !== FALSE) {
      drupal_set_message("CCK Type $type already has revisions enabled");
    } else {
      $node_options[] = 'revision';
      drupal_set_message("Enabling revisions for $type:");
      drupal_set_message(print_r($node_options,1));
    }
    variable_set('node_options_' . $type, $node_options);  // update the variable table with the new settings
  }
}

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.