node_type_get_type() and hook_uninstall() I have a job_post module, which defines the "job_post" content type.

In this module I have hook_unistall() which calls node_type_delete() to remove that content type.

After uninstalling, I have the following error from the Comment module:


  Notice: Trying to get property of non-object in comment_node_type_delete() (line 343 of ....\comment.module).


I have this error because the $info variable in node_type_delete() is set to FALSE.

Why when my module is installed and when I am printing var_dump(node_type_get_type('job_post')) on any page, I have an object, but when I'm trying to print the same code in my unistall function I get FALSE and this error?

job_post.install

/**
 * Implements hook_install().
 */
function job_post_install() {
  node_types_rebuild();

  $types = node_type_get_types();
  node_add_body_field($types['job_post']);

  $body_instance = field_info_instance('node', 'body', 'job_post');
  $body_instance['type'] = 'text_summary_or_trimmed';

  field_update_instance($body_instance);
}

/**
 * Implements hook_uninstall().
 */
function job_post_uninstall() {
  $instances = field_info_instances('node', 'job_post');
  foreach ($instances as $instance_name =&gt; $instance) {
    field_delete_instance($instance);
  }

  // Force rebuild of the node type cache
  // as Clive suggested didn't help
  // _node_types_build(TRUE);

  node_type_delete('job_post');

  field_purge_batch(1000);
}


job_post.module

/**
 * Implements hook_node_info() to provide our job_post type.
 */
function job_post_node_info() {
  return array(
    'job_post' =&gt; array(
      'name' =&gt; t('Job Post'),
      'base' =&gt; 'job_post',
      'description' =&gt; t('Use this content type to post a job.'),
      'has_title' =&gt; TRUE,
      'title_label' =&gt; t('Job Title'),
      'help' =&gt; t('Enter the job title and job description')
    )
  );
}

/**
 * Implement hook_form() with the standard default form.
 */
function job_post_form($node, $form_state) {
  return node_content_form($node, $form_state);
}
If you look at the code that the Forum module executes in forum_uninstall(), you will notice that it just deletes the field it defines, but it doesn't delete the content type it defines.

function forum_uninstall() {
  // Load the dependent Taxonomy module, in case it has been disabled.
  drupal_load('module', 'taxonomy');

  variable_del('forum_containers');
  variable_del('forum_hot_topic');
  variable_del('forum_per_page');
  variable_del('forum_order');
  variable_del('forum_block_num_active');
  variable_del('forum_block_num_new');
  variable_del('node_options_forum');

  field_delete_field('taxonomy_forums');
  // Purge field data now to allow taxonomy module to be uninstalled
  // if this is the only field remaining.
  field_purge_batch(10);
}


Your module should do the same, and avoid deleting the fields defined for the content type (if they are not defined from the module), or the content type itself.