From f2e34ee52b2e52eea9ec5613bd650054d0c25e26 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Wed, 7 Jul 2010 17:26:34 +0000 Subject: [PATCH] MDL-22245 backup - keep subplugin branches connected all the time. Thanks for spotting it David! --- backup/moodle2/backup_stepslib.php | 11 ++++------- backup/moodle2/backup_subplugin.class.php | 12 +++++++----- .../backup_assignment_offline_subplugin.class.php | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 588a5a4e857..0581ad05c1b 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -106,6 +106,7 @@ abstract class backup_activity_structure_step extends backup_structure_step { // Arrived here, subplugin is correct, let's create the optigroup $optigroupname = $subplugintype . '_' . $element->get_name() . '_subplugin'; $optigroup = new backup_optigroup($optigroupname, null, $multiple); + $element->add_child($optigroup); // Add optigroup to stay connected since beginning // Get all the optigroup_elements, looking across al the subplugin dirs $elements = array(); @@ -115,15 +116,11 @@ 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); - // Add subplugin returned structure to optigroup (must be optigroup_element instance) - if ($subpluginstructure = $backupsubplugin->define_subplugin_structure($element->get_name())) { - $optigroup->add_child($subpluginstructure); - } + $backupsubplugin = new $classname($subplugintype, $name, $optigroup); + // Add subplugin returned structure to optigroup + $backupsubplugin->define_subplugin_structure($element->get_name()); } } - // Finished, add optigroup to element - $element->add_child($optigroup); } /** diff --git a/backup/moodle2/backup_subplugin.class.php b/backup/moodle2/backup_subplugin.class.php index 3dd3debc304..da1b4e7f400 100644 --- a/backup/moodle2/backup_subplugin.class.php +++ b/backup/moodle2/backup_subplugin.class.php @@ -32,10 +32,12 @@ abstract class backup_subplugin { protected $subplugintype; protected $subpluginname; protected $connectionpoint; + protected $optigroup; // Optigroup, parent of all optigroup elements - public function __construct($subplugintype, $subpluginname) { + public function __construct($subplugintype, $subpluginname, $optigroup) { $this->subplugintype = $subplugintype; $this->subpluginname = $subpluginname; + $this->optigroup = $optigroup; $this->connectionpoint = ''; } @@ -46,10 +48,8 @@ abstract class backup_subplugin { $methodname = 'define_' . $connectionpoint . '_subplugin_structure'; if (method_exists($this, $methodname)) { - return $this->$methodname(); + $this->$methodname(); } - - return false; } /** @@ -60,7 +60,9 @@ abstract class backup_subplugin { // Something exclusive for this backup_subplugin_element (backup_optigroup_element) // because it hasn't XML representation $name = 'optigroup_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint; - return new backup_subplugin_element($name, $final_elements, $conditionparam, $conditionvalue); + $optigroup_element = new backup_subplugin_element($name, $final_elements, $conditionparam, $conditionvalue); + $this->optigroup->add_child($optigroup_element); // Add optigroup_element to stay connected since beginning + return $optigroup_element; } /** diff --git a/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php b/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php index b247c7d8be0..8deb7749101 100644 --- a/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php +++ b/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php @@ -81,7 +81,7 @@ class backup_assignment_offline_subplugin extends backup_subplugin { $subplugin->add_child($assassoff); $assassoff->add_child($config); - $config->set_source_table('config', array()); + $config->set_source_table('config', array('id' => '/assignment/id')); return $subplugin; // And we return the root subplugin element } @@ -105,7 +105,7 @@ class backup_assignment_offline_subplugin extends backup_subplugin { $subplugin->add_child($asssuboff); $asssuboff->add_child($config); - $config->set_source_table('config', array()); + $config->set_source_table('config', array('id' => backup::VAR_PARENTID)); return $subplugin; // And we return the root subplugin element }