Commit 5d3ec7aa authored by Devin Zuczek's avatar Devin Zuczek
Browse files

Issue #1517284: translate old certificate column on course_node to creation of...

Issue #1517284: translate old certificate column on course_node to creation of a course object at the end of the course if it does not already have one
parent 9507758b
Loading
Loading
Loading
Loading
+41 −0
Changes for modules/course_certificate/course_certificate.install: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

function course_certificate_install() {
  course_certificate_update_6101();
}

/**
 * Create certificate course objects at the end of a course for courses that had
 * the "certificate" checkbox checked. Drop the old field.
 */
function course_certificate_update_6101() {
  $ret = array();
  drupal_get_schema(NULL, TRUE);
  drupal_load('module', 'uuid');

  if (db_column_exists('course_node', 'certificate')) {
    // Find courses that had certificate checked, but no course object.
    $sql = "select * from {course_node} cn
      inner join {course_outline} co on (cn.nid = co.nid and co.requirement_type = 'course_certificate')
      where cn.certificate and co.snid is null";
    $result = db_query($sql);
    while ($row = db_fetch_object($result)) {
      $object = array(
        'requirement_type' => 'course_certificate',
        'requirement_component' => 'certificate',
        'nid' => $row->nid,
        'enabled' => 1,
        'required' => 0,
        'hidden' => 0,
        'title' => 'Certificate',
        'weight' => 999,
        'uuid' => uuid_uuid(),
      );
      drupal_write_record('course_outline', $object);
    }
  }

  db_drop_field($ret, 'course_node', 'certificate');

  return $ret;
}