You are here

function casetracker_update_13 in Case Tracker 5

File

./casetracker.install, line 372

Code

function casetracker_update_13() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $result = db_query('SELECT * FROM {casetracker_case_priority}');
      while ($priority = db_fetch_object($result)) {
        db_query("INSERT INTO {casetracker_case_states} (case_state_name, case_state_realm) VALUES ('%s', '%s')", $priority->case_priority, 'priority');
        $new_id = _casetracker_update_db_next_id();

        // get the MySQL ID created by the previous insert.
        db_query('UPDATE {casetracker_case} SET case_priority_id = %d WHERE case_priority_id = %d', $new_id, $priority->case_priority_id);
        db_query('UPDATE {casetracker_comment_status} SET case_priority_id = %d WHERE case_priority_id = %d', $new_id, $priority->case_priority_id);
      }
      db_query('DROP TABLE {casetracker_case_priority}');
      $result = db_query('SELECT * FROM {casetracker_case_status}');
      while ($status = db_fetch_object($result)) {
        db_query("INSERT INTO {casetracker_case_states} (case_state_name, case_state_realm) VALUES ('%s', '%s')", $status->case_status_name, 'status');
        $new_id = _casetracker_update_db_next_id();

        // get the MySQL ID created by the previous insert.
        db_query('UPDATE {casetracker_case} SET case_status_id = %d WHERE case_status_id = %d', $new_id, $status->case_status_id);
        db_query('UPDATE {casetracker_comment_status} SET case_status_id = %d WHERE case_status_id = %d', $new_id, $status->case_status_id);
      }
      db_query('DROP TABLE {casetracker_case_status}');
      $result = db_query('SELECT * FROM {casetracker_case_type}');
      while ($type = db_fetch_object($result)) {
        db_query("INSERT INTO {casetracker_case_states} (case_state_name, case_state_realm) VALUES ('%s', '%s')", $type->case_type, 'type');
        $new_id = _casetracker_update_db_next_id();

        // get the MySQL ID created by the previous insert.
        db_query('UPDATE {casetracker_case} SET case_type_id = %d WHERE case_type_id = %d', $new_id, $priority->case_type_id);
        db_query('UPDATE {casetracker_comment_status} SET case_type_id = %d WHERE case_type_id = %d', $new_id, $type->case_type_id);
      }
      db_query('DROP TABLE {casetracker_case_type}');
      break;
  }
  return $ret;
}