MDL-21432 restore - spreading restore plan with block tasks
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user