MDL-32690: Restore 1.9 backup into 2.X fails on missing assignment type
Solution is as follows: * Allow unsupported subplugins to convert from Moodle1 to Moodle2 * On Moodle2 restore hide unsupported subplugins * Graceful error message in assignment of unsupported subplugins
This commit is contained in:
@@ -194,7 +194,8 @@ class moodle1_mod_assignment_handler extends moodle1_mod_handler {
|
||||
}
|
||||
|
||||
if (!isset($this->subpluginhandlers[$subplugin])) {
|
||||
throw new moodle1_convert_exception('unsupported_subplugin', 'assignment_'.$subplugin);
|
||||
// Generic handling, prevents breaking conversion process...
|
||||
$this->subpluginhandlers[$subplugin] = new moodle1_assignment_unsupported_subplugin_handler($this, $subplugin);
|
||||
}
|
||||
|
||||
return $this->subpluginhandlers[$subplugin];
|
||||
@@ -236,4 +237,10 @@ abstract class moodle1_assignment_subplugin_handler extends moodle1_submod_handl
|
||||
|
||||
//you will probably want to do stuff with $this->xmlwriter here (within your overridden method) to write plugin specific data.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class handles subplugins that do not exist or that are not supported
|
||||
*/
|
||||
class moodle1_assignment_unsupported_subplugin_handler extends moodle1_assignment_subplugin_handler {
|
||||
}
|
||||
@@ -72,6 +72,11 @@ class restore_assignment_activity_structure_step extends restore_activity_struct
|
||||
$newitemid = $DB->insert_record('assignment', $data);
|
||||
// immediately after inserting "activity" record, call this
|
||||
$this->apply_activity_instance($newitemid);
|
||||
|
||||
// Hide unsupported sub-plugins
|
||||
if (!$this->is_valid_assignment_subplugin($data->assignmenttype)) {
|
||||
$DB->set_field('course_modules', 'visible', 0, array('id' => $this->get_task()->get_moduleid()));
|
||||
}
|
||||
}
|
||||
|
||||
protected function process_assignment_submission($data) {
|
||||
@@ -100,4 +105,19 @@ class restore_assignment_activity_structure_step extends restore_activity_struct
|
||||
$this->add_related_files('mod_assignment', 'submission', 'assignment_submission');
|
||||
$this->add_related_files('mod_assignment', 'response', 'assignment_submission');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a sub-plugin is supported or not
|
||||
*
|
||||
* @param string $type
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_valid_assignment_subplugin($type) {
|
||||
static $subplugins = null;
|
||||
|
||||
if (is_null($subplugins)) {
|
||||
$subplugins = get_plugin_list('assignment');
|
||||
}
|
||||
return array_key_exists($type, $subplugins);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,3 +223,4 @@ $string['viewfeedback'] = 'View assignment grades and feedback';
|
||||
$string['viewmysubmission'] = 'View my submission';
|
||||
$string['viewsubmissions'] = 'View {$a} submitted assignments';
|
||||
$string['yoursubmission'] = 'Your submission';
|
||||
$string['unsupportedsubplugin'] = 'The assignment type of \'{$a}\' is not currently supported. You may wait until the assignment type is made available, or delete the assignment.';
|
||||
|
||||
@@ -3948,7 +3948,12 @@ function assignment_extend_settings_navigation(settings_navigation $settings, na
|
||||
global $PAGE, $DB, $USER, $CFG;
|
||||
|
||||
$assignmentrow = $DB->get_record("assignment", array("id" => $PAGE->cm->instance));
|
||||
require_once "$CFG->dirroot/mod/assignment/type/$assignmentrow->assignmenttype/assignment.class.php";
|
||||
|
||||
$classfile = "$CFG->dirroot/mod/assignment/type/$assignmentrow->assignmenttype/assignment.class.php";
|
||||
if (!file_exists($classfile)) {
|
||||
return;
|
||||
}
|
||||
require_once($classfile);
|
||||
|
||||
$assignmentclass = 'assignment_'.$assignmentrow->assignmenttype;
|
||||
$assignmentinstance = new $assignmentclass($PAGE->cm->id, $assignmentrow, $PAGE->cm, $PAGE->course);
|
||||
|
||||
@@ -9,7 +9,7 @@ class mod_assignment_mod_form extends moodleform_mod {
|
||||
protected $_assignmentinstance = null;
|
||||
|
||||
function definition() {
|
||||
global $CFG, $DB, $PAGE;
|
||||
global $CFG, $DB, $PAGE, $COURSE;
|
||||
$mform =& $this->_form;
|
||||
|
||||
// this hack is needed for different settings of each subtype
|
||||
@@ -29,7 +29,11 @@ class mod_assignment_mod_form extends moodleform_mod {
|
||||
$mform->setType('type', PARAM_ALPHA);
|
||||
$mform->setDefault('type', $type);
|
||||
|
||||
require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
|
||||
$classfile = $CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php';
|
||||
if (!file_exists($classfile)) {
|
||||
throw new moodle_exception('unsupportedsubplugin', 'assignment', new moodle_url('/course/view.php', array('id' => $COURSE->id)), $type);
|
||||
}
|
||||
require_once($classfile);
|
||||
$assignmentclass = 'assignment_'.$type;
|
||||
$assignmentinstance = new $assignmentclass();
|
||||
|
||||
|
||||
@@ -40,7 +40,11 @@ require_login($course, true, $cm);
|
||||
|
||||
$PAGE->requires->js('/mod/assignment/assignment.js');
|
||||
|
||||
require ("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
||||
$classfile = "$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php";
|
||||
if (!file_exists($classfile)) {
|
||||
throw new moodle_exception('unsupportedsubplugin', 'assignment', new moodle_url('/course/view.php', array('id' => $course->id)), $assignment->assignmenttype);
|
||||
}
|
||||
require ($classfile);
|
||||
$assignmentclass = "assignment_$assignment->assignmenttype";
|
||||
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user