Exemple #1
0
/**
 * Check if there are some legacy workshop 1.x data to be migrated and upgrade them
 *
 * This must be called after workshop core migration has finished so that
 * all assessments are already upgraded and tables are correctly renamed.
 */
function workshopform_comments_upgrade_legacy() {
    global $CFG, $DB, $OUTPUT;
    require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php');

    if (!workshopform_comments_upgrade_legacy_needed()) {
        return;
    }

    // get the list of all legacy workshops using this grading strategy
    if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 0), 'course,id', 'id')) {
        echo $OUTPUT->notification('Copying assessment forms elements', 'notifysuccess');
        $legacyworkshops = array_keys($legacyworkshops);
        // get the list of all form elements
        list($workshopids, $params) = $DB->get_in_or_equal($legacyworkshops, SQL_PARAMS_NAMED);
        $sql = "SELECT *
                  FROM {workshop_elements_old}
                 WHERE workshopid $workshopids
                       AND newid IS NULL";
        $rs = $DB->get_recordset_sql($sql, $params);
        foreach ($rs as $old) {
            $new = workshopform_comments_upgrade_element($old, $old->workshopid);
            $newid = $DB->insert_record('workshopform_comments', $new);
            $DB->set_field('workshop_elements_old', 'newplugin', 'comments', array('id' => $old->id));
            $DB->set_field('workshop_elements_old', 'newid', $newid, array('id' => $old->id));
        }
        $rs->close();

        // now we need to reload the legacy element ids
        $newelementids = workshop_upgrade_element_id_mappings('comments');

        // migrate all comments for these elements (it est the values that reviewers put into forms)
        echo $OUTPUT->notification('Copying assessment form comments', 'notifysuccess');
        $sql = "SELECT *
                  FROM {workshop_grades_old}
                 WHERE workshopid $workshopids
                       AND newid IS NULL";
        $rs = $DB->get_recordset_sql($sql, $params);
        $newassessmentids = workshop_upgrade_assessment_id_mappings();
        foreach ($rs as $old) {
            if (!isset($newassessmentids[$old->assessmentid])) {
                // orphaned comment - the assessment was removed but the grade remained
                continue;
            }
            if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) {
                // orphaned comment - the assessment form element has been removed after the grade was recorded
                continue;
            }
            $new = workshopform_comments_upgrade_grade($old, $newassessmentids[$old->assessmentid],
                                                         $newelementids[$old->workshopid][$old->elementno]);
            $newid = $DB->insert_record('workshop_grades', $new);
            $DB->set_field('workshop_grades_old', 'newplugin', 'comments', array('id' => $old->id));
            $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id));
        }
        $rs->close();
    }
}
Exemple #2
0
 /**
  * Converts <ELEMENT> into <workshopform_comments_dimension>
  *
  * @param array $data legacy element data
  * @param array $raw raw element data
  *
  * @return array converted
  */
 public function process_legacy_element(array $data, array $raw)
 {
     // prepare a fake record and re-use the upgrade logic
     $fakerecord = (object) $data;
     $converted = (array) workshopform_comments_upgrade_element($fakerecord, 12345678);
     unset($converted['workshopid']);
     $converted['id'] = $data['id'];
     $this->write_xml('workshopform_comments_dimension', $converted, array('/workshopform_comments_dimension/id'));
     return $converted;
 }