You are here

function course_update_6126 in Course 6

Same name and namespace in other branches
  1. 7.2 course.install \course_update_6126()
  2. 7 course.install \course_update_6126()

Delete old fulfillment duplicates. Add indexes to outline and fulfillment table. Change grade_result to signed.

File

./course.install, line 543
course.install Install and update functions for Courses.

Code

function course_update_6126() {
  $ret = array();
  $sql = "SELECT * FROM {course_outline_fulfillment} order by sfid asc";
  $result = db_query($sql);
  $sfids = array();
  $delete = array();
  while ($row = db_fetch_object($result)) {
    if ($sfids[$row->snid][$row->uid]) {
      $delete[] = $sfids[$row->snid][$row->uid];
    }
    $sfids[$row->snid][$row->uid] = $row->sfid;
  }
  if ($delete) {
    $placeholders = db_placeholders($delete);
    $sql = "DELETE FROM {course_outline_fulfillment} WHERE sfid in ({$placeholders})";
    $ret[] = array(
      'success' => db_query($sql, $delete),
      'query' => $sql,
    );
  }
  db_add_unique_key($ret, 'course_outline_fulfillment', 'snid_uid', array(
    'snid',
    'uid',
  ));
  db_add_index($ret, 'course_outline_fulfillment', 'snid', array(
    'snid',
  ));
  db_add_index($ret, 'course_outline', 'nid', array(
    'nid',
  ));
  db_change_field($ret, 'course_outline_fulfillment', 'grade_result', 'grade_result', array(
    'type' => 'int',
    'not null' => TRUE,
    'unsigned' => FALSE,
    'default' => 0,
    'description' => 'grade_result',
  ));
  return $ret;
}