You are here

function imagecrop_update_6100 in Image javascript crop 6

Update 6100 : Change preset ids into preset names, and add correct primary key for it.

File

./imagecrop.install, line 81
Install file.

Code

function imagecrop_update_6100() {
  $ret[] = update_sql("ALTER TABLE {imagecrop} ADD presetname VARCHAR(255)");

  // Get all presets.
  $presets = array();
  $result = db_query('SELECT presetid, presetname FROM {imagecache_preset}');
  while ($row = db_fetch_object($result)) {
    $presets[$row->presetid] = $row->presetname;
  }

  // Get all presetids and update them.
  $result = db_query('SELECT DISTINCT(presetid) FROM {imagecrop}');
  while ($row = db_fetch_object($result)) {

    // Only update when the presetname exists.
    if (!isset($presets[$row->presetid])) {
      return;
    }
    $preset = db_escape_string($presets[$row->presetid]);
    $ret[] = update_sql("UPDATE {imagecrop} SET presetname = '{$preset}' WHERE presetid = {$row->presetid}");
  }
  db_drop_index($ret, 'imagecrop', 'fid');
  db_drop_field($ret, 'imagecrop', 'presetid');
  db_add_primary_key($ret, 'imagecrop', array(
    'fid, presetname',
  ));
  return $ret;
}