email.install 2.01 KB
Newer Older
1 2
<?php

3

4 5 6 7
/**
 * Implementation of hook_install().
 */
function email_install() {
8
  drupal_load('module', 'content');
9 10 11 12 13 14 15
  content_notify('install', 'email');
}

/**
 * Implementation of hook_uninstall().
 */
function email_uninstall() {
16
  drupal_load('module', 'content');
17 18 19 20 21 22 23 24 25
  content_notify('uninstall', 'email');
}

/**
 * Implementation of hook_enable().
 *
 * Notify content module when this module is enabled.
 */
function email_enable() {
26
  drupal_load('module', 'content');
27 28 29 30 31 32 33 34 35
  content_notify('enable', 'email');
}

/**
 * Implementation of hook_disable().
 *
 * Notify content module when this module is disabled.
 */
function email_disable() {
36
  drupal_load('module', 'content');
37 38 39
  content_notify('disable', 'email');
}

40 41 42 43 44 45 46 47 48
/**
 * Implemenation of hook_update_N();
 *
 * Update from 5.x to 6.x
 *
 * Set all columns to accept NULL values and set empty string values in the
 * database to NULL.
 */
function email_update_6001() {
49 50 51 52 53
  if ($abort = content_check_update('email')) {
    return $abort;
  }
  
  drupal_load('module', 'content');
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  $ret = array();
  $ret[] = update_sql("UPDATE {". content_instance_tablename() ."} SET widget_type = 'email_textfield' WHERE widget_type = 'email'");
  content_associate_fields('email');
  content_clear_type_cache(TRUE);

  include_once(drupal_get_path('module', 'content') .'/content.install');
  $types = content_types_install();
  foreach ($types as $type_name => $fields) {
    foreach ($fields as $field) {
      switch ($field['type']) {
        case 'email':
          $db_info = content_database_info($field);
          $table = $db_info['table'];
          foreach ($db_info['columns'] as $column => $attributes) {
            $attributes['not null'] = FALSE;
            $column = $attributes['column'];
            db_change_field($ret, $table, $column, $column, $attributes);
            db_field_set_no_default($ret, $table, $column);
            $ret[] = update_sql("UPDATE {". $table ."} SET ". $column ." = NULL WHERE ". $column ." = ''");

          }
          break;
      }
    }
  }
  return $ret;
}