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