[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/audio/contrib/attach/ -> audio_attach.install (source)

   1  <?php
   2  // $Id: audio_attach.install,v 1.7 2008/12/21 23:21:19 drewish Exp $
   3  
   4  /**
   5   * Implementation of hook_install().
   6   */
   7  function audio_attach_install() {
   8    drupal_load('module', 'content');
   9    content_notify('install', 'audio_attach');
  10  }
  11  
  12  /**
  13   * Implementation of hook_uninstall().
  14   */
  15  function audio_attach_uninstall() {
  16    drupal_load('module', 'content');
  17    content_notify('uninstall', 'audio_attach');
  18  }
  19  
  20  /**
  21   * Implementation of hook_enable().
  22   */
  23  function audio_attach_enable() {
  24    drupal_load('module', 'content');
  25    content_notify('enable', 'audio_attach');
  26  }
  27  
  28  /**
  29   * Implementation of hook_disable().
  30   */
  31  function audio_attach_disable() {
  32    drupal_load('module', 'content');
  33    content_notify('disable', 'audio_attach');
  34  }
  35  
  36  /**
  37   * Implementation of hook_update_last_removed().
  38   */
  39  function audio_attach_update_last_removed() {
  40    return 1;
  41  }
  42  
  43  /**
  44   * Create a CCK nodereference field and migrate the data to it.
  45   */
  46  function audio_attach_update_6000() {
  47    // Make sure they've enabled CCK
  48    if (!drupal_load('module', 'content') || !drupal_load('module', 'nodereference') || !function_exists('content_check_update')) {
  49      $ret['#abort'] = array('success' => FALSE, 'query' => t('Audio Attach now requires CCK be installed. Some updates are still pending.<br/>Please re-run the update script.'));
  50      return $ret;
  51    }
  52    if ($abort = content_check_update('audio_attach')) {
  53      return $abort;
  54    }
  55  
  56    // Need to load the CCK include file where content_field_instance_create()
  57    // is defined.
  58    module_load_include('inc', 'content', 'includes/content.crud');
  59  
  60    // var_export(content_fields('field_audio_attach', 'story'));
  61    $field = array (
  62      'field_name' => 'field_audio_attach',
  63      'display_settings' =>
  64      array (
  65        'weight' => '31',
  66        'parent' => '',
  67        'label' =>
  68        array (
  69          'format' => 'above',
  70        ),
  71        'teaser' =>
  72        array (
  73          'format' => 'audio_attach',
  74          'exclude' => 0,
  75        ),
  76        'full' =>
  77        array (
  78          'format' => 'audio_attach',
  79          'exclude' => 0,
  80        ),
  81        4 =>
  82        array (
  83          'format' => 'default',
  84          'exclude' => 0,
  85        ),
  86        2 =>
  87        array (
  88          'format' => 'default',
  89          'exclude' => 0,
  90        ),
  91        3 =>
  92        array (
  93          'format' => 'default',
  94          'exclude' => 0,
  95        ),
  96        'token' =>
  97        array (
  98          'format' => 'default',
  99          'exclude' => 0,
 100        ),
 101      ),
 102      'widget_active' => '1',
 103      'type' => 'nodereference',
 104      'required' => '0',
 105      'multiple' => '1',
 106      'db_storage' => '0',
 107      'module' => 'nodereference',
 108      'active' => '1',
 109      'locked' => '0',
 110      'columns' =>
 111      array (
 112        'nid' =>
 113        array (
 114          'type' => 'int',
 115          'unsigned' => true,
 116          'not null' => false,
 117        ),
 118      ),
 119      'referenceable_types' =>
 120      array (
 121        'audio' => 'audio',
 122      ),
 123      'advanced_view' => '--',
 124      'advanced_view_args' => '',
 125      'widget' =>
 126      array (
 127        'autocomplete_match' => 'contains',
 128        'default_value' =>
 129        array (
 130          0 =>
 131          array (
 132            'nid' => NULL,
 133            '_error_element' => 'default_value_widget][field_audio_attach][0][nid][nid',
 134          ),
 135        ),
 136        'default_value_php' => NULL,
 137        'label' => 'Attached audio files',
 138        'weight' => '31',
 139        'description' => '',
 140        'type' => 'nodereference_autocomplete',
 141        'module' => 'nodereference',
 142      ),
 143    );
 144  
 145    // Now create the fields for each node type that audio_attach is enabled on.
 146    foreach (node_get_types() as $type) {
 147      if (variable_get('audio_attach_'. $type->type, 0)) {
 148        $field['type_name'] = $type->type;
 149        content_field_instance_create($field);
 150      }
 151    }
 152  
 153    // Now the tricky part is to migrate the data...
 154    // GREAT BIG ASSUMPTION: We created the field to accept unlimited values so
 155    // it should have $field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD for
 156    // all instances of the field. If not this code will probably not work right.
 157    $db_info = content_database_info($field);
 158    $table = $db_info['table'];
 159    $column = $db_info['columns']['nid']['column'];
 160  
 161    $ret[] = update_sql("INSERT INTO {$table} (nid, vid, delta, $column) SELECT n.nid, n.vid, a.weight, a.aid FROM {audio_attach} a INNER JOIN {node} n ON a.nid = n.nid");
 162  
 163  
 164    // Remove the old variables.
 165    foreach (node_get_types() as $type) {
 166  #    variable_del('audio_attach_'. $type);
 167    }
 168  
 169    // And drop the old table.
 170  #  db_drop_table($ret, 'audio_attach');
 171  
 172    return $ret;
 173  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7