Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Script to migrate settings and files from old 2.2 assignments to thei…
Browse files Browse the repository at this point in the history
…r upgraded 2.3 mod_assign
  • Loading branch information
danmarsden committed Dec 13, 2012
1 parent ec3dcaf commit a83d161
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lang/en/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@
$string['missingkey'] = 'Turnitin Secret Key not set!';
$string['fileopenerror'] = 'error trying to open plagiarism XML file! {$a}';
$string['beingprocessed'] = 'File was uploaded successfully and is currently being processed by turnitin';
$string['errorlookup'] = 'See <a href ="http://docs.moodle.org/dev/Turnitin_errors">here</a> for an explanation of the code';
$string['errorlookup'] = 'See <a href ="http://docs.moodle.org/dev/Turnitin_errors">here</a> for an explanation of the code';
$string['turnitinmigrate'] = 'Migrate 2.2 Assignments';
$string['turnitinmigrate_help'] = 'If you have upgraded assignments to the new 2.3 mod_assign, this will try to re-link turnitin scores/reports generted in the old 2.2 Assignment with the upgraded 2.3 assignment module';
$string['migrated'] = 'Turnitin settings migrated';
69 changes: 69 additions & 0 deletions migrateassignment22.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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/>.

/**
* migrateassignment22.php - migrates Assignment 2.2 settings to upgraded 2.3 assignments.
*
* @package plagiarism_turnitin
* @author Dan Marsden <dan@danmarsden.com>
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(dirname(__FILE__)) . '/../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/plagiarismlib.php');
require_once($CFG->dirroot.'/plagiarism/turnitin/lib.php');
require_once('turnitin_form.php');

require_login();
admin_externalpage_setup('plagiarismturnitin');
$PAGE->set_url('/plagiarism/turnitin/migrateassignment22.php');

echo $OUTPUT->header();
$currenttab='turnitinmigrate';
require_once('turnitin_tabs.php');

echo $OUTPUT->box(get_string('turnitinmigrate_help', 'plagiarism_turnitin'));

if ((data_submitted()) && confirm_sesskey()) {
$sql = "SELECT DISTINCT cmid, info FROM {log} WHERE module='assign' AND action='view'";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $r) {
if (is_numeric($r->info) && $r->cmid <> $r->info) {
$oldcm = (int) $r->info;
//update config with new cm

if (!$DB->record_exists('course_modules', array('id' => $oldcm)) && //check that the $oldcm doesn't exist - if it still exists we shouldn't do anything here.
$DB->record_exists('course_modules', array('id' => $r->cmid)) && //check that the new cm still exists.
$DB->record_exists('plagiarism_turnitin_config', array('cm'=>$oldcm))) { //check that we have records to update.

//update turnitin config with new cm
$DB->set_field('plagiarism_turnitin_config', 'cm', $r->cmid, array('cm' => $oldcm));

//update turnitin files with new cm
$DB->set_field('plagiarism_turnitin_files', 'cm', $r->cmid, array('cm' => $oldcm));

}
}
}
$rs->close();
echo $OUTPUT->notification(get_string('migrated', 'plagiarism_turnitin'), 'notifysuccess');
} else {
echo $OUTPUT->single_button($PAGE->url, get_string('turnitinmigrate', 'plagiarism_turnitin'));
}

echo $OUTPUT->footer();
2 changes: 2 additions & 0 deletions turnitin_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
$strplagiarism = get_string('turnitin', 'plagiarism_turnitin');
$strplagiarismdefaults = get_string('turnitindefaults', 'plagiarism_turnitin');
$strplagiarismerrors = get_string('turnitinerrors', 'plagiarism_turnitin');
$strplagiarismmigrate = get_string('turnitinmigrate', 'plagiarism_turnitin');

$tabs = array();
$tabs[] = new tabobject('turnitinsettings', 'settings.php', $strplagiarism, $strplagiarism, false);
$tabs[] = new tabobject('turnitindefaults', 'turnitin_defaults.php', $strplagiarismdefaults, $strplagiarismdefaults, false);
$tabs[] = new tabobject('turnitinerrors', 'turnitin_errors.php', $strplagiarismerrors, $strplagiarismerrors, false);
$tabs[] = new tabobject('turnitinmigrate', 'migrateassignment22.php', $strplagiarismmigrate, $strplagiarismmigrate, false);
print_tabs(array($tabs), $currenttab);

0 comments on commit a83d161

Please sign in to comment.