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

This commit is contained in:
Eloy Lafuente (stronk7)
2011-02-10 12:14:00 +01:00
parent 1e37c39180
commit 4ab111b9bf
4 changed files with 61 additions and 5 deletions
+22 -2
View File
@@ -33,12 +33,16 @@ abstract class backup_plugin {
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 @@ abstract class backup_plugin {
}
}
// 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)
+9 -1
View File
@@ -125,13 +125,21 @@ abstract class backup_activity_structure_step extends backup_structure_step {
$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());
}
}
}
/**
* 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...
+21 -1
View File
@@ -34,12 +34,16 @@ abstract class backup_subplugin {
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 @@ abstract class backup_subplugin {
}
}
// 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)
@@ -101,6 +101,14 @@ abstract class backup_structure_step extends backup_step {
$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 @@ abstract class backup_structure_step extends backup_step {
$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());
}