diff --git a/mod/assignment/backup/moodle1/lib.php b/mod/assignment/backup/moodle1/lib.php index 68c955292f4..9ddc169797d 100644 --- a/mod/assignment/backup/moodle1/lib.php +++ b/mod/assignment/backup/moodle1/lib.php @@ -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 { } \ No newline at end of file diff --git a/mod/assignment/backup/moodle2/restore_assignment_stepslib.php b/mod/assignment/backup/moodle2/restore_assignment_stepslib.php index 0d95d76d6e2..b7f8f56243e 100644 --- a/mod/assignment/backup/moodle2/restore_assignment_stepslib.php +++ b/mod/assignment/backup/moodle2/restore_assignment_stepslib.php @@ -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); + } } diff --git a/mod/assignment/lang/en/assignment.php b/mod/assignment/lang/en/assignment.php index eee525b65e0..29c37facb99 100644 --- a/mod/assignment/lang/en/assignment.php +++ b/mod/assignment/lang/en/assignment.php @@ -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.'; diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 7ed45af42e3..d3c27c704a1 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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); diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index bc0818fea2e..0a7e8361dbe 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -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(); diff --git a/mod/assignment/view.php b/mod/assignment/view.php index 2d80577189c..255a7c70c48 100644 --- a/mod/assignment/view.php +++ b/mod/assignment/view.php @@ -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);