0), presetname VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (presetid)); "); $ret2 = db_query("CREATE TABLE {imagecache_action} ( actionid INTEGER NOT NULL CHECK (actionid > 0), presetid INTEGER NOT NULL DEFAULT 0, weight INTEGER NOT NULL DEFAULT 0, module varchar(255) not null default '', action varchar(255) not null default '', data TEXT NOT NULL DEFAULT '', PRIMARY KEY (actionid)); "); db_query("CREATE SEQUENCE imagecache_preset_presetid_seq INCREMENT 1 START 1;"); db_query("CREATE SEQUENCE imagecache_action_actionid_seq INCREMENT 1 START 1;"); break; } if ($ret1 && $ret2) { drupal_set_message(t('Imagecache module installed succesfully.')); } else { drupal_set_message(t('Imagecache module installation was unsuccessfull. Necessary database tables should be created by hand.', 'error')); } return $ret; } // Add action id to actions table. function imagecache_update_1() { $ret = array(); $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL primary key auto_increment'); return $ret; } // Rename rulesets to presets; Make all table names singular; function imagecache_update_2() { $ret = array(); $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} RENAME TO {imagecache_preset}'); $ret[] = update_sql('ALTER TABLE {imagecache_actions} RENAME TO {imagecache_action}'); switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetid presetid INT UNSIGNED NOT NULL AUTO_INCREMENT'); $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\''); $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid INTEGER NOT NULL DEFAULT 0'); break; case 'pgsql': $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid'); $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname'); $ret[] = update_sql('ALTER TABLE {imagecache_action} RENAME COLUMN rulesetid TO presetid'); break; } return $ret; } /** * Remove auto-increment from tables, instead depending on the sequences table and db_next_id() */ function imagecache_update_3() { $ret = array(); $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1; $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1; switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL"); $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL"); // Add the sequences $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', $count_action)"); $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', $count_preset)"); break; case 'pgsql': db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0')); db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0')); // Re-add our indexes $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)"); $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)"); // Add the sequences $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START $count_action;"); $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START $count_preset;"); } return $ret; } function imagecache_update_4() { $ret = array(); // add action column to the imagecache_action table just becuase serialization bugs me. switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) not null default '' after weight"); case 'pgsql': // @todo: pgsql updates. break; } // unserialize what we can. $result = db_query("SELECT * FROM {imagecache_action}"); while($row = db_fetch_array($result)) { $data = unserialize($row['data']); // Keep scale and crop and the old scale function seperate... I don't really want to break BC with // the 2.x update. We'll deprecate this version. $function = $data['function']; unset($data['function']); $data = serialize($data); // Rename scale and crop for any people who upgraded early... if ($function == 'scale and crop') { $function = 'scale_and_crop'; } // Keep scale and crop and the old scale function seperate... I don't really want to break BC with // the 2.x update. We'll deprecate this version. if ($function == 'scale') { $function = 'deprecated_scale'; } // prefix with module name as per new status quo. // since other modules couldn't implement actions before this update // we assume imagecache... $function = 'imagecache_'. $function; db_query("UPDATE {imagecache_action} SET action='%s', data='%s' WHERE actionid = %d", $function, $data, $row['actionid']); } return $ret; } /** * Implementation of hook_uninstall(). */ function imagecache_uninstall() { db_query('DROP TABLE {imagecache_preset}'); db_query('DROP TABLE {imagecache_action}'); switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': db_query("DELETE FROM {sequences} WHERE name = '{imagecache_action}_actionid'"); db_query("DELETE FROM {sequences} WHERE name = '{imagecache_action}_presetid'"); break; case 'pgsql': db_query('DROP SEQUENCE {imagecache_action}_actionid_seq'); db_query('DROP SEQUENCE {imagecache_preset}_presetid_seq'); break; } }