From dae9e82d886ea5bf5563ddf74c1693f62567cd73 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 6 Sep 2007 05:04:55 +0000 Subject: [PATCH] MDL-11128, creating grade items after restoring from a pre 1.9 backup --- backup/restorelib.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/backup/restorelib.php b/backup/restorelib.php index 533b33e051..ae6e34054d 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -7227,7 +7227,7 @@ echo ''; } } - + //Bring back the course blocks -- do it AFTER the modules!!! if($status) { //If we are deleting and bringing into a course or making a new course, same situation @@ -7361,6 +7361,42 @@ echo ''; } } + + // for moodle versions before 1.9, those grades need to be converted to use the new gradebook + // this code needs to execute *after* the course_modules are sorted out + if ($status && $restore->backup_version < 2007090500) { + if (!defined('RESTORE_SILENTLY')) { + echo "
  • ".get_string("migratinggrades"); + } + + // we need need to worry about mods that are restored + // the others in the course are not relevent + if (!empty($restore->mods)) { + require_once($CFG->dirroot.'/lib/gradelib.php'); + foreach ($restore->mods as $mod=>$modtype) { + if (!empty($modtype->instances)) { + foreach ($modtype->instances as $modinstance) { + $sql = "SELECT a.*, cm.idnumber as cmidnumber, m.name as modname + FROM {$CFG->prefix}$mod a, + {$CFG->prefix}course_modules cm, + {$CFG->prefix}modules m + WHERE m.name='$mod' + AND m.id=cm.module + AND cm.instance=a.id + AND cm.id= {$modinstance->restored_as_course_module}"; + + if ($module = get_record_sql($sql)) { + grade_update_mod_grades($module); + } + } + } + } + } + + if (!defined('RESTORE_SILENTLY')) { + echo '
  • '; + } + } /******************************************************************************* ************* Restore of Roles and Capabilities happens here ****************** -- 2.39.5