MDL-55236 mod_assign: Allow subplugins to backup files

This commit is contained in:
Henning Bostelmann
2016-09-05 11:39:12 +02:00
parent 5c33a0db21
commit e5e89cacfb
5 changed files with 57 additions and 1 deletions
+10
View File
@@ -383,6 +383,16 @@ abstract class assign_plugin {
return $config;
}
/**
* Get a list of file areas associated with the plugin configuration.
* This is used for backup/restore.
*
* @return array names of the fileareas, can be an empty array
*/
public function get_config_file_areas() {
return array();
}
/**
* Should not output anything - return the result as a string so it can be consumed by webservices.
*
@@ -24,6 +24,8 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* Define the complete choice structure for backup, with file and id annotations
*
@@ -33,6 +35,24 @@ defined('MOODLE_INTERNAL') || die();
*/
class backup_assign_activity_structure_step extends backup_activity_structure_step {
/**
* Annotate files from plugin configuration
* @param backup_nested_element $assign the backup structure of the activity
* @param string $subtype the plugin type to handle
* @return void
*/
protected function annotate_plugin_config_files(backup_nested_element $assign, $subtype) {
$dummyassign = new assign(null, null, null);
$plugins = $dummyassign->load_plugins($subtype);
foreach ($plugins as $plugin) {
$component = $plugin->get_subtype() . '_' . $plugin->get_type();
$areas = $plugin->get_config_file_areas();
foreach ($areas as $area) {
$assign->annotate_files($component, $area, null);
}
}
}
/**
* Define the structure for the assign activity
* @return void
@@ -153,6 +173,8 @@ class backup_assign_activity_structure_step extends backup_activity_structure_st
// These file areas don't have an itemid.
$assign->annotate_files('mod_assign', 'intro', null);
$assign->annotate_files('mod_assign', 'introattachment', null);
$this->annotate_plugin_config_files($assign, 'assignsubmission');
$this->annotate_plugin_config_files($assign, 'assignfeedback');
// Return the root element (choice), wrapped into standard activity structure.
@@ -24,6 +24,8 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* Define the complete assignment structure for restore, with file and id annotations
*
@@ -334,6 +336,23 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
$DB->insert_records('assign_submission', $submissions);
}
/**
* Restore files from plugin configuration
* @param string $subtype the plugin type to handle
* @return void
*/
protected function add_plugin_config_files($subtype) {
$dummyassign = new assign(null, null, null);
$plugins = $dummyassign->load_plugins($subtype);
foreach ($plugins as $plugin) {
$component = $plugin->get_subtype() . '_' . $plugin->get_type();
$areas = $plugin->get_config_file_areas();
foreach ($areas as $area) {
$this->add_related_files($component, $area, null);
}
}
}
/**
* Once the database tables have been fully restored, restore the files
* @return void
@@ -342,6 +361,9 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
$this->add_related_files('mod_assign', 'intro', null);
$this->add_related_files('mod_assign', 'introattachment', null);
$this->add_plugin_config_files('assignsubmission');
$this->add_plugin_config_files('assignfeedback');
$this->set_latest_submission_field();
}
}
+1 -1
View File
@@ -378,7 +378,7 @@ class assign {
* @param string $subtype - either submission or feedback
* @return array - The sorted list of plugins
*/
protected function load_plugins($subtype) {
public function load_plugins($subtype) {
global $CFG;
$result = array();
+2
View File
@@ -11,6 +11,8 @@ This files describes API changes in the assign code.
filename, filepath, mimetype, filesize, timemodified and fileurl.
Those fields are now marked as VALUE_OPTIONAL for backwards compatibility.
Please, note that previously the filename was part of the filepath field, now they are separated.
* Submission and feedback plugins can now specify file areas related to their configuration data,
which will then be included in backup and restore; see assign_plugin::get_config_file_areas().
=== 3.1 ===
* The feedback plugins now need to implement the is_feedback_modified() method. The default is to return true