From 2801883fd5ac821cae6bb90bbbf5fbb879d005aa Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Sun, 11 Jul 2010 18:22:38 +0000 Subject: [PATCH] MDL-21432 restore - spreading restore plan with block tasks --- .../moodle2/restore_activity_task.class.php | 6 +- backup/moodle2/restore_block_task.class.php | 101 ++++++++++++++++++ .../restore_default_block_task.class.php | 48 +++++++++ backup/moodle2/restore_plan_builder.class.php | 39 ++++--- 4 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 backup/moodle2/restore_block_task.class.php create mode 100644 backup/moodle2/restore_default_block_task.class.php diff --git a/backup/moodle2/restore_activity_task.class.php b/backup/moodle2/restore_activity_task.class.php index 7c9c0a82d6f..4349d7e3e50 100644 --- a/backup/moodle2/restore_activity_task.class.php +++ b/backup/moodle2/restore_activity_task.class.php @@ -45,7 +45,7 @@ abstract class restore_activity_task extends restore_task { * Activity tasks have their own directory to read files */ public function get_taskbasepath() { - return $this->get_basepath() . '/activities/' . $info->modulename . '_' . $info->moduleid; + return $this->get_basepath() . '/activities/' . $this->info->modulename . '_' . $this->info->moduleid; } /** @@ -59,7 +59,7 @@ abstract class restore_activity_task extends restore_task { return; } - // TODO: Link all the section steps here + // TODO: Link all the activity steps here // At the end, mark it as built $this->built = true; @@ -176,7 +176,7 @@ abstract class restore_activity_task extends restore_task { abstract protected function define_my_steps(); /** - * Code the transformations to perform in the course in + * Code the transformations to perform by the activity in * order to get encoded transformed back to working links */ abstract static public function decode_content_links($content); diff --git a/backup/moodle2/restore_block_task.class.php b/backup/moodle2/restore_block_task.class.php new file mode 100644 index 00000000000..20c027047d6 --- /dev/null +++ b/backup/moodle2/restore_block_task.class.php @@ -0,0 +1,101 @@ +. + +/** + * @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 + */ + +/** + * abstract block task that provides all the properties and common steps to be performed + * when one block is being restored + * + * TODO: Finish phpdocs + */ +abstract class restore_block_task extends restore_task { + + protected $taskbasepath; // To store the basepath of this block + + /** + * Constructor - instantiates one object of this class + */ + public function __construct($name, $taskbasepath, $plan = null) { + $this->$taskbasepath = $taskbasepath; + parent::__construct($name, $plan); + } + + /** + * Block tasks have their own directory to write files + */ + public function get_taskbasepath() { + return $this->$taskbasepath; + } + + /** + * Create all the steps that will be part of this task + */ + public function build() { + + // If we have decided not to backup blocks, prevent anything to be built + if (!$this->get_setting_value('blocks')) { + $this->built = true; + return; + } + + // TODO: Link all the activity steps here + + // At the end, mark it as built + $this->built = true; + } + +// Protected API starts here + + /** + * Define the common setting that any backup block will have + */ + protected function define_settings() { + + // Nothing to add, blocks doesn't have common settings (for now) + + // End of common activity settings, let's add the particular ones + $this->define_my_settings(); + } + + /** + * Define (add) particular settings that each block can have + */ + abstract protected function define_my_settings(); + + /** + * Define (add) particular steps that each block can have + */ + abstract protected function define_my_steps(); + + /** + * Define one array() of configdata attributes + * that need to be decoded + */ + abstract public function get_configdata_encoded_attributes(); + + /** + * Code the transformations to perform by the block in + * order to get encoded transformed back to working links + */ + abstract static public function decode_content_links($content); +} diff --git a/backup/moodle2/restore_default_block_task.class.php b/backup/moodle2/restore_default_block_task.class.php new file mode 100644 index 00000000000..0c1d8d2bfcc --- /dev/null +++ b/backup/moodle2/restore_default_block_task.class.php @@ -0,0 +1,48 @@ +. + +/** + * @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 + */ + +/** + * Default block task to restore blocks not having own DB structures to be added + * + * TODO: Finish phpdocs + */ +class restore_default_block_task extends restore_block_task { + // Nothing to do, it's just the restore_block_task in action + // with required methods doing nothing special + + protected function define_my_settings() { + } + + protected function define_my_steps() { + } + + public function get_configdata_encoded_attributes() { + return array(); + } + + static public function decode_content_links($content) { + return $content; + } +} + diff --git a/backup/moodle2/restore_plan_builder.class.php b/backup/moodle2/restore_plan_builder.class.php index be074ad6de5..aa42f2ca828 100644 --- a/backup/moodle2/restore_plan_builder.class.php +++ b/backup/moodle2/restore_plan_builder.class.php @@ -27,8 +27,8 @@ require_once($CFG->dirroot . '/backup/moodle2/restore_course_task.class.php'); require_once($CFG->dirroot . '/backup/moodle2/restore_section_task.class.php'); require_once($CFG->dirroot . '/backup/moodle2/restore_activity_task.class.php'); require_once($CFG->dirroot . '/backup/moodle2/restore_final_task.class.php'); -//require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php'); -//require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php'); +require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php'); +require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php'); //require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php'); require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php'); //require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php'); @@ -111,14 +111,18 @@ abstract class restore_plan_builder { // as far as the module can be missing on restore if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing $plan->add_task($task); - } - // For the given activity, add as many block tasks as necessary - // TODO: Add blocks, we need to introspect xml here - //$blockids = backup_plan_dbops::get_blockids_from_moduleid($id); - //foreach ($blockids as $blockid) { - // $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id)); - //} + // For the given activity path, add as many block tasks as necessary + // TODO: Add blocks, we need to introspect xml here + $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); + foreach ($blocks as $basepath => $name) { + if ($task = restore_factory::get_restore_block_task($name, $basepath)) { + $plan->add_task($task); + } else { + // TODO: Debug information about block not supported + } + } + } } /** @@ -156,18 +160,23 @@ abstract class restore_plan_builder { // Add the course task, responsible for restoring // all the course related information - $plan->add_task(restore_factory::get_restore_course_task($info->course, $courseid)); + $task = restore_factory::get_restore_course_task($info->course, $courseid); + $plan->add_task($task); // For the given course, add as many section tasks as necessary foreach ($info->sections as $sectionid => $section) { self::build_section_plan($controller, $sectionid); } - // For the given course, add as many block tasks as necessary + // For the given course path, add as many block tasks as necessary // TODO: Add blocks, we need to introspect xml here - //$blockids = backup_plan_dbops::get_blockids_from_courseid($id); - //foreach ($blockids as $blockid) { - // $plan->add_task(restore_factory::get_restore_block_task($controller->get_format(), $blockid)); - //} + $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); + foreach ($blocks as $basepath => $name) { + if ($task = restore_factory::get_restore_block_task($name, $basepath)) { + $plan->add_task($task); + } else { + // TODO: Debug information about block not supported + } + } } } -- 2.43.0