mirror of
https://github.com/moodle/moodle.git
synced 2025-03-17 14:10:08 +01:00
MDL-30610 remove outdated workshop upgrade code
This commit is contained in:
parent
7c58c19fa3
commit
17510ff0fe
@ -26,8 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/mod/workshop/db/upgradelib.php');
|
||||
|
||||
/**
|
||||
* Workshop conversion handler
|
||||
*/
|
||||
@ -354,3 +352,60 @@ abstract class moodle1_workshopform_handler extends moodle1_submod_handler {
|
||||
// do nothing by default
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a record containing data from 1.9 workshop table, returns object containing data as should be saved in 2.0 workshop table
|
||||
*
|
||||
* @param stdClass $old record from 1.9 workshop table
|
||||
* @return stdClass
|
||||
*/
|
||||
function workshop_upgrade_transform_instance(stdClass $old) {
|
||||
global $CFG;
|
||||
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php');
|
||||
|
||||
$new = new stdClass();
|
||||
$new->course = $old->course;
|
||||
$new->name = $old->name;
|
||||
$new->intro = $old->description;
|
||||
$new->introformat = $old->format;
|
||||
$new->nattachments = $old->nattachments;
|
||||
$new->maxbytes = $old->maxbytes;
|
||||
$new->grade = $old->grade;
|
||||
$new->gradinggrade = $old->gradinggrade;
|
||||
$new->phase = workshop::PHASE_CLOSED;
|
||||
$new->timemodified = time();
|
||||
if ($old->ntassessments > 0) {
|
||||
$new->useexamples = 1;
|
||||
} else {
|
||||
$new->useexamples = 0;
|
||||
}
|
||||
$new->usepeerassessment = 1;
|
||||
$new->useselfassessment = $old->includeself;
|
||||
switch ($old->gradingstrategy) {
|
||||
case 0: // 'notgraded' - renamed
|
||||
$new->strategy = 'comments';
|
||||
break;
|
||||
case 1: // 'accumulative'
|
||||
$new->strategy = 'accumulative';
|
||||
break;
|
||||
case 2: // 'errorbanded' - renamed
|
||||
$new->strategy = 'numerrors';
|
||||
break;
|
||||
case 3: // 'criterion' - will be migrated into 'rubric'
|
||||
$new->strategy = 'rubric';
|
||||
break;
|
||||
case 4: // 'rubric'
|
||||
$new->strategy = 'rubric';
|
||||
break;
|
||||
}
|
||||
if ($old->submissionstart < $old->submissionend) {
|
||||
$new->submissionstart = $old->submissionstart;
|
||||
$new->submissionend = $old->submissionend;
|
||||
}
|
||||
if ($old->assessmentstart < $old->assessmentend) {
|
||||
$new->assessmentstart = $old->assessmentstart;
|
||||
$new->assessmentend = $old->assessmentend;
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
@ -30,19 +30,5 @@
|
||||
*/
|
||||
function xmldb_workshopform_accumulative_install() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// upgrade from old workshop 1.x if needed
|
||||
workshopform_accumulative_upgrade_legacy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post installation procedure recovery
|
||||
*/
|
||||
function xmldb_workshopform_accumulative_install_recovery() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// continue upgrading from old workshop 1.x if needed
|
||||
workshopform_accumulative_upgrade_legacy();
|
||||
}
|
||||
|
@ -35,22 +35,6 @@ function xmldb_workshopform_accumulative_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2010091700) {
|
||||
// clean up orphaned dimensions
|
||||
$orphans = $DB->get_records_sql("SELECT d.id
|
||||
FROM {workshopform_accumulative} d
|
||||
LEFT JOIN {workshop} w ON d.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned assessment form elements found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_accumulative', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2010091700, 'workshopform', 'accumulative');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
@ -1,316 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Functions used by some stages of accumulative grading upgrade
|
||||
*
|
||||
* @package workshopform
|
||||
* @subpackage accumulative
|
||||
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 (i.e. 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a given record from workshop_elements_old into an object to be saved into workshopform_accumulative
|
||||
*
|
||||
* @param stdClass $old legacy record from workshop_elements_old
|
||||
* @param array $newscaleids mapping from old scale types into new standard ones
|
||||
* @param int $newworkshopid id of the new workshop instance that replaced the previous one
|
||||
* @return stdclass to be saved in workshopform_accumulative
|
||||
*/
|
||||
function workshopform_accumulative_upgrade_element(stdclass $old, array $newscaleids, $newworkshopid) {
|
||||
$new = new stdclass();
|
||||
$new->workshopid = $newworkshopid;
|
||||
$new->sort = $old->elementno;
|
||||
$new->description = $old->description;
|
||||
$new->descriptionformat = FORMAT_HTML;
|
||||
// calculate new grade/scale of the element
|
||||
if ($old->scale >= 0 and $old->scale <= 6 and isset($newscaleids[$old->scale])) {
|
||||
$new->grade = -$newscaleids[$old->scale];
|
||||
} elseif ($old->scale == 7) {
|
||||
$new->grade = 10;
|
||||
} elseif ($old->scale == 8) {
|
||||
$new->grade = 20;
|
||||
} elseif ($old->scale == 9) {
|
||||
$new->grade = 100;
|
||||
} else {
|
||||
$new->grade = 0; // something is wrong
|
||||
}
|
||||
// calculate new weight of the element. Negative weights are not supported any more and
|
||||
// are replaced with weight = 0. Legacy workshop did not store the raw weight but the index
|
||||
// in the array of weights (see $WORKSHOP_EWEIGHTS in workshop 1.x)
|
||||
// workshop 2.0 uses integer weights only (0-16) so all previous weights are multiplied by 4.
|
||||
switch ($old->weight) {
|
||||
case 8: $new->weight = 1; break;
|
||||
case 9: $new->weight = 2; break;
|
||||
case 10: $new->weight = 3; break;
|
||||
case 11: $new->weight = 4; break;
|
||||
case 12: $new->weight = 6; break;
|
||||
case 13: $new->weight = 8; break;
|
||||
case 14: $new->weight = 16; break;
|
||||
default: $new->weight = 0;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms given grade record
|
||||
*
|
||||
* @param stdClass $old
|
||||
* @param int $newassessmentid
|
||||
* @param stdClass $newdimensioninfo
|
||||
* @return stdclass
|
||||
*/
|
||||
function workshopform_accumulative_upgrade_grade(stdclass $old, $newassessmentid, stdclass $newdimensioninfo) {
|
||||
$new = new stdclass();
|
||||
$new->assessmentid = $newassessmentid;
|
||||
$new->strategy = 'accumulative';
|
||||
$new->dimensionid = $newdimensioninfo->newid;
|
||||
if ($newdimensioninfo->type == 'value') {
|
||||
$new->grade = $old->grade;
|
||||
} elseif ($newdimensioninfo->type == 'scale') {
|
||||
// in workshop 1.x, scale items are numbered starting from 0 but Moodle in-built scales start numbering from 1
|
||||
$new->grade = $old->grade + 1;
|
||||
}
|
||||
$new->peercomment = $old->feedback;
|
||||
$new->peercommentformat = FORMAT_HTML;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the the migration from legacy workshop 1.9 is needed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function workshopform_accumulative_upgrade_legacy_needed() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
if (!($dbman->table_exists('workshop_elements_old') and $dbman->table_exists('workshop_grades_old'))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new standard (global) scales to replace the legacy workshop ones
|
||||
*
|
||||
* In workshop 1.x, scale field in workshop_elements had the following meaning:
|
||||
* 0 | 2 point Yes/No scale
|
||||
* 1 | 2 point Present/Absent scale
|
||||
* 2 | 2 point Correct/Incorrect scale
|
||||
* 3 | 3 point Good/Poor scale
|
||||
* 4 | 4 point Excellent/Very Poor scale
|
||||
* 5 | 5 point Excellent/Very Poor scale
|
||||
* 6 | 7 point Excellent/Very Poor scale
|
||||
* 7 | Score out of 10
|
||||
* 8 | Score out of 20
|
||||
* 9 | Score out of 100
|
||||
*
|
||||
* @return array (int)oldscale => (int)newscaleid
|
||||
*/
|
||||
function workshopform_accumulative_upgrade_scales() {
|
||||
global $DB, $CFG, $USER;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
$sql = 'SELECT DISTINCT scale
|
||||
FROM {workshop_elements_old}
|
||||
WHERE newplugin IS NULL';
|
||||
$oldscales = $DB->get_records_sql($sql);
|
||||
$newscales = array();
|
||||
foreach($oldscales as $oldscale => $whatever) {
|
||||
switch ($oldscale) {
|
||||
case 0:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename0', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array(get_string('no'), get_string('yes')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[0] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 1:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename1', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array(get_string('absent', 'workshopform_accumulative'),
|
||||
get_string('present', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[1] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 2:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename2', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array(get_string('incorrect', 'workshopform_accumulative'),
|
||||
get_string('correct', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[2] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 3:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename3', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array('* ' . get_string('poor', 'workshopform_accumulative'),
|
||||
'**',
|
||||
'*** ' . get_string('good', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[3] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 4:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename4', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
|
||||
'**',
|
||||
'***',
|
||||
'**** ' . get_string('excellent', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[4] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 5:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename5', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
|
||||
'**',
|
||||
'***',
|
||||
'****',
|
||||
'***** ' . get_string('excellent', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[5] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
case 6:
|
||||
$data = new stdclass();
|
||||
$data->courseid = 0;
|
||||
$data->userid = $USER->id;
|
||||
$data->name = get_string('scalename6', 'workshopform_accumulative');
|
||||
$data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
|
||||
'**',
|
||||
'***',
|
||||
'****',
|
||||
'*****',
|
||||
'******',
|
||||
'******* ' . get_string('excellent', 'workshopform_accumulative')));
|
||||
$data->description = '';
|
||||
$data->descriptionformat = FORMAT_HTML;
|
||||
|
||||
$scale = new grade_scale();
|
||||
grade_scale::set_properties($scale, $data);
|
||||
$newscales[6] = $scale->insert('mod/workshop');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $newscales;
|
||||
}
|
@ -30,19 +30,5 @@
|
||||
*/
|
||||
function xmldb_workshopform_comments_install() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// upgrade from old workshop 1.x if needed
|
||||
workshopform_comments_upgrade_legacy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post installation procedure recovery
|
||||
*/
|
||||
function xmldb_workshopform_comments_install_recovery() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// continue upgrading from old workshop 1.x if needed
|
||||
workshopform_comments_upgrade_legacy();
|
||||
}
|
||||
|
@ -35,22 +35,6 @@ function xmldb_workshopform_comments_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2010091700) {
|
||||
// clean up orphaned dimensions
|
||||
$orphans = $DB->get_records_sql("SELECT d.id
|
||||
FROM {workshopform_comments} d
|
||||
LEFT JOIN {workshop} w ON d.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned assessment form elements found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_comments', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2010091700, 'workshopform', 'comments');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
@ -1,138 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Functions used by some stages of comments-only grading upgrade
|
||||
*
|
||||
* @package workshopform
|
||||
* @subpackage comments
|
||||
* @copyright 2010 David Mudrak <david.mudrak@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 (i.e. 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a given record from workshop_elements_old into an object to be saved into workshopform_comments
|
||||
*
|
||||
* @param stdClass $old legacy record from workshop_elements_old
|
||||
* @param int $newworkshopid id of the new workshop instance that replaced the previous one
|
||||
* @return stdclass to be saved in workshopform_comments
|
||||
*/
|
||||
function workshopform_comments_upgrade_element(stdclass $old, $newworkshopid) {
|
||||
$new = new stdclass();
|
||||
$new->workshopid = $newworkshopid;
|
||||
$new->sort = $old->elementno;
|
||||
$new->description = $old->description;
|
||||
$new->descriptionformat = FORMAT_HTML;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms given grade record
|
||||
*
|
||||
* @param stdClass $old
|
||||
* @param int $newassessmentid
|
||||
* @param stdClass $newdimensioninfo
|
||||
* @return stdclass
|
||||
*/
|
||||
function workshopform_comments_upgrade_grade(stdclass $old, $newassessmentid, stdclass $newdimensioninfo) {
|
||||
$new = new stdclass();
|
||||
$new->assessmentid = $newassessmentid;
|
||||
$new->strategy = 'comments';
|
||||
$new->dimensionid = $newdimensioninfo->newid;
|
||||
$new->grade = 100.00000;
|
||||
$new->peercomment = $old->feedback;
|
||||
$new->peercommentformat = FORMAT_HTML;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the the migration from legacy workshop 1.9 is needed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function workshopform_comments_upgrade_legacy_needed() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
if (!($dbman->table_exists('workshop_elements_old') and $dbman->table_exists('workshop_grades_old'))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
@ -30,19 +30,5 @@
|
||||
*/
|
||||
function xmldb_workshopform_numerrors_install() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// upgrade from old workshop 1.x if needed
|
||||
workshopform_numerrors_upgrade_legacy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post installation procedure recovery
|
||||
*/
|
||||
function xmldb_workshopform_numerrors_install_recovery() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// continue upgrading from old workshop 1.x if needed
|
||||
workshopform_numerrors_upgrade_legacy();
|
||||
}
|
||||
|
@ -35,32 +35,6 @@ function xmldb_workshopform_numerrors_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2010091700) {
|
||||
// clean up orphaned dimensions
|
||||
$orphans = $DB->get_records_sql("SELECT d.id
|
||||
FROM {workshopform_numerrors} d
|
||||
LEFT JOIN {workshop} w ON d.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned assessment form elements found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_numerrors', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
// clean up orphaned mappings
|
||||
$orphans = $DB->get_records_sql("SELECT m.id
|
||||
FROM {workshopform_numerrors_map} m
|
||||
LEFT JOIN {workshop} w ON m.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned mappings found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_numerrors_map', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2010091700, 'workshopform', 'numerrors');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
@ -1,184 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Functions used by some stages of number of errors grading upgrade
|
||||
*
|
||||
* @package workshopform
|
||||
* @subpackage numerrors
|
||||
* @copyright 2010 David Mudrak <david.mudrak@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php'); // grade_floatval() called here
|
||||
|
||||
/**
|
||||
* 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 (i.e. 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a given record from workshop_elements_old into an object to be saved into workshopform_numerrors
|
||||
*
|
||||
* @param stdClass $old legacy record from workshop_elements_old
|
||||
* @param int $newworkshopid id of the new workshop instance that replaced the previous one
|
||||
* @return stdclass to be saved in workshopform_numerrors
|
||||
*/
|
||||
function workshopform_numerrors_upgrade_element(stdclass $old, $newworkshopid) {
|
||||
$new = new stdclass();
|
||||
$new->workshopid = $newworkshopid;
|
||||
$new->sort = $old->elementno;
|
||||
$new->description = $old->description;
|
||||
$new->descriptionformat = FORMAT_HTML;
|
||||
$new->grade0 = get_string('grade0default', 'workshopform_numerrors');
|
||||
$new->grade1 = get_string('grade1default', 'workshopform_numerrors');
|
||||
// calculate new weight of the element. Negative weights are not supported any more and
|
||||
// are replaced with weight = 0. Legacy workshop did not store the raw weight but the index
|
||||
// in the array of weights (see $WORKSHOP_EWEIGHTS in workshop 1.x)
|
||||
// workshop 2.0 uses integer weights only (0-16) so all previous weights are multiplied by 4.
|
||||
switch ($old->weight) {
|
||||
case 8: $new->weight = 1; break;
|
||||
case 9: $new->weight = 2; break;
|
||||
case 10: $new->weight = 3; break;
|
||||
case 11: $new->weight = 4; break;
|
||||
case 12: $new->weight = 6; break;
|
||||
case 13: $new->weight = 8; break;
|
||||
case 14: $new->weight = 16; break;
|
||||
default: $new->weight = 0;
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms given grade record
|
||||
*
|
||||
* @param stdClass $old
|
||||
* @param int $newassessmentid
|
||||
* @param stdClass $newdimensioninfo
|
||||
* @return stdclass
|
||||
*/
|
||||
function workshopform_numerrors_upgrade_grade(stdclass $old, $newassessmentid, stdclass $newdimensioninfo) {
|
||||
$new = new stdclass();
|
||||
$new->assessmentid = $newassessmentid;
|
||||
$new->strategy = 'numerrors';
|
||||
$new->dimensionid = $newdimensioninfo->newid;
|
||||
$new->grade = $old->grade;
|
||||
$new->peercomment = $old->feedback;
|
||||
$new->peercommentformat = FORMAT_HTML;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the the migration from legacy workshop 1.9 is needed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function workshopform_numerrors_upgrade_legacy_needed() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
if (!($dbman->table_exists('workshop_elements_old') and $dbman->table_exists('workshop_grades_old'))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
@ -30,19 +30,5 @@
|
||||
*/
|
||||
function xmldb_workshopform_rubric_install() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// upgrade from old workshop 1.x if needed
|
||||
workshopform_rubric_upgrade_legacy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post installation procedure recovery
|
||||
*/
|
||||
function xmldb_workshopform_rubric_install_recovery() {
|
||||
global $CFG, $DB;
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
|
||||
// continue upgrading from old workshop 1.x if needed
|
||||
workshopform_rubric_upgrade_legacy();
|
||||
}
|
||||
|
@ -35,33 +35,6 @@ function xmldb_workshopform_rubric_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2010091700) {
|
||||
// clean up orphaned dimensions
|
||||
$orphans = $DB->get_records_sql("SELECT d.id
|
||||
FROM {workshopform_rubric} d
|
||||
LEFT JOIN {workshop} w ON d.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned assessment form elements found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_rubric_levels', 'dimensionid', array_keys($orphans));
|
||||
$DB->delete_records_list('workshopform_rubric', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
// clean up orphaned configurations
|
||||
$orphans = $DB->get_records_sql("SELECT c.id
|
||||
FROM {workshopform_rubric_config} c
|
||||
LEFT JOIN {workshop} w ON c.workshopid = w.id
|
||||
WHERE w.id IS NULL");
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned configuration found - cleaning...');
|
||||
$DB->delete_records_list('workshopform_rubric_config', 'id', array_keys($orphans));
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2010091700, 'workshopform', 'rubric');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
@ -1,305 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Functions used by some stages of rubric grading upgrade
|
||||
*
|
||||
* @package workshopform
|
||||
* @subpackage rubric
|
||||
* @copyright 2010 David Mudrak <david.mudrak@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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_rubric_upgrade_legacy() {
|
||||
|
||||
if (!workshopform_rubric_upgrade_legacy_needed()) {
|
||||
return;
|
||||
}
|
||||
workshopform_rubric_upgrade_legacy_criterion();
|
||||
workshopform_rubric_upgrade_legacy_rubric();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades legacy workshops using criterion grading strategy
|
||||
*/
|
||||
function workshopform_rubric_upgrade_legacy_criterion() {
|
||||
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' => 3), 'course,id', 'id')) {
|
||||
echo $OUTPUT->notification('Copying criterion assessment form 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);
|
||||
$newdimensionids = array(); // (int)workshopid => (int)dimensionid
|
||||
foreach ($rs as $old) {
|
||||
// create rubric criterion and the configuration if necessary
|
||||
if (!isset($newdimensionids[$old->workshopid])) {
|
||||
if (!$DB->record_exists('workshopform_rubric', array('workshopid' => $old->workshopid, 'sort' => 1))) {
|
||||
$newdimension = new stdclass();
|
||||
$newdimension->workshopid = $old->workshopid;
|
||||
$newdimension->sort = 1;
|
||||
$newdimension->description = trim(get_string('dimensionnumber', 'workshopform_rubric', ''));
|
||||
$newdimension->descriptionformat = FORMAT_HTML;
|
||||
$newdimensionids[$old->workshopid] = $DB->insert_record('workshopform_rubric', $newdimension);
|
||||
} else {
|
||||
$newdimensionids[$old->workshopid] = $DB->get_field('workshopform_rubric', 'id',
|
||||
array('workshopid' => $old->workshopid, 'sort' => 1));
|
||||
}
|
||||
if (!$DB->record_exists('workshopform_rubric_config', array('workshopid' => $old->workshopid))) {
|
||||
$newconfig = new stdclass();
|
||||
$newconfig->workshopid = $old->workshopid;
|
||||
$newconfig->layout = 'list';
|
||||
$DB->insert_record('workshopform_rubric_config', $newconfig);
|
||||
}
|
||||
}
|
||||
// process the information about the criterion levels
|
||||
if (trim($old->description)) {
|
||||
$new = workshopform_rubric_upgrade_criterion_level($old, $newdimensionids[$old->workshopid]);
|
||||
$newid = $DB->insert_record('workshopform_rubric_levels', $new);
|
||||
$DB->set_field('workshop_elements_old', 'newplugin', 'rubric_levels', array('id' => $old->id));
|
||||
$DB->set_field('workshop_elements_old', 'newid', $newid, array('id' => $old->id));
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// reload the mappings - this must be reloaded to that we can run this during recovery
|
||||
$newelementids = workshop_upgrade_element_id_mappings('rubric_levels');
|
||||
|
||||
// migrate all grades for these elements (i.e. the values that reviewers put into forms)
|
||||
echo $OUTPUT->notification('Copying criterion assessment form grades', 'notifysuccess');
|
||||
$sql = "SELECT *
|
||||
FROM {workshop_grades_old}
|
||||
WHERE workshopid $workshopids
|
||||
AND elementno = 0
|
||||
AND newid IS NULL";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
$newassessmentids = workshop_upgrade_assessment_id_mappings();
|
||||
$newdimensionids = $DB->get_records('workshopform_rubric_levels', array(), '', 'id,dimensionid');
|
||||
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;
|
||||
}
|
||||
$newlevelid = $newelementids[$old->workshopid][$old->elementno]->newid;
|
||||
$new = new stdclass();
|
||||
$new->assessmentid = $newassessmentids[$old->assessmentid];
|
||||
$new->strategy = 'rubric';
|
||||
$new->dimensionid = $newdimensionids[$newlevelid]->dimensionid;
|
||||
$new->grade = $newelementids[$old->workshopid][$old->grade]->maxscore;
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (i.e. 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms given record from workshop_elements_old into an object to be saved into workshopform_rubric_levels
|
||||
*
|
||||
* This is used during Criterion 1.9 -> Rubric 2.0 conversion
|
||||
*
|
||||
* @param stdClass $old legacy record from workshop_elements_old
|
||||
* @param int $newdimensionid id of the new workshopform_rubric dimension record to be linked to
|
||||
* @return stdclass to be saved in workshopform_rubric_levels
|
||||
*/
|
||||
function workshopform_rubric_upgrade_criterion_level(stdclass $old, $newdimensionid) {
|
||||
$new = new stdclass();
|
||||
$new->dimensionid = $newdimensionid;
|
||||
$new->grade = $old->maxscore;
|
||||
$new->definition = $old->description;
|
||||
$new->definitionformat = FORMAT_HTML;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms given record into an object to be saved into workshopform_rubric_levels
|
||||
*
|
||||
* This is used during Rubric 1.9 -> Rubric 2.0 conversion
|
||||
*
|
||||
* @param stdClass $old legacy record from joined workshop_elements_old + workshop_rubrics_old
|
||||
* @param int $newdimensionid id of the new workshopform_rubric dimension record to be linked to
|
||||
* @return stdclass to be saved in workshopform_rubric_levels
|
||||
*/
|
||||
function workshopform_rubric_upgrade_rubric_level(stdclass $old, $newdimensionid) {
|
||||
$new = new stdclass();
|
||||
$new->dimensionid = $newdimensionid;
|
||||
$new->grade = $old->rgrade * workshopform_rubric_upgrade_weight($old->eweight);
|
||||
$new->definition = $old->rdesc;
|
||||
$new->definitionformat = FORMAT_HTML;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the the migration from legacy workshop 1.9 is needed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function workshopform_rubric_upgrade_legacy_needed() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
if (!($dbman->table_exists('workshop_elements_old') and $dbman->table_exists('workshop_grades_old'))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given old workshop element weight, returns the weight multiplier
|
||||
*
|
||||
* Negative weights are not supported any more and are replaced with weight = 0.
|
||||
* Legacy workshop did not store the raw weight but the index in the array
|
||||
* of weights (see $WORKSHOP_EWEIGHTS in workshop 1.x). workshop 2.0 uses
|
||||
* integer weights only (0-16) so all previous weights are multiplied by 4.
|
||||
*
|
||||
* @param $oldweight index in legacy $WORKSHOP_EWEIGHTS
|
||||
* @return int new weight
|
||||
*/
|
||||
function workshopform_rubric_upgrade_weight($oldweight) {
|
||||
|
||||
switch ($oldweight) {
|
||||
case 8: $weight = 1; break;
|
||||
case 9: $weight = 2; break;
|
||||
case 10: $weight = 3; break;
|
||||
case 11: $weight = 4; break;
|
||||
case 12: $weight = 6; break;
|
||||
case 13: $weight = 8; break;
|
||||
case 14: $weight = 16; break;
|
||||
default: $weight = 0;
|
||||
}
|
||||
return $weight;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user