You are here

function casetracker_update_3 in Case Tracker 5

File

./casetracker.install, line 194

Code

function casetracker_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {casetracker_case} ADD vid int(10) unsigned NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {casetracker_case} ADD UNIQUE KEY vid (vid)");
      $ret[] = update_sql("ALTER TABLE {casetracker_case} ADD KEY nid (nid)");
      $ret[] = update_sql("ALTER TABLE {casetracker_case} ADD KEY p_id (p_id)");
      $result = db_query('SELECT n.vid, n.nid FROM {node} n INNER JOIN {casetracker_project} p ON p.nid = n.nid');
      while ($node = db_fetch_object($result)) {

        // add support for revisions of project node types.
        db_query('UPDATE {casetracker_project} SET vid = %d WHERE nid = %d', $node->vid, $node->nid);
      }
      $ret[] = update_sql("ALTER TABLE {casetracker_project} DROP PRIMARY KEY");
      $ret[] = update_sql("ALTER TABLE {casetracker_project} ADD PRIMARY KEY vid (vid)");
      $ret[] = update_sql("ALTER TABLE {casetracker_project} ADD KEY nid (nid)");
      break;
  }
  return $ret;
}