MDL-22245 backup - added activities subplugin support

This commit is contained in:
Eloy Lafuente
2010-07-02 11:13:00 +00:00
parent 400475947a
commit 060df4c8f7
5 changed files with 117 additions and 2 deletions
+6
View File
@@ -101,3 +101,9 @@ class file_nested_element extends backup_nested_element {
backup_file_manager::copy_file_moodle2backup($this->backupid, $values);
}
}
/**
* Implementation of backup_optigroup_element to be used by subplugins stuff.
* Split just for better separation and future especialitation
*/
class backup_subplugin_element extends backup_optigroup_element { }
@@ -30,6 +30,7 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_final_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_default_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_settingslib.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
+39 -1
View File
@@ -75,10 +75,48 @@ class create_taskbasepath_directory extends backup_execution_step {
/**
* Abtract tructure step, parent of all the activity structure steps. Used to wrap the
* activity structure definition within the main <activity ...> tag
* activity structure definition within the main <activity ...> tag. Also provides
* subplugin support for activities (that must be properly declared)
*/
abstract class backup_activity_structure_step extends backup_structure_step {
protected function add_subplugin_structure($subpluginname, $element, $multiple) {
global $CFG;
// Check the requested subpluginname is a valid one
$subpluginsfile = $CFG->dirroot . '/mod/' . $this->task->get_modulename() . '/db/subplugins.php';
if (!file_exists($subpluginsfile)) {
throw new backup_step_exception('activity_missing_subplugins_php_file', $this->task->get_modulename());
}
include($subpluginsfile);
if (!array_key_exists($subpluginname, $subplugins)) {
throw new backup_step_exception('incorrect_subplugin_type', $subpluginname);
}
// Arrived here, subplugin is correct, let's create the optigroup
$optigroupname = $subpluginname . '_' . $element->get_name() . '_subplugin';
$optigroup = new backup_optigroup($optigroupname, null, $multiple);
// Get all the optigroup_elements, looking across al the subplugin dirs
$elements = array();
$subpluginsdirs = get_plugin_list($subpluginname);
foreach ($subpluginsdirs as $name => $subpluginsdir) {
$classname = 'backup_' . $subpluginname . '_' . $name . '_subplugin';
$backupfile = $subpluginsdir . '/backup/moodle2/' . $classname . '.class.php';
if (file_exists($backupfile)) {
require_once($backupfile);
$backupsubplugin = new $classname($subpluginname, $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);
}
}
}
// Finished, add optigroup to element
$element->add_child($optigroup);
}
protected function prepare_activity_structure($activitystructure) {
// Create the wrap element
+70
View File
@@ -0,0 +1,70 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class implementing the subplugins support for moodle2 backups
*
* TODO: Finish phpdocs
*/
abstract class backup_subplugin {
protected $subplugintype;
protected $subpluginname;
public function __construct($subplugintype, $subpluginname) {
$this->subplugintype = $subplugintype;
$this->subpluginname = $subpluginname;
}
public function define_subplugin_structure($connectionpoint) {
$methodname = 'define_' . $connectionpoint . '_subplugin_structure';
if (method_exists($this, $methodname)) {
return $this->$methodname($connectionpoint);
}
return false;
}
/**
* 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)
*/
protected function get_subplugin_element($connectionpoint, $final_elements = null, $conditionparam = null, $conditionvalue = null) {
// Something exclusive for this backup_subplugin_element (backup_optigroup_element)
// because it hasn't XML representation
$name = 'optigroup_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $connectionpoint;
return new backup_subplugin_element($name, $final_elements, $conditionparam, $conditionvalue);
}
/**
* Simple helper function that suggests one name for the main nested element in subplugins
* It's not mandatory to use it but recommended ;-)
*/
protected function get_recommended_name($connectionpoint) {
return 'subplugin_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $connectionpoint;
}
}
@@ -131,7 +131,7 @@ abstract class base_optigroup extends base_nested_element {
* Recalculate all the used elements in the optigroup, observing
* restrictions and passing the new used to outer level
*/
function add_used($element) {
protected function add_used($element) {
$newused = array();
// Iterate over all the element useds, filling $newused and
// observing the multiple setting