mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-19937 workshop: migration of comments (no grading) strategy
This commit is contained in:
parent
f5be71a379
commit
f9b827d86e
2 changed files with 181 additions and 0 deletions
47
mod/workshop/form/comments/db/install.php
Normal file
47
mod/workshop/form/comments/db/install.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* This file replaces the legacy STATEMENTS section in db/install.xml,
|
||||
* lib.php/modulename_install() post installation hook and partially defaults.php
|
||||
*
|
||||
* @package mod-workshop
|
||||
* @copyright 2010 David Mudrak <david.mudrak@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Post installation procedure
|
||||
*/
|
||||
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();
|
||||
}
|
134
mod/workshop/form/comments/db/upgradelib.php
Normal file
134
mod/workshop/form/comments/db/upgradelib.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?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_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);
|
||||
$newworkshopids = workshop_upgrade_workshop_id_mappings();
|
||||
foreach ($rs as $old) {
|
||||
$new = workshopform_comments_upgrade_element($old, $newworkshopids[$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($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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue