You are here

function uc_catalog_update_7 in Ubercart 5

File

uc_catalog/uc_catalog.install, line 158

Code

function uc_catalog_update_7() {
  $ret = array();
  if (module_exists('imagecache')) {
    if (db_num_rows(db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'uc_category'")) == 0) {
      $preset_id = db_next_id('{imagecache_preset}_presetid');
      $action_id = db_next_id('{imagecache_action}_actionid');
      db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'uc_category')", $preset_id);
      db_query("INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (%d, %d, 0, '%s')", $action_id, $preset_id, 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"96";s:6:"height";s:2:"96";}');
      cache_clear_all('imagecache:presets', 'cache');
      $ret[] = array(
        'success' => TRUE,
        'query' => "INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (" . $preset_id . ", 'uc_category')",
      );
      $ret[] = array(
        'success' => TRUE,
        'query' => "INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (" . $action_id . ", " . $preset_id . ", 0, '" . 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"96";s:6:"height";s:2:"96";}' . "')",
      );
      if ($old_id = db_result(db_query("SELECT presetid FROM {imagecache_preset} WHERE presetname = 'uc_catalog'"))) {
        _imagecache_preset_flush($old_id);
        db_query("DELETE FROM {imagecache_preset} WHERE presetid = %d", $old_id);
        db_query("DELETE FROM {imagecache_action} WHERE presetid = %d", $old_id);
        $ret[] = array(
          'success' => TRUE,
          'query' => "DELETE FROM {imagecache_action} WHERE presetid = {$old_id}",
        );
        $ret[] = array(
          'success' => TRUE,
          'query' => "DELETE FROM {imagecache_action} WHERE presetid = {$old_id}",
        );
        _imagecache_get_presets(TRUE);
      }
    }
  }
  return $ret;
}