Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1249 diff -u -r1.1249 node.module --- modules/node/node.module 26 Mar 2010 17:14:45 -0000 1.1249 +++ modules/node/node.module 26 Mar 2010 22:09:55 -0000 @@ -457,14 +457,36 @@ * All new or non-modified module-defined node types are saved to the database. */ function node_types_rebuild() { - // Reset and load updated node types. + // Reset static variable for node_type_get_* functions. drupal_static_reset('_node_types_build'); - foreach (node_type_get_types() as $type => $info) { - if (!empty($info->is_new)) { - node_type_save($info); + + $info_array = module_invoke_all('node_info'); + + $types_in_db = array(); + $type_result = db_select('node_type', 'nt') + ->addTag('translatable') + ->addTag('node_type_access') + ->fields('nt') + ->orderBy('nt.type', 'ASC') + ->execute(); + foreach ($type_result as $type_object) { + if (isset($type_object->base) && $type_object->base != 'node_content' && empty($info_array[$type_object->type])) { + // This type was in the database, but is no longer being returned by + // a hook_node_info(), so delete it. Note that 'node_content' types are + // excepted (these are the types defined by administrators in the UI). + node_type_delete($type_object->type); } - if (!empty($info->disabled)) { - node_type_delete($info->type); + else { + $types_in_db[$type_object->type] = 1; + } + } + + // Now go through the types we found from hook_node_info() and save any + // that were not in the database previously. + foreach ($info_array as $type => $info) { + if (!isset($types_in_db[$type])) { + $info = node_type_set_defaults($info); + node_type_save($info); } } } @@ -660,47 +682,24 @@ /** * Builds and returns the list of available node types. - * - * The list of types is built by querying hook_node_info() in all modules, and - * by comparing this information with the node types in the {node_type} table. - * */ function _node_types_build() { $_node_types = &drupal_static(__FUNCTION__); if (is_object($_node_types)) { return $_node_types; } - $_node_types = (object)array('types' => array(), 'names' => array()); - $info_array = module_invoke_all('node_info'); - foreach ($info_array as $type => $info) { - $info['type'] = $type; - $_node_types->types[$type] = node_type_set_defaults($info); - $_node_types->names[$type] = $info['name']; - } $type_result = db_select('node_type', 'nt') ->addTag('translatable') ->addTag('node_type_access') ->fields('nt') ->orderBy('nt.type', 'ASC') ->execute(); + + $_node_types = (object)array('types' => array(), 'names' => array()); foreach ($type_result as $type_object) { - // Check for node types from disabled modules and mark their types for removal. - // Types defined by the node module in the database (rather than by a separate - // module using hook_node_info) have a base value of 'node_content'. The isset() - // check prevents errors on old (pre-Drupal 7) databases. - if (isset($type_object->base) && $type_object->base != 'node_content' && empty($info_array[$type_object->type])) { - $type_object->disabled = TRUE; - } - if (!isset($_node_types->types[$type_object->type]) || $type_object->modified) { - $_node_types->types[$type_object->type] = $type_object; - $_node_types->names[$type_object->type] = $type_object->name; - - if ($type_object->type != $type_object->orig_type) { - unset($_node_types->types[$type_object->orig_type]); - unset($_node_types->names[$type_object->orig_type]); - } - } + $_node_types->types[$type_object->type] = $type_object; + $_node_types->names[$type_object->type] = $type_object->name; } asort($_node_types->names);