Skip to content

Commit

Permalink
MDL-19142 assignment/backup&restore: support backing up and restoring…
Browse files Browse the repository at this point in the history
… third party subtypes if they need it.

Merged from MOODLE_19_STABLE
  • Loading branch information
mjollnir_ committed Aug 13, 2009
1 parent e57c283 commit 3b804d2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
15 changes: 13 additions & 2 deletions mod/assignment/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ function assignment_backup_one_mod($bf,$preferences,$assignment) {
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);
}
Expand All @@ -91,7 +97,7 @@ function backup_assignment_submissions ($bf,$preferences,$assignment) {

$status = true;

$assignment_submissions = $DB->get_records("assignment_submissions", array("assignment"=>$assignment),"id");
$assignment_submissions = $DB->get_records("assignment_submissions", array("assignment"=>$assignment->id),"id");
//If there is submissions
if ($assignment_submissions) {
//Write start tag
Expand All @@ -114,6 +120,11 @@ function backup_assignment_submissions ($bf,$preferences,$assignment) {
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));
}
Expand Down
63 changes: 63 additions & 0 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,69 @@ function reset_userdata($data) {
function portfolio_exportable() {
return false;
}

/**
* 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
*/
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
*/
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
*/
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
*/
static function restore_one_submission($info, $restore, $assignment, $submission) {
return true;
}

} ////// End of the assignment_base class

/**
Expand Down
14 changes: 13 additions & 1 deletion mod/assignment/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ function assignment_restore_mods($mod,$restore) {
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;
Expand All @@ -121,7 +128,7 @@ function assignment_restore_mods($mod,$restore) {
}

//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, $DB;

$status = true;
Expand Down Expand Up @@ -198,6 +205,11 @@ function assignment_submissions_restore_mods($old_assignment_id, $new_assignment
$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;
}
Expand Down

0 comments on commit 3b804d2

Please sign in to comment.