| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: audio_images.install,v 1.4 2008/12/21 23:21:18 drewish Exp $ 3 4 function audio_images_install() { 5 drupal_install_schema('audio_images'); 6 } 7 8 function audio_images_uninstall() { 9 drupal_uninstall_schema('audio_images'); 10 variable_del('audio_default_image_type'); 11 variable_del('audio_image_size'); 12 // TODO should we delete the image files too? 13 } 14 15 /** 16 * Install the initial schema. 17 */ 18 function audio_images_schema() { 19 $schema['audio_image'] = array( 20 'description' => t('Associates an image (such as album artwork) with an audio file.'), 21 'fields' => array( 22 'fid' => array( 23 'type' => 'int', 24 'unsigned' => TRUE, 25 'not null' => TRUE, 26 'description' => t('Primary Key: The {files}.fid.'), 27 ), 28 'vid' => array( 29 'type' => 'int', 30 'size' => 'medium', 31 'not null' => TRUE, 32 ), 33 'nid' => array( 34 'type' => 'int', 35 'size' => 'medium', 36 'not null' => TRUE, 37 ), 38 'pictype' => array( 39 'type' => 'int', 40 'size' => 'tiny', 41 'not null' => TRUE, 42 'default' => 0, 43 ), 44 'width' => array( 45 'type' => 'int', 46 'size' => 'small', 47 'not null' => TRUE, 48 'default' => 0, 49 ), 50 'height' => array( 51 'type' => 'int', 52 'size' => 'small', 53 'not null' => TRUE, 54 'default' => 0, 55 ), 56 ), 57 'primary key' => array('vid', 'fid'), 58 'indexes' => array( 59 'audio_image_fid' => array('fid'), 60 ), 61 ); 62 return $schema; 63 } 64 65 /** 66 * Implementation of hook_update_last_removed(). 67 */ 68 function audio_images_update_last_removed() { 69 return 2; 70 } 71 72 /** 73 * Move the majority of our data into the {files} table. 74 */ 75 function audio_images_update_6000() { 76 $ret = array(); 77 $fid_field = array( 78 'type' => 'int', 79 'unsigned' => TRUE, 80 'not null' => TRUE, 81 'description' => t('Primary Key: The {files}.fid.'), 82 ); 83 db_add_field($ret, 'audio_image', 'fid', $fid_field); 84 db_add_index($ret, 'audio_image', 'audio_image_fid', array('fid')); 85 86 // Load all the distinct filepaths. 87 $result = db_query("SELECT DISTINCT filepath FROM {audio_image} WHERE fid IS NULL OR fid = 0"); 88 while ($file = db_fetch_object($result)) { 89 // Then move the data into the files table. 90 db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) SELECT n.uid, '%s', ai.filepath, ai.filemime, ai.filesize, %d, n.created AS timestamp FROM {node} n INNER JOIN {audio_image} ai ON n.vid = ai.vid WHERE ai.filepath = '%s' LIMIT 1", array(basename($file->filepath), FILE_STATUS_PERMANENT, $file->filepath)); 91 db_query("UPDATE {audio_image} SET fid = %d WHERE filepath = '%s'", db_last_insert_id('files', 'fid'), $file->filepath); 92 } 93 94 // Remove all the old fields and setup the new indexes. 95 db_drop_field($ret, 'audio_image', 'pid'); 96 db_drop_field($ret, 'audio_image', 'filesize'); 97 db_drop_field($ret, 'audio_image', 'filepath'); 98 db_drop_field($ret, 'audio_image', 'filemime'); 99 db_drop_index($ret, 'audio_image', 'audio_image_vid_pictype'); 100 101 return $ret; 102 } 103 104 function audio_images_update_6001() { 105 $ret = array(); 106 db_drop_primary_key($ret, 'audio_image'); 107 db_add_primary_key($ret, 'audio_image', array('vid', 'fid')); 108 return $ret; 109 }
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 |