Enabling a custom module after uninstalling it I have simple question concerning enabling a custom module after having disinstalled it.
The module provides a simple creation of a new content type based on node content.
It implements a hook_install() function that first time i enabled the module worked perfectly. For debugging reasons i had to disable and unistall the module, then when i tried to enable again the module the system checks it as enabled but the new content type that is the result of the hook_install() function does not appear anymore. 

It seems to me that when i try to re-activate the module the installation script doesn't work anymore, and this although i cleared the cache after unistallind the module the first time.

Any ideas?

Here's the install code:


function bachecanews_install() {
  $t = get_t();
  $node_bachecanews = array(
    'type' => 'node_bachecanews',
    'name' => $t('Bacheca News'),
    'base' => 'node_content',
    'description' => $t('Usa Bacheca News per inserire le notizio sul sito.'),
    'body_label' => $t('Contenuto della News')
  );
  $content_type = node_type_set_defaults($node_bachecanews);
  node_add_body_field($content_type);
  node_add_date_field($content_type);
  $status = node_type_save($content_type);
  $t_args = array('%name' => $content_type->name);
  if ($status == SAVED_UPDATED) { // in caso di modifica
    drupal_set_message($t('Il nuovo tipo di contenuto %name è stato modificato.', $t_args));
  } 
  elseif ($status == SAVED_NEW) { // in caso di creazione
    drupal_set_message($t('Il nuovo tipo di contenuto %name è stato creato.', $t_args));
    watchdog('node', 'Creato il nuovo tipo di contenuto %name.', $t_args, WATCHDOG_NOTICE, l($t('view'), 'admin/structure/types')); 
  }
}

function bachecanews_uninstall() {
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  $result = db_query($sql, array(':type' => 'node_bachecanews'));
  $nids = array();
  foreach ($result as $row) {
    $nids[] = $row->nid;
  }
  node_delete_multiple($nids);
  node_type_delete('node_bachecanews');
}
I found out that you have 2 issues with your hook_install code.


You're adding body field first then saving the node type. It should be the opposite. 
There's no such function called node_add_date_field in Drupal package, unless you've created it yourself in your custom module.


Your hook_install should be as the following code:

function bachecanews_install() {
  $t = get_t();
  $node_bachecanews = array(
    'type' =&gt; 'node_bachecanews',
    'name' =&gt; $t('Bacheca News'),
    'base' =&gt; 'node_content',
    'description' =&gt; $t('Usa Bacheca News per inserire le notizio sul sito.'),
    'body_label' =&gt; $t('Contenuto della News')
  );
  $content_type = node_type_set_defaults($node_bachecanews);
  $status = node_type_save($content_type);
  node_add_body_field($content_type);
  $t_args = array('%name' =&gt; $content_type-&gt;name);
  if ($status == SAVED_UPDATED) { // in caso di modifica
    drupal_set_message($t('Il nuovo tipo di contenuto %name è stato modificato.', $t_args));
  } 
  elseif ($status == SAVED_NEW) { // in caso di creazione
    drupal_set_message($t('Il nuovo tipo di contenuto %name è stato creato.', $t_args));
    watchdog('node', 'Creato il nuovo tipo di contenuto %name.', $t_args, WATCHDOG_NOTICE, l($t('view'), 'admin/structure/types')); 
  }
}


If you want to add additional field to your custom content type and this field is not body field, you use field_create_field() 

As an example, you can look at standard_install().