Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-22146 backup & restore - extending the backup plugins API

  • Loading branch information...
commit 4ab111b9bf9d18c515252fe743cd0c960d99f7a9 1 parent 1e37c39
@stronk7 stronk7 authored
View
24 backup/moodle2/backup_plugin.class.php
@@ -33,12 +33,16 @@
protected $pluginname;
protected $connectionpoint;
protected $optigroup; // Optigroup, parent of all optigroup elements
+ protected $step;
+ protected $task;
- public function __construct($plugintype, $pluginname, $optigroup) {
+ public function __construct($plugintype, $pluginname, $optigroup, $step) {
$this->plugintype = $plugintype;
$this->pluginname = $pluginname;
- $this->optigroup = $optigroup;
+ $this->optigroup = $optigroup;
$this->connectionpoint = '';
+ $this->step = $step;
+ $this->task = $step->get_task();
}
public function define_plugin_structure($connectionpoint) {
@@ -52,6 +56,22 @@ public function define_plugin_structure($connectionpoint) {
}
}
+// Protected API starts here
+
+// backup_step/structure_step/task wrappers
+
+ /**
+ * Returns the value of one (task/plan) setting
+ */
+ protected function get_setting_value($name) {
+ if (is_null($this->task)) {
+ throw new restore_step_exception('not_specified_restore_task');
+ }
+ return $this->task->get_setting_value($name);
+ }
+
+// end of backup_step/structure_step/task wrappers
+
/**
* Factory method that will return one backup_plugin_element (backup_optigroup_element)
* with its name automatically calculated, based one the plugin being handled (type, name)
View
10 backup/moodle2/backup_stepslib.php
@@ -125,7 +125,7 @@ protected function add_subplugin_structure($subplugintype, $element, $multiple)
$backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php';
if (file_exists($backupfile)) {
require_once($backupfile);
- $backupsubplugin = new $classname($subplugintype, $name, $optigroup);
+ $backupsubplugin = new $classname($subplugintype, $name, $optigroup, $this);
// Add subplugin returned structure to optigroup
$backupsubplugin->define_subplugin_structure($element->get_name());
}
@@ -133,6 +133,14 @@ protected function add_subplugin_structure($subplugintype, $element, $multiple)
}
/**
+ * As far as activity backup steps are implementing backup_subplugin stuff, they need to
+ * have the parent task available for wrapping purposes (get course/context....)
+ */
+ public function get_task() {
+ return $this->task;
+ }
+
+ /**
* Wraps any activity backup structure within the common 'activity' element
* that will include common to all activities information like id, context...
*/
View
22 backup/moodle2/backup_subplugin.class.php
@@ -34,12 +34,16 @@
protected $subpluginname;
protected $connectionpoint;
protected $optigroup; // Optigroup, parent of all optigroup elements
+ protected $step;
+ protected $task;
- public function __construct($subplugintype, $subpluginname, $optigroup) {
+ public function __construct($subplugintype, $subpluginname, $optigroup, $step) {
$this->subplugintype = $subplugintype;
$this->subpluginname = $subpluginname;
$this->optigroup = $optigroup;
$this->connectionpoint = '';
+ $this->step = $step;
+ $this->task = $step->get_task();
}
public function define_subplugin_structure($connectionpoint) {
@@ -53,6 +57,22 @@ public function define_subplugin_structure($connectionpoint) {
}
}
+// Protected API starts here
+
+// backup_step/structure_step/task wrappers
+
+ /**
+ * Returns the value of one (task/plan) setting
+ */
+ protected function get_setting_value($name) {
+ if (is_null($this->task)) {
+ throw new restore_step_exception('not_specified_restore_task');
+ }
+ return $this->task->get_setting_value($name);
+ }
+
+// end of backup_step/structure_step/task wrappers
+
/**
* Factory method that will return one backup_subplugin_element (backup_optigroup_element)
* with its name automatically calculated, based one the subplugin being handled (type, name)
View
10 backup/util/plan/backup_structure_step.class.php
@@ -101,6 +101,14 @@ public function execute() {
$structure->destroy();
}
+ /**
+ * As far as backup structure steps are implementing backup_plugin stuff, they need to
+ * have the parent task available for wrapping purposes (get course/context....)
+ */
+ public function get_task() {
+ return $this->task;
+ }
+
// Protected API starts here
/**
@@ -133,7 +141,7 @@ protected function add_plugin_structure($plugintype, $element, $multiple) {
$backupfile = $plugindir . '/backup/moodle2/' . $classname . '.class.php';
if (file_exists($backupfile)) {
require_once($backupfile);
- $backupplugin = new $classname($plugintype, $name, $optigroup);
+ $backupplugin = new $classname($plugintype, $name, $optigroup, $this);
// Add plugin returned structure to optigroup
$backupplugin->define_plugin_structure($element->get_name());
}
Please sign in to comment.
Something went wrong with that request. Please try again.