| Commit | Line | Data |
|---|---|---|
| ed7d47b6 DP |
1 | <?php |
| 2 | // $Id$ | |
| 3 | ||
| 34eb1998 | 4 | function imagecache_requirements($phase) { |
| 19fefb49 DP |
5 | $requirements = array(); |
| 6 | // Ensure translations don't break at install time. | |
| 7 | $t = get_t(); | |
| 8 | ||
| 19fefb49 | 9 | if ($phase == 'runtime') { |
| 23c2a416 | 10 | |
| 19fefb49 DP |
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'), | |
| 47da7247 | 16 | 'value' => $t('%p is not a directory or is not readable by the webserver.', array('%p' => $imagecache_directory)), |
| 19fefb49 DP |
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 | ||
| 8c361d7c DP |
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, | |
| 65e8db7c | 55 | 'not null' => TRUE, |
| 56 | ), | |
| 8c361d7c DP |
57 | 'presetname' => array( |
| 58 | 'description' => t('The primary identifier for a node.'), | |
| 59 | 'type' => 'varchar', | |
| 60 | 'length' => 255, | |
| 65e8db7c | 61 | 'not null' => TRUE, |
| 62 | ), | |
| 8c361d7c DP |
63 | ), |
| 64 | 'primary key' => array('presetid'), | |
| 65 | ); | |
| 2d6b7863 | 66 | |
| 8c361d7c DP |
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, | |
| 65e8db7c | 73 | 'not null' => TRUE, |
| 74 | ), | |
| 8c361d7c DP |
75 | 'presetid' => array( |
| 76 | 'description' => t('The primary identifier for an imagecache_preset.'), | |
| 77 | 'type' => 'int', | |
| 78 | 'unsigned' => TRUE, | |
| 79 | 'not null' => TRUE, | |
| 65e8db7c | 80 | 'default' => 0, |
| 81 | ), | |
| 8c361d7c DP |
82 | 'weight' => array( |
| 83 | 'description' => t('The weight of the action in the preset.'), | |
| 84 | 'type' => 'int', | |
| 8c361d7c | 85 | 'not null' => TRUE, |
| 65e8db7c | 86 | 'default' => 0, |
| 87 | ), | |
| 8c361d7c DP |
88 | 'module' => array( |
| 89 | 'description' => t('The module that defined the action.'), | |
| 90 | 'type' => 'varchar', | |
| 91 | 'length' => 255, | |
| 65e8db7c | 92 | 'not null' => TRUE, |
| 93 | ), | |
| 8c361d7c DP |
94 | 'action' => array( |
| 95 | 'description' => t('The unique ID of the action to be executed.'), | |
| 96 | 'type' => 'varchar', | |
| 97 | 'length' => 255, | |
| 65e8db7c | 98 | 'not null' => TRUE, |
| 99 | ), | |
| 8c361d7c DP |
100 | 'data' => array( |
| 101 | 'description' => t('The configuration data for the action.'), | |
| 102 | 'type' => 'text', | |
| 103 | 'not null' => TRUE, | |
| 104 | 'size' => 'big', | |
| 65e8db7c | 105 | 'serialize' => TRUE, |
| 106 | ), | |
| 8c361d7c DP |
107 | ), |
| 108 | 'primary key' => array('actionid'), | |
| 109 | 'indexes' => array( | |
| 110 | 'presetid' => array('presetid'), | |
| 111 | ), | |
| 112 | ); | |
| 2d6b7863 | 113 | |
| 8c361d7c DP |
114 | return $schema; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Implementation of hook_install(). | |
| 119 | */ | |
| 120 | function imagecache_install() { | |
| 121 | drupal_install_schema('imagecache'); | |
| ed7d47b6 DP |
122 | } |
| 123 | ||
| 19fefb49 DP |
124 | /** |
| 125 | * Implementation of hook_uninstall(). | |
| 126 | */ | |
| 127 | function imagecache_uninstall() { | |
| ba30c51c | 128 | // Remove any cached images. |
| 129 | $path = file_directory_path() .'/imagecache/'; | |
| 130 | if (is_dir($path)) { | |
| 131 | _imagecache_recursive_delete($path); | |
| 132 | } | |
| 133 | ||
| 8c361d7c | 134 | drupal_uninstall_schema('imagecache'); |
| 19fefb49 DP |
135 | } |
| 136 | ||
| 2d6b7863 | 137 | // Add action id to actions table. |
| ed7d47b6 | 138 | function imagecache_update_1() { |
| 2d6b7863 DP |
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; | |
| 23c2a416 | 156 | |
| 2d6b7863 DP |
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 | ||
| 23c2a416 | 167 | /** |
| 2d6b7863 | 168 | * Remove auto-increment from tables, instead depending on the sequences table and db_next_id() |
| 23c2a416 | 169 | */ |
| 2d6b7863 DP |
170 | function imagecache_update_3() { |
| 171 | $ret = array(); | |
| 23c2a416 | 172 | |
| 2d6b7863 DP |
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; | |
| 23c2a416 | 175 | |
| 2d6b7863 DP |
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; | |
| ed7d47b6 | 196 | } |
| 1c784f3b | 197 | |
| 650d9de9 DP |
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"); | |
| e179eb81 | 206 | break; |
| 650d9de9 | 207 | case 'pgsql': |
| 183ee288 | 208 | $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) NOT NULL DEFAULT ''"); |
| 650d9de9 DP |
209 | break; |
| 210 | } | |
| 211 | ||
| 212 | // unserialize what we can. | |
| 213 | $result = db_query("SELECT * FROM {imagecache_action}"); | |
| 65312e36 | 214 | while ($row = db_fetch_array($result)) { |
| 650d9de9 | 215 | $data = unserialize($row['data']); |
| 8e83c5be DP |
216 | |
| 217 | // remove function from data if present; | |
| 650d9de9 DP |
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 | } | |
| 23c2a416 | 226 | // Keep scale and crop and the old scale function seperate... I don't really want to break BC with |
| 650d9de9 DP |
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 | } | |
| a5dfad85 | 239 | cache_clear_all('*', 'cache', TRUE); |
| 650d9de9 DP |
240 | return $ret; |
| 241 | } | |
| 242 | ||
| d7ac7c8c | 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 | |
| 12bbac9e | 249 | // ln: 516 diff 511. |
| 650d9de9 | 250 | |
| 12bbac9e | 251 | return array(); |
| 252 | } | |
| 6a40afd6 | 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) { | |
| 6a40afd6 | 295 | $field = $info['primary key'][0]; |
| 470939d5 | 296 | if (db_table_exists('sequences')) { |
| 6a40afd6 | 297 | $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{{$table}}_{$field}'"); |
| 298 | } | |
| 470939d5 | 299 | db_change_field($ret, $table, $field, $field, $info['fields'][$field]); |
| 6a40afd6 | 300 | } |
| 301 | ||
| 470939d5 | 302 | // Going to assume that if the table doesn't have a module column that |
| 303 | // it needs the index as well. | |
| 6a40afd6 | 304 | if (!db_column_exists('imagecache_action', 'module')) { |
| 470939d5 | 305 | // Add 'module' column to action table. |
| 6a40afd6 | 306 | db_add_field($ret, 'imagecache_action', 'module', $schema['imagecache_action']['fields']['module']); |
| 470939d5 | 307 | |
| 308 | // Add 'presetid' index to action table | |
| 309 | db_add_index($ret, 'imagecache_action', 'presetid', array('presetid')); | |
| 6a40afd6 | 310 | } |
| 311 | ||
| 6a40afd6 | 312 | |
| 313 | return $ret; | |
| 314 | } | |
| 65e8db7c | 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 | } |