You are here

function uc_coupon_update_6000 in Ubercart Discount Coupons 6

File

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

Code

function uc_coupon_update_6000() {
  $ret = array();
  if (!db_column_exists('uc_coupons', 'data')) {
    db_add_field($ret, 'uc_coupons', 'data', array(
      'type' => 'text',
    ));
    $result = db_query('SELECT cid, products, users, roles FROM {uc_coupons}');
    while ($row = db_fetch_object($result)) {
      $data = array(
        'wholesale' => $row->roles,
      );
      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);
    }
    db_drop_field($ret, 'uc_coupons', 'products');
    db_drop_field($ret, 'uc_coupons', 'users');
    db_drop_field($ret, 'uc_coupons', 'roles');
    db_drop_field($ret, 'uc_coupons_orders', 'user');
    db_drop_field($ret, 'uc_coupons_orders', 'role');
  }
  return $ret;
}