/** * 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_accumulative_upgrade_legacy() { global $CFG, $DB, $OUTPUT; require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php'); if (!workshopform_accumulative_upgrade_legacy_needed()) { return; } // get the list of all legacy workshops using this grading strategy if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 1), '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); // prepare system (global) scales to replace the legacy in-built ones $newscaleids = workshopform_accumulative_upgrade_scales(); foreach ($rs as $old) { $new = workshopform_accumulative_upgrade_element($old, $newscaleids, $old->workshopid); $newid = $DB->insert_record('workshopform_accumulative', $new); $DB->set_field('workshop_elements_old', 'newplugin', 'accumulative', 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 ids. Although we have them in $newelements after the first run, we must // refetch them from DB so that this function can be called during recovery $newelementids = workshop_upgrade_element_id_mappings('accumulative'); // migrate all grades for these elements (it est the values that reviewers put into forms) echo $OUTPUT->notification('Copying assessment form grades', '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 grade - the assessment was removed but the grade remained continue; } if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) { // orphaned grade - the assessment form element has been removed after the grade was recorded continue; } $new = workshopform_accumulative_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', 'accumulative', array('id' => $old->id)); $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id)); } $rs->close(); } }
/** * 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(); } }
/** * Upgrades legacy workshops using rubric grading strategy */ function workshopform_rubric_upgrade_legacy_rubric() { global $CFG, $DB, $OUTPUT; require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php'); // get the list of all legacy workshops using this grading strategy if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 4), 'course,id', 'id')) { echo $OUTPUT->notification('Copying rubric assessment form elements', 'notifysuccess'); $legacyworkshops = array_keys($legacyworkshops); // get the list of all form elements and rubrics list($workshopids, $params) = $DB->get_in_or_equal($legacyworkshops, SQL_PARAMS_NAMED); $sql = "SELECT e.id AS eid, e.workshopid AS workshopid, e.elementno AS esort, e.description AS edesc, e.weight AS eweight, r.id AS rid, r.rubricno AS rgrade, r.description AS rdesc FROM {workshop_elements_old} e LEFT JOIN {workshop_rubrics_old} r ON (r.elementno = e.elementno AND r.workshopid = e.workshopid) WHERE e.workshopid $workshopids AND e.newid IS NULL AND r.newid IS NULL ORDER BY e.workshopid, e.elementno, r.rubricno"; $rs = $DB->get_recordset_sql($sql, $params); $newdimensionids = array(); // (int)workshopid => (int)elementno => (int)dimensionid $newlevelids = array(); // (int)oldrubricid => (int)newlevelid $prevelement = null; foreach ($rs as $old) { // create rubric criterion and the configuration if necessary if (!isset($newdimensionids[$old->workshopid]) or !isset($newdimensionids[$old->workshopid][$old->esort])) { if (!$DB->record_exists('workshopform_rubric', array('workshopid' => $old->workshopid, 'sort' => $old->esort))) { $newdimension = new stdclass(); $newdimension->workshopid = $old->workshopid; $newdimension->sort = $old->esort; $newdimension->description = $old->edesc; $newdimension->descriptionformat = FORMAT_HTML; $newdimensionids[$old->workshopid][$old->esort] = $DB->insert_record('workshopform_rubric', $newdimension); } else { $newdimensionids[$old->workshopid][$old->esort] = $DB->get_field('workshopform_rubric', 'id', array('workshopid' => $old->workshopid, 'sort' => $old->esort)); } if (!$DB->record_exists('workshopform_rubric_config', array('workshopid' => $old->workshopid))) { $newconfig = new stdclass(); $newconfig->workshopid = $old->workshopid; $newconfig->layout = 'grid'; $DB->insert_record('workshopform_rubric_config', $newconfig); } } // process the information about the criterion levels if (trim($old->rdesc)) { $new = workshopform_rubric_upgrade_rubric_level($old, $newdimensionids[$old->workshopid][$old->esort]); $newid = $DB->insert_record('workshopform_rubric_levels', $new); $DB->set_field('workshop_rubrics_old', 'newplugin', 'rubric_levels', array('id' => $old->rid)); $DB->set_field('workshop_rubrics_old', 'newid', $newid, array('id' => $old->rid)); } // mark the whole element as processed if the last level was processed if ($old->rgrade == 4) { $DB->set_field('workshop_elements_old', 'newplugin', 'rubric', array('id' => $old->eid)); $DB->set_field('workshop_elements_old', 'newid', $newdimensionids[$old->workshopid][$old->esort], array('id' => $old->eid)); } } $rs->close(); // reload the mappings - this must be reloaded so that we can run this during recovery $newelementids = workshop_upgrade_element_id_mappings('rubric'); // load the legacy element weights and multiply the new max grade by it echo $OUTPUT->notification('Recalculating rubric assessment form element weights', 'notifysuccess'); $oldweights = $DB->get_records('workshop_elements_old', array('newplugin' => 'rubric'), '', 'id,workshopid,elementno,weight'); $newweights = array(); foreach ($oldweights as $eid => $element) { $newweights[$newelementids[$element->workshopid][$element->elementno]->newid] = workshopform_rubric_upgrade_weight($element->weight); } unset($oldweights); unset($element); // migrate all grades for these elements (it est the values that reviewers put into forms) echo $OUTPUT->notification('Copying rubric assessment form grades', '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($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) { // orphaned grade - the assessment form element has been removed after the grade was recorded continue; } $new = new stdclass(); $new->assessmentid = $newassessmentids[$old->assessmentid]; $new->strategy = 'rubric'; $new->dimensionid = $newelementids[$old->workshopid][$old->elementno]->newid; $new->grade = $old->grade * $newweights[$new->dimensionid]; $new->peercomment = $old->feedback; $new->peercommentformat = FORMAT_HTML; $newid = $DB->insert_record('workshop_grades', $new); $DB->set_field('workshop_grades_old', 'newplugin', 'rubric', array('id' => $old->id)); $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id)); } $rs->close(); } }
/** * 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_numerrors_upgrade_legacy() { global $CFG, $DB, $OUTPUT; require_once($CFG->dirroot . '/mod/workshop/db/upgradelib.php'); if (!workshopform_numerrors_upgrade_legacy_needed()) { return; } // get the list of all legacy workshops using this grading strategy if ($legacyworkshops = $DB->get_records('workshop_old', array('gradingstrategy' => 2), 'course,id', 'id')) { echo $OUTPUT->notification('Copying assessment forms elements and grade mappings', 'notifysuccess'); $legacyworkshops = array_keys($legacyworkshops); // get some needed info about the workshops $workshopinfos = $DB->get_records_list('workshop_old', 'id', $legacyworkshops, 'id', 'id,grade'); // 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) { // process the information about mapping $newmapping = new stdclass(); $newmapping->workshopid = $old->workshopid; $newmapping->nonegative = $old->elementno; $newmapping->grade = $old->maxscore; if ($old->maxscore > 0) { $newmapping->grade = grade_floatval($old->maxscore / $workshopinfos[$old->workshopid]->grade * 100); } else { $newmapping->grade = 0; } $DB->delete_records('workshopform_numerrors_map', array('workshopid' => $newmapping->workshopid, 'nonegative' => $newmapping->nonegative)); $DB->insert_record('workshopform_numerrors_map', $newmapping); // process the information about the element itself if (trim($old->description) and $old->description <> '@@ GRADE_MAPPING_ELEMENT @@') { $new = workshopform_numerrors_upgrade_element($old, $old->workshopid); $newid = $DB->insert_record('workshopform_numerrors', $new); } else { $newid = 0; } $DB->set_field('workshop_elements_old', 'newplugin', 'numerrors', 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 ids. Although we have them in $newelements after the first run, we must // refetch them from DB so that this function can be called during recovery $newelementids = workshop_upgrade_element_id_mappings('numerrors'); // migrate all grades for these elements (it est the values that reviewers put into forms) echo $OUTPUT->notification('Copying assessment form grades', '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 grade - the assessment was removed but the grade remained continue; } if (!isset($newelementids[$old->workshopid]) or !isset($newelementids[$old->workshopid][$old->elementno])) { // orphaned grade - the assessment form element has been removed after the grade was recorded continue; } $newelementinfo = $newelementids[$old->workshopid][$old->elementno]; if ($newelementinfo->newid == 0 or $old->feedback == '@@ GRADE_ADJUSTMENT @@') { // this is not a real grade - it was used just for mapping purposes $DB->set_field('workshop_grades_old', 'newplugin', 'numerrors_map', array('id' => $old->id)); $DB->set_field('workshop_grades_old', 'newid', 0, array('id' => $old->id)); continue; } $new = workshopform_numerrors_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', 'numerrors', array('id' => $old->id)); $DB->set_field('workshop_grades_old', 'newid', $newid, array('id' => $old->id)); } $rs->close(); } }