You are here

function course_update_6133 in Course 7

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

Change schema, so all literal date fields can be NULL with no default.

File

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

Code

function course_update_6133() {
  $change = array();
  $change['course_enrolment'][] = 'created';
  $change['course_enrolment'][] = 'timestamp';
  $change['course_enrolment'][] = 'enrol_end';
  $change['course_node'][] = 'open';
  $change['course_node'][] = 'close';
  $change['course_node'][] = 'duration';
  $type = array(
    'type' => 'int',
    'not null' => FALSE,
    'unsigned' => TRUE,
    'default' => NULL,
  );
  foreach ($change as $table => $fields) {
    foreach ($fields as $field) {

      // Change schema definition.
      db_change_field($table, $field, $field, $type);

      // Change values to NULL where 0 was stored.
      $sql = "UPDATE {{$table}} SET {$field} = NULL WHERE {$field} = 0";
      db_query($sql);
    }
  }
  return t('Let date fields be NULL.');
}