You are here

function imagecache_update_4 in ImageCache 6.2

Same name and namespace in other branches
  1. 5.2 imagecache.install \imagecache_update_4()

File

./imagecache.install, line 197

Code

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");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) NOT NULL DEFAULT ''");
      break;
  }

  // unserialize what we can.
  $result = db_query("SELECT * FROM {imagecache_action}");
  while ($row = db_fetch_array($result)) {
    $data = unserialize($row['data']);

    // remove function from data if present;
    $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']);
  }
  cache_clear_all('*', 'cache', TRUE);
  return $ret;
}