You are here

function course_update_6122 in Course 7

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

Migrate and remove old fields that won't be used anymore.

File

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

Code

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

  // Migrate any passing grade to serialized storage.
  $sql = "SELECT * FROM {course_outline}";
  $result = db_query($sql);
  while ($row = $result
    ->fetch()) {
    $row->data = unserialize($row->data);
    if (!is_array($row->data)) {
      $row->data = array();
    }
    $row->data['passing_grade'] = $row->passing_grade;
    $row->data = serialize($row->data);
    db_update('course_outline')
      ->fields(array(
      'data' => $row->data,
    ))
      ->condition('snid', $row->snid)
      ->execute();
  }
  $deletes = array(
    array(
      'course_node',
      'outline_custom_titles',
    ),
    array(
      'course_outline',
      'graded',
    ),
    array(
      'course_outline',
      'passing_grade',
    ),
    array(
      'course_outline',
      'payment_required',
    ),
  );
  foreach ($deletes as $delete) {
    $table = $delete[0];
    $column = $delete[1];
    if (db_field_exists($table, $column)) {
      db_drop_field($table, $column);
    }
  }

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.
  return t('TODO Add a descriptive string here to show in the UI.');
}