4 function imagecache_requirements($phase) {
5 $requirements = array();
6 // Ensure translations don't break at install time.
9 if ($phase == 'runtime') {
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 does not a directory or is not readable by the webserver.', array('%p' => $imagecache_directory)),
17 'severity' => REQUIREMENT_ERROR
,
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
,
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
,
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
,
48 function imagecache_schema() {
49 $schema['imagecache_preset'] = array(
52 'description' => t('The primary identifier for an imagecache_preset.'),
56 'presetname' => array(
57 'description' => t('The primary identifier for a node.'),
62 'primary key' => array('presetid'),
65 $schema['imagecache_action'] = array(
68 'description' => t('The primary identifier for an imagecache_action.'),
73 'description' => t('The primary identifier for an imagecache_preset.'),
79 'description' => t('The weight of the action in the preset.'),
85 'description' => t('The module that defined the action.'),
90 'description' => t('The unique ID of the action to be executed.'),
95 'description' => t('The configuration data for the action.'),
101 'primary key' => array('actionid'),
103 'presetid' => array('presetid'),
113 * Implementation of hook_install().
115 function imagecache_install() {
116 drupal_install_schema('imagecache');
120 * Implementation of hook_uninstall().
122 function imagecache_uninstall() {
123 // Remove any cached images.
124 $path = file_directory_path() .
'/imagecache/';
126 _imagecache_recursive_delete($path);
129 drupal_uninstall_schema('imagecache');
132 // Add action id to actions table.
133 function imagecache_update_1() {
135 $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL primary key auto_increment');
139 // Rename rulesets to presets; Make all table names singular;
140 function imagecache_update_2() {
142 $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} RENAME TO {imagecache_preset}');
143 $ret[] = update_sql('ALTER TABLE {imagecache_actions} RENAME TO {imagecache_action}');
144 switch ($GLOBALS['db_type']) {
147 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetid presetid INT UNSIGNED NOT NULL AUTO_INCREMENT');
148 $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\'');
149 $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid INTEGER NOT NULL DEFAULT 0');
153 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid');
154 $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname');
155 $ret[] = update_sql('ALTER TABLE {imagecache_action} RENAME COLUMN rulesetid TO presetid');
163 * Remove auto-increment from tables, instead depending on the sequences table and db_next_id()
165 function imagecache_update_3() {
168 $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1;
169 $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1;
171 switch ($GLOBALS['db_type']) {
174 $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL");
175 $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL");
177 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', $count_action)");
178 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', $count_preset)");
181 db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE
, 'default' => '0'));
182 db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array('not null' => TRUE
, 'default' => '0'));
183 // Re-add our indexes
184 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)");
185 $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)");
187 $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START $count_action;");
188 $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START $count_preset;");
193 function imagecache_update_4() {
196 // add action column to the imagecache_action table just becuase serialization bugs me.
197 switch ($GLOBALS['db_type']) {
200 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) not null default '' after weight");
202 $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) NOT NULL DEFAULT ''");
206 // unserialize what we can.
207 $result = db_query("SELECT * FROM {imagecache_action}");
208 while ($row = db_fetch_array($result)) {
209 $data = unserialize($row['data']);
211 // remove function from data if present;
212 $function = $data['function'];
213 unset($data['function']);
214 $data = serialize($data);
216 // Rename scale and crop for any people who upgraded early...
217 if ($function == 'scale and crop') {
218 $function = 'scale_and_crop';
220 // Keep scale and crop and the old scale function seperate... I don't really want to break BC with
221 // the 2.x update. We'll deprecate this version.
222 if ($function == 'scale') {
223 $function = 'deprecated_scale';
226 // prefix with module name as per new status quo.
227 // since other modules couldn't implement actions before this update
228 // we assume imagecache...
229 $function = 'imagecache_'.
$function;
231 db_query("UPDATE {imagecache_action} SET action='%s', data='%s' WHERE actionid = %d", $function, $data, $row['actionid']);
233 cache_clear_all('*', 'cache', TRUE
);
237 function imagecache_update_5() {
239 module_rebuild_cache(); // make sure new modules are in the system table.
240 module_enable(array('imageapi', 'imageapi_gd', 'imageapi_imagemagick')); // enable our new module.
242 // @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