[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/filefield/filefield_meta/ -> filefield_meta.install (source)

   1  <?php
   2  /**
   3   * @file
   4   * FileField Meta: Add Video Support to File Field.
   5   */
   6  
   7  /**
   8   * Implementation of hook_install().
   9   */
  10  function filefield_meta_install() {
  11    drupal_install_schema('filefield_meta');
  12  }
  13  
  14  function filefield_meta_uninstall() {
  15    drupal_uninstall_schema('filefield_meta');
  16  }
  17  
  18  /**
  19   * Implementation of hook_schema().
  20   */
  21  function filefield_meta_schema() {
  22    $schema = array();
  23    // The primary field/index.
  24    $schema['filefield_meta'] = array(
  25      'description' => 'The table for meta data about filefield files.',
  26      'fields' => array(
  27        'fid' => array(
  28          'description' => 'The file id.',
  29          'type' => 'int',
  30          'unsigned' => TRUE,
  31          'not null' => TRUE,
  32        ),
  33        'width' => array(
  34          'description' => 'Width of a video or image file in pixels.',
  35          'type' => 'int',
  36          'unsigned' => TRUE,
  37          'not null' => FALSE,
  38        ),
  39        'height' => array(
  40          'description' => 'Height of a video or image file in pixels.',
  41          'type' => 'int',
  42          'unsigned' => TRUE,
  43          'not null' => FALSE,
  44        ),
  45        'duration' => array(
  46          'description' => 'The duration of audio or video files, in seconds.',
  47          'type' => 'float',
  48          'size' => 'normal',
  49          'not null' => FALSE,
  50        ),
  51        'audio_format' => array(
  52          'description' => 'The audio format.',
  53          'type' => 'varchar',
  54          'length' => 10,
  55          'not null' => TRUE,
  56          'default' => '',
  57        ),
  58        'audio_sample_rate' => array(
  59          'description' => 'The sample rate of the audio.',
  60          'type' => 'int',
  61          'size' => 'medium',
  62          'not null' => TRUE,
  63          'default' => 0,
  64        ),
  65        'audio_channel_mode' => array(
  66          'description' => 'The number of channels in the audio, by name (stereo or mono).',
  67          'type' => 'varchar',
  68          'length' => 10,
  69          'not null' => TRUE,
  70          'default' => '',
  71        ),
  72        'audio_bitrate' => array(
  73          'description' => 'The audio bitrate.',
  74          'type' => 'float',
  75          'size' => 'medium',
  76          'not null' => TRUE,
  77          'default' => 0,
  78        ),
  79        'audio_bitrate_mode' => array(
  80          'description' => 'The kind of audio bitrate, such as VBR. Usually empty.',
  81          'type' => 'varchar',
  82          'length' => 4,
  83          'not null' => TRUE,
  84          'default' => '',
  85        ),
  86        'tags' => array(
  87          'description' => 'ID3 tags such as artist, album, and genre.',
  88          'type' => 'text',
  89          'serialize' => TRUE,
  90        ),
  91      ),
  92      'primary key' => array('fid'),
  93    );
  94  
  95    return $schema;
  96  }
  97  
  98  function filefield_meta_update_1() {
  99    $ret = array();
 100    db_add_field($ret, 'filefield_meta', 'audio_format', array(
 101      'description' => 'The audio format.',
 102      'type' => 'varchar',
 103      'length' => 10,
 104      'not null' => TRUE,
 105      'default' => '',
 106    ));
 107    db_add_field($ret, 'filefield_meta', 'audio_sample_rate', array(
 108      'description' => 'The sample rate of the audio.',
 109      'type' => 'int',
 110      'size' => 'medium',
 111      'not null' => TRUE,
 112      'default' => 0,
 113    ));
 114    db_add_field($ret, 'filefield_meta', 'audio_channel_mode', array(
 115      'description' => 'The number of channels in the audio, by name.',
 116      'type' => 'varchar',
 117      'length' => 10,
 118      'not null' => TRUE,
 119      'default' => '',
 120    ));
 121    db_add_field($ret, 'filefield_meta', 'audio_bitrate', array(
 122      'description' => 'The audio bitrate.',
 123      'type' => 'float',
 124      'size' => 'medium',
 125      'not null' => TRUE,
 126      'default' => 0,
 127    ));
 128    db_add_field($ret, 'filefield_meta', 'audio_bitrate_mode', array(
 129      'description' => 'The kind of audio bitrate.',
 130      'type' => 'varchar',
 131      'length' => 4,
 132      'not null' => TRUE,
 133      'default' => '',
 134    ));
 135    return $ret;
 136  }
 137  
 138  /**
 139   * Add the tags column.
 140   */
 141  function filefield_meta_update_6100(&$context) {
 142    $ret = array();
 143  
 144    // Set up our update and add the tags column.
 145    if (!isset($context['sandbox']['progress'])) {
 146      $context['sandbox']['progress'] = 0;
 147      $context['sandbox']['total'] = db_result(db_query("SELECT COUNT(*) FROM {files} f INNER JOIN {filefield_meta} fm ON f.fid = fm.fid WHERE fm.audio_format <> ''"));
 148      $context['sandbox']['current_fid'] = 0;
 149      if (!db_column_exists('filefield_meta', 'tags')) {
 150        db_add_field($ret, 'filefield_meta', 'tags', array('type' => 'text'));
 151      }
 152      // We are done if there are none to update.
 153      if ($context['sandbox']['total'] == 0) {
 154        return $ret;
 155      }
 156    }
 157  
 158    // Select and process 200 files at a time.
 159    $limit = 200;
 160    $result = db_query_range("SELECT f.* FROM {files} f INNER JOIN {filefield_meta} fm ON f.fid = fm.fid WHERE f.fid > %d AND fm.audio_format <> '' ORDER BY f.fid ASC", $context['sandbox']['current_fid'], 0, $limit);
 161  
 162    // Loop through each file and read in its ID3 tags if applicable.
 163    while ($file = db_fetch_object($result)) {
 164      filefield_meta_file_update($file);
 165      $context['sandbox']['current_fid'] = $file->fid;
 166      $context['sandbox']['progress']++;
 167    }
 168  
 169    // Update our progress indicator.
 170    $ret['#finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
 171  
 172    return $ret;
 173  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7