You are here

function uc_coupon_update_2 in Ubercart Discount Coupons 5

File

./uc_coupon.install, line 49
Ubercart uc_coupon.module schema

Code

function uc_coupon_update_2() {
  $ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN data text");
  $result = db_query('SELECT cid, products, users FROM {uc_coupons}');
  while ($row = db_fetch_object($result)) {
    $data = array();
    if ($row->products) {
      $data['products'] = explode(',', $row->products);
    }
    if ($row->users) {

      // substr() removes the final comma that was present in the previous strings.
      $data['users'] = explode(',', substr($row->users, 0, -1));
    }
    db_query("UPDATE {uc_coupons} SET data = '%s' WHERE cid = %d", serialize($data), $row->cid);
  }
  $ret[] = update_sql("ALTER TABLE {uc_coupons} DROP COLUMN products");
  $ret[] = update_sql("ALTER TABLE {uc_coupons} DROP COLUMN users");

  // These columns were never used.
  $ret[] = update_sql("ALTER TABLE {uc_coupons_orders} DROP COLUMN user");
  $ret[] = update_sql("ALTER TABLE {uc_coupons_orders} DROP COLUMN role");
  return $ret;
}