You are here

function uc_order_update_3 in Ubercart 5

File

uc_order/uc_order.install, line 275

Code

function uc_order_update_3() {
  $ret = array();

  // Update orders and comments to hold string values for order statuses.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_orders} CHANGE order_status order_status VARCHAR(32) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_order_comments} CHANGE order_status order_status VARCHAR(32) NOT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'uc_orders', 'order_status', 'order_status', 'varchar(32)', array(
        'not null' => true,
        'default' => "''",
      ));
      db_change_column($ret, 'uc_order_comments', 'order_status', 'order_status', 'varchar(32)', array(
        'not null' => true,
        'default' => "''",
      ));
      break;
  }
  $ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'in_checkout' WHERE order_status = '0'");
  $ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'pending' WHERE order_status = '1'");
  $ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'processing' WHERE order_status = '2' OR order_status = '3'");
  $ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'completed' WHERE order_status = '4'");
  $ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'in_checkout' WHERE order_status = '0'");
  $ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'pending' WHERE order_status = '1'");
  $ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'processing' WHERE order_status = '2' OR order_status = '3'");
  $ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'completed' WHERE order_status = '4'");

  // Clean out the old order status table and redefine its structure.
  if ($_SESSION['statuses'] !== TRUE) {
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE order_status_id order_status_id VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
        $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE title title VARCHAR(48) CHARACTER SET utf8 NOT NULL default ''");
        $ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE notify state VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
        $ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD weight MEDIUMINT(9) NOT NULL");
        $ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD locked TINYINT NOT NULL DEFAULT '0'");
        break;
      case 'pgsql':
        db_change_column($ret, 'uc_order_statuses', 'order_status_id', 'order_status_id', 'varchar(32) CHARACTER SET utf8', array(
          'not null' => true,
          'default' => "''",
        ));
        db_change_column($ret, 'uc_order_statuses', 'title', 'title', 'varchar(48) CHARACTER SET utf8', array(
          'not null' => true,
          'default' => "''",
        ));
        db_change_column($ret, 'uc_order_statuses', 'notify', 'state', 'varchar(32) CHARACTER SET utf8', array(
          'not null' => true,
          'default' => "''",
        ));
        db_add_column($ret, 'uc_order_statuses', 'weight', 'integer', array(
          'not null' => true,
          'default' => 0,
        ));
        db_add_column($ret, 'uc_order_statuses', 'locked', 'smallint', array(
          'not null' => true,
          'default' => 0,
        ));
        break;
    }
    $ret[] = update_sql("DELETE FROM {uc_order_statuses} WHERE order_status_id LIKE '_'");
    $_SESSION['statuses'] = TRUE;
  }

  // Fill the table with the new default order statuses.
  $t = get_t();
  $ret[] = update_sql("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES " . "('canceled', '" . $t('Canceled') . "', 'canceled', -20, 1), " . "('in_checkout', '" . $t('In checkout') . "', 'in_checkout', -10, 1), " . "('pending', '" . $t('Pending') . "', 'post_checkout', 0, 1), " . "('processing', '" . $t('Processing') . "', 'post_checkout', 5, 1), " . "('completed', '" . $t('Completed') . "', 'completed', 20, 1);");
  return $ret;
}