From 8b6405ce85fbba825a11465faada99cfc3c185c0 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Thu, 13 Aug 2009 09:35:40 +0000 Subject: [PATCH] MDL-19142 assignment/backup&restore: support backing up and restoring third party subtypes if they need it. --- mod/assignment/backuplib.php | 15 +++++++-- mod/assignment/lib.php | 63 +++++++++++++++++++++++++++++++++++ mod/assignment/restorelib.php | 14 ++++++-- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/mod/assignment/backuplib.php b/mod/assignment/backuplib.php index 747df2bb94a..1a6d0cd7a58 100644 --- a/mod/assignment/backuplib.php +++ b/mod/assignment/backuplib.php @@ -73,10 +73,16 @@ fwrite ($bf,full_tag("TIMEAVAILABLE",4,false,$assignment->timeavailable)); fwrite ($bf,full_tag("GRADE",4,false,$assignment->grade)); fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$assignment->timemodified)); + + $class = 'assignment_' . $assignment->assignmenttype; + require_once($CFG->dirroot . '/mod/assignment/lib.php'); + require_once($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'); + call_user_func(array($class, 'backup_one_mod'), $bf, $preferences, $assignment); + //if we've selected to backup users info, then execute backup_assignment_submisions and //backup_assignment_files_instance if (backup_userdata_selected($preferences,'assignment',$assignment->id)) { - $status = backup_assignment_submissions($bf,$preferences,$assignment->id); + $status = backup_assignment_submissions($bf,$preferences,$assignment); if ($status) { $status = backup_assignment_files_instance($bf,$preferences,$assignment->id); } @@ -94,7 +100,7 @@ $status = true; - $assignment_submissions = get_records("assignment_submissions","assignment",$assignment,"id"); + $assignment_submissions = get_records("assignment_submissions","assignment",$assignment->id,"id"); //If there is submissions if ($assignment_submissions) { //Write start tag @@ -117,6 +123,11 @@ fwrite ($bf,full_tag("TEACHER",6,false,$ass_sub->teacher)); fwrite ($bf,full_tag("TIMEMARKED",6,false,$ass_sub->timemarked)); fwrite ($bf,full_tag("MAILED",6,false,$ass_sub->mailed)); + + $class = 'assignment_' . $assignment->assignmenttype; + require_once($CFG->dirroot . '/mod/assignment/lib.php'); + require_once($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'); + call_user_func(array($class, 'backup_one_submission'), $bf, $preferences, $assignment, $ass_sub); //End submission $status =fwrite ($bf,end_tag("SUBMISSION",5,true)); } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 7b011f78b17..1ffcce18cf6 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1924,6 +1924,69 @@ class assignment_base { return $status; } + + /** + * base implementation for backing up subtype specific information + * for one single module + * + * @param filehandle $bf file handle for xml file to write to + * @param mixed $preferences the complete backup preference object + * + * @return boolean + * + * @static + */ + function backup_one_mod($bf, $preferences, $assignment) { + return true; + } + + /** + * base implementation for backing up subtype specific information + * for one single submission + * + * @param filehandle $bf file handle for xml file to write to + * @param mixed $preferences the complete backup preference object + * @param object $submission the assignment submission db record + * + * @return boolean + * + * @static + */ + function backup_one_submission($bf, $preferences, $assignment, $submission) { + return true; + } + + /** + * base implementation for restoring subtype specific information + * for one single module + * + * @param array $info the array representing the xml + * @param object $restore the restore preferences + * + * @return boolean + * + * @static + */ + function restore_one_mod($info, $restore, $assignment) { + return true; + } + + /** + * base implementation for restoring subtype specific information + * for one single submission + * + * @param object $submission the newly created submission + * @param array $info the array representing the xml + * @param object $restore the restore preferences + * + * @return boolean + * + * @static + */ + function restore_one_submission($info, $restore, $assignment, $submission) { + return true; + } + } ////// End of the assignment_base class diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php index 19ef45cfe4f..c6ca5fa238d 100644 --- a/mod/assignment/restorelib.php +++ b/mod/assignment/restorelib.php @@ -105,11 +105,16 @@ //We have the newid, update backup_ids backup_putid($restore->backup_unique_code,$mod->modtype, $mod->id, $newid); + // load up the subtype and see if it wants anything further restored. + $class = 'assignment_' . $assignment->assignmenttype; + require_once($CFG->dirroot . '/mod/assignment/lib.php'); + require_once($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'); + call_user_func(array($class, 'restore_one_mod'), $info, $restore, $assignment); //Now check if want to restore user data and do it. if (restore_userdata_selected($restore,'assignment',$mod->id)) { //Restore assignmet_submissions - $status = assignment_submissions_restore_mods($mod->id, $newid,$info,$restore) && $status; + $status = assignment_submissions_restore_mods($mod->id, $newid,$info,$restore, $assignment) && $status; } } else { $status = false; @@ -122,7 +127,7 @@ } //This function restores the assignment_submissions - function assignment_submissions_restore_mods($old_assignment_id, $new_assignment_id,$info,$restore) { + function assignment_submissions_restore_mods($old_assignment_id, $new_assignment_id,$info,$restore, $assignment) { global $CFG; @@ -200,6 +205,11 @@ $status = assignment_restore_files ($old_assignment_id, $new_assignment_id, $olduserid, $submission->userid, $restore); + $submission->id = $newid; + $class = 'assignment_' . $assignment->assignmenttype; + require_once($CFG->dirroot . '/mod/assignment/lib.php'); + require_once($CFG->dirroot . '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'); + call_user_func(array($class, 'restore_one_submission'), $info, $restore, $assignment, $submission); } else { $status = false; }