| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: image_attach.install,v 1.22.2.1 2010/08/03 17:43:00 sun Exp $ 3 4 /** 5 * Implementation of hook_schema(). 6 */ 7 function image_attach_schema() { 8 $schema['image_attach'] = array( 9 'description' => 'Stores the image/node relationship.', 10 'fields' => array( 11 'nid' => array( 12 'description' => 'The {node}.nid of the node.', 13 'type' => 'int', 14 'unsigned' => TRUE, 15 'not null' => TRUE, 16 'default' => 0, 17 ), 18 'iid' => array( 19 'description' => 'The {image}.nid of the image file.', 20 'type' => 'int', 21 'unsigned' => TRUE, 22 'not null' => TRUE, 23 'default' => 0, 24 ), 25 'weight' => array( 26 'description' => 'The display order of attached images.', 27 'type' => 'int', 28 'not null' => TRUE, 29 'default' => 0, 30 ), 31 ), 32 'primary key' => array('nid', 'iid'), 33 'indexes' => array( 34 'iid' => array('iid'), 35 ), 36 ); 37 return $schema; 38 } 39 40 /** 41 * Implementation of hook_install(). 42 */ 43 function image_attach_install() { 44 drupal_install_schema('image_attach'); 45 } 46 47 /** 48 * Implementation of hook_uninstall(). 49 */ 50 function image_attach_uninstall() { 51 drupal_uninstall_schema('image_attach'); 52 variable_del('image_attach_existing'); 53 variable_del('image_attach_block_0_size'); 54 } 55 56 /** 57 * Add an index to the image id field. 58 */ 59 function image_attach_update_1() { 60 $ret = array(); 61 switch ($GLOBALS['db_type']) { 62 case 'mysql': 63 case 'mysqli': 64 $ret[] = update_sql("ALTER TABLE {image_attach} ADD KEY (iid)"); 65 break; 66 67 case 'pgsql': 68 $ret[] = update_sql("CREATE INDEX {image_attach}_iid_idx ON {image_attach}(iid)"); 69 break; 70 } 71 return $ret; 72 } 73 74 /** 75 * Remove attach records that point to a missing image. 76 */ 77 function image_attach_update_2() { 78 $ret = array(); 79 switch ($GLOBALS['db_type']) { 80 case 'mysqli': 81 case 'mysql': 82 $ret[] = update_sql("DELETE FROM {image_attach} USING {image_attach} LEFT JOIN {node} n ON {image_attach}.iid = n.nid WHERE n.nid IS NULL OR n.type <> 'image'"); 83 break; 84 85 case 'pgsql': 86 $ret[] = update_sql("DELETE FROM {image_attach} USING {node} n WHERE {image_attach}.iid = n.nid AND (n.nid IS NULL OR n.type <> 'image')"); 87 break; 88 } 89 return $ret; 90 } 91 92 /** 93 * Add primary key and index on 'iid' to {image_attach} table. 94 */ 95 function image_attach_update_6100() { 96 $ret = array(); 97 db_change_field($ret, 'image_attach', 'nid', 'nid', array( 98 'type' => 'int', 99 'unsigned' => TRUE, 100 'not null' => TRUE, 101 'default' => 0, 102 )); 103 db_change_field($ret, 'image_attach', 'iid', 'iid', array( 104 'type' => 'int', 105 'unsigned' => TRUE, 106 'not null' => TRUE, 107 'default' => 0, 108 )); 109 110 /** 111 * We remove and re-add primary keys and indexes because the column types 112 * are changed. 113 * Sometimes however these don't exist in the first place (@see 114 * <http://drupal.org/node/562810>; the @ takes care of suppressing the 115 * error message this causes. 116 */ 117 @db_drop_primary_key($ret, 'image_attach'); 118 db_add_primary_key($ret, 'image_attach', array('nid')); 119 @db_drop_index($ret, 'image_attach', 'iid'); 120 db_add_index($ret, 'image_attach', 'iid', array('iid')); 121 122 // Notify the user that they may get harmless fail messages here. 123 $ret[] = array('success' => TRUE, 'query' => t('If you see a message of the form "Failed: ALTER TABLE {image_attach} DROP PRIMARY KEY" or "DROP INDEX iid" here it is harmless.')); 124 return $ret; 125 } 126 127 /** 128 * Delete bad entry in {blocks} table due to old bug. 129 * Next visit to blocks admin page will rehash and show the block. 130 * @see <http://drupal.org/node/426724> 131 */ 132 function image_attach_update_6101() { 133 $ret = array(); 134 $ret[] = update_sql("DELETE FROM {blocks} WHERE module = 'image_attach' AND delta = '0'"); 135 136 return $ret; 137 } 138 139 /** 140 * Adjust primary key on {image_attach} to allow multiple attachments. 141 */ 142 function image_attach_update_6102() { 143 $ret = array(); 144 db_drop_primary_key($ret, 'image_attach'); 145 db_add_primary_key($ret, 'image_attach', array('nid', 'iid')); 146 db_add_field($ret, 'image_attach', 'weight', array( 147 'type' => 'int', 148 'not null' => TRUE, 149 'default' => 0, 150 )); 151 return $ret; 152 } 153 154 /** 155 * Remove erroneous data inside image_attach table, where iid = 0. 156 */ 157 function image_attach_update_6103() { 158 $ret = array(); 159 $ret[] = update_sql("DELETE FROM {image_attach} WHERE iid = 0"); 160 return $ret; 161 } 162
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 |