| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: imagecache.install,v 1.27 2009/05/01 15:02:29 drewish Exp $ 3 4 function imagecache_requirements($phase) { 5 $requirements = array(); 6 // Ensure translations don't break at install time. 7 $t = get_t(); 8 9 if ($phase == 'runtime') { 10 11 $imagecache_directory = file_create_path() .'/imagecache'; 12 if (!file_check_directory($imagecache_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { 13 if (!is_dir($imagecache_directory)) { 14 $requirements['imagecache_directory'] = array( 15 'title' => $t('ImageCache Directory'), 16 'value' => $t('%p is not a directory or is not readable by the webserver.', array('%p' => $imagecache_directory)), 17 'severity' => REQUIREMENT_ERROR, 18 ); 19 } 20 elseif (!is_writable($imagecache_directory)) { 21 $requirements['imagecache_directory'] = array( 22 'title' => $t('ImageCache Directory'), 23 'value' => $t('%p is not writeable by the webserver.', array('%p' => $imagecache_directory)), 24 'severity' => REQUIREMENT_ERROR, 25 ); 26 } 27 else { 28 $requirements['imagecache_directory'] = array( 29 'title' => $t('ImageCache Directory'), 30 'value' => $t('An unknown error occured.'), 31 'description' => $t('An unknown error occured trying to verify %p is a directory and is writable.', array('%p' => $imagecache_directory)), 32 'severity' => REQUIREMENT_ERROR, 33 ); 34 } 35 } 36 37 if (!is_writable(file_directory_temp())) { 38 $requirements['imagecache_directory'] = array( 39 'title' => $t('ImageCache Temp Directory'), 40 'value' => $t('%p is not writeable by the webserver.', array('%p' => file_directory_temp())), 41 'severity' => REQUIREMENT_ERROR, 42 ); 43 } 44 } 45 return $requirements; 46 } 47 48 function imagecache_schema() { 49 $schema['imagecache_preset'] = array( 50 'fields' => array( 51 'presetid' => array( 52 'description' => t('The primary identifier for an imagecache_preset.'), 53 'type' => 'serial', 54 'unsigned' => TRUE, 55 'not null' => TRUE, 56 ), 57 'presetname' => array( 58 'description' => t('The primary identifier for a node.'), 59 'type' => 'varchar', 60 'length' => 255, 61 'not null' => TRUE, 62 ), 63 ), 64 'primary key' => array('presetid'), 65 ); 66 67 $schema['imagecache_action'] = array( 68 'fields' => array( 69 'actionid' => array( 70 'description' => t('The primary identifier for an imagecache_action.'), 71 'type' => 'serial', 72 'unsigned' => TRUE, 73 'not null' => TRUE, 74 ), 75 'presetid' => array( 76 'description' => t('The primary identifier for an imagecache_preset.'), 77 'type' => 'int', 78 'unsigned' => TRUE, 79 'not null' => TRUE, 80 'default' => 0, 81 ), 82 'weight' => array( 83 'description' => t('The weight of the action in the preset.'), 84 'type' => 'int', 85 'not null' => TRUE, 86 'default' => 0, 87 ), 88 'module' => array( 89 'description' => t('The module that defined the action.'), 90 'type' => 'varchar', 91 'length' => 255, 92 'not null' => TRUE, 93 ), 94 'action' => array( 95 'description' => t('The unique ID of the action to be executed.'), 96 'type' => 'varchar', 97 'length' => 255, 98 'not null' => TRUE, 99 ), 100 'data' => array( 101 'description' => t('The configuration data for the action.'), 102 'type' => 'text', 103 'not null' => TRUE, 104 'size' => 'big', 105 'serialize' => TRUE, 106 ), 107 ), 108 'primary key' => array('actionid'), 109 'indexes' => array( 110 'presetid' => array('presetid'), 111 ), 112 ); 113 114 return $schema; 115 } 116 117 /** 118 * Implementation of hook_install(). 119 */ 120 function imagecache_install() { 121 drupal_install_schema('imagecache'); 122 } 123 124 /** 125 * Implementation of hook_uninstall(). 126 */ 127 function imagecache_uninstall() { 128 // Remove any cached images. 129 $path = file_directory_path() .'/imagecache/'; 130 if (is_dir($path)) { 131 _imagecache_recursive_delete($path); 132 } 133 134 drupal_uninstall_schema('imagecache'); 135 } 136 137 // Add action id to actions table. 138 function imagecache_update_1() { 139 $ret = array(); 140 $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL primary key auto_increment'); 141 return $ret; 142 } 143 144 // Rename rulesets to presets; Make all table names singular; 145 function imagecache_update_2() { 146 $ret = array(); 147 $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} RENAME TO {imagecache_preset}'); 148 $ret[] = update_sql('ALTER TABLE {imagecache_actions} RENAME TO {imagecache_action}'); 149 switch ($GLOBALS['db_type']) { 150 case 'mysql': 151 case 'mysqli': 152 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetid presetid INT UNSIGNED NOT NULL AUTO_INCREMENT'); 153 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\''); 154 $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid INTEGER NOT NULL DEFAULT 0'); 155 break; 156 157 case 'pgsql': 158 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid'); 159 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname'); 160 $ret[] = update_sql('ALTER TABLE {imagecache_action} RENAME COLUMN rulesetid TO presetid'); 161 break; 162 } 163 return $ret; 164 } 165 166 167 /** 168 * Remove auto-increment from tables, instead depending on the sequences table and db_next_id() 169 */ 170 function imagecache_update_3() { 171 $ret = array(); 172 173 $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1; 174 $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1; 175 176 switch ($GLOBALS['db_type']) { 177 case 'mysql': 178 case 'mysqli': 179 $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL"); 180 $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL"); 181 // Add the sequences 182 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', $count_action)"); 183 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', $count_preset)"); 184 break; 185 case 'pgsql': 186 db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0')); 187 db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0')); 188 // Re-add our indexes 189 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)"); 190 $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)"); 191 // Add the sequences 192 $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START $count_action;"); 193 $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START $count_preset;"); 194 } 195 return $ret; 196 } 197 198 function imagecache_update_4() { 199 $ret = array(); 200 201 // add action column to the imagecache_action table just becuase serialization bugs me. 202 switch ($GLOBALS['db_type']) { 203 case 'mysql': 204 case 'mysqli': 205 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) not null default '' after weight"); 206 break; 207 case 'pgsql': 208 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) NOT NULL DEFAULT ''"); 209 break; 210 } 211 212 // unserialize what we can. 213 $result = db_query("SELECT * FROM {imagecache_action}"); 214 while ($row = db_fetch_array($result)) { 215 $data = unserialize($row['data']); 216 217 // remove function from data if present; 218 $function = $data['function']; 219 unset($data['function']); 220 $data = serialize($data); 221 222 // Rename scale and crop for any people who upgraded early... 223 if ($function == 'scale and crop') { 224 $function = 'scale_and_crop'; 225 } 226 // Keep scale and crop and the old scale function seperate... I don't really want to break BC with 227 // the 2.x update. We'll deprecate this version. 228 if ($function == 'scale') { 229 $function = 'deprecated_scale'; 230 } 231 232 // prefix with module name as per new status quo. 233 // since other modules couldn't implement actions before this update 234 // we assume imagecache... 235 $function = 'imagecache_'. $function; 236 237 db_query("UPDATE {imagecache_action} SET action='%s', data='%s' WHERE actionid = %d", $function, $data, $row['actionid']); 238 } 239 cache_clear_all('*', 'cache', TRUE); 240 return $ret; 241 } 242 243 function imagecache_update_5() { 244 // enable image API. 245 module_rebuild_cache(); // make sure new modules are in the system table. 246 module_enable(array('imageapi', 'imageapi_gd', 'imageapi_imagemagick')); // enable our new module. 247 248 // @todo: update formatter names: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/imagecache/imagecache.module?r1=1.68&r2=1.68.2.8&pathrev=DRUPAL-5--2 249 // ln: 516 diff 511. 250 251 return array(); 252 } 253 254 /** 255 * Upgrade from Drupal 5 => Drupal 6. 256 * 257 * Use serial data type for primary keys. Add module field and presetid index. 258 */ 259 function imagecache_update_6000() { 260 $ret = array(); 261 262 // Our additions to the schema. 263 $schema['imagecache_preset'] = array( 264 'fields' => array( 265 'presetid' => array( 266 'description' => t('The primary identifier for an imagecache_preset.'), 267 'type' => 'serial', 268 'unsigned' => TRUE, 269 'not null' => TRUE, 270 ), 271 ), 272 'primary key' => array('presetid'), 273 ); 274 $schema['imagecache_action'] = array( 275 'fields' => array( 276 'actionid' => array( 277 'description' => t('The primary identifier for an imagecache_action.'), 278 'type' => 'serial', 279 'unsigned' => TRUE, 280 'not null' => TRUE, 281 ), 282 'module' => array( 283 'description' => t('The module that defined the action.'), 284 'type' => 'varchar', 285 'length' => 255, 286 'not null' => TRUE, 287 'initial' => 'imagecache', 288 ), 289 ), 290 'primary key' => array('actionid'), 291 ); 292 293 // Update primary keys to serial type for Drupal 6 294 foreach ($schema as $table => $info) { 295 $field = $info['primary key'][0]; 296 if (db_table_exists('sequences')) { 297 $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{{$table}}_{$field}'"); 298 } 299 db_change_field($ret, $table, $field, $field, $info['fields'][$field]); 300 } 301 302 // Going to assume that if the table doesn't have a module column that 303 // it needs the index as well. 304 if (!db_column_exists('imagecache_action', 'module')) { 305 // Add 'module' column to action table. 306 db_add_field($ret, 'imagecache_action', 'module', $schema['imagecache_action']['fields']['module']); 307 308 // Add 'presetid' index to action table 309 db_add_index($ret, 'imagecache_action', 'presetid', array('presetid')); 310 } 311 312 313 return $ret; 314 } 315 316 /** 317 * Make sure the schemas match, the weight should be signed. 318 */ 319 function imagecache_update_6001() { 320 $ret = array(); 321 db_change_field($ret, 'imagecache_action', 'weight', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); 322 return $ret; 323 }
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 |