MDL-21432 backup - let the tasks to use the steps

This commit is contained in:
Eloy Lafuente 2010-07-27 23:40:35 +00:00
parent 394edb7e0e
commit 5ab8d2de39
7 changed files with 186 additions and 42 deletions

View File

@ -113,7 +113,7 @@ class backup_course_task extends backup_task {
static public function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
$base = preg_quote($CFG->wwwroot, '/');
// Link to the course main page (it also covers "&topic=xx" and "&week=xx"
// because they don't become transformed (section number) in backup/restore

View File

@ -31,6 +31,13 @@
abstract class restore_activity_task extends restore_task {
protected $info; // info related to activity gathered from backup file
protected $modulename; // name of the module
protected $moduleid; // new (target) id of the course module
protected $oldmoduleid; // old (original) id of the course module
protected $contextid; // new (target) context of the activity
protected $oldcontextid;// old (original) context of the activity
protected $activityid; // new (target) id of the activity
protected $oldactivityid;// old (original) id of the activity
/**
* Constructor - instantiates one object of this class
@ -38,6 +45,13 @@ abstract class restore_activity_task extends restore_task {
public function __construct($name, $info, $plan = null) {
$this->info = $info;
$this->modulename = $this->info->modulename;
$this->moduleid = 0;
$this->oldmoduleid = $this->info->moduleid;
$this->contextid = 0;
$this->oldcontextid = 0;
$this->activityid = 0;
$this->oldactivityid = 0;
parent::__construct($name, $plan);
}
@ -45,7 +59,51 @@ 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/' . $this->info->modulename . '_' . $this->info->moduleid;
return $this->get_basepath() . '/' . $this->info->directory;
}
public function set_moduleid($moduleid) {
$this->moduleid = $moduleid;
}
public function set_activityid($activityid) {
$this->activityid = $activityid;
}
public function set_old_activityid($activityid) {
$this->oldactivityid = $activityid;
}
public function set_contextid($contextid) {
$this->contextid = $contextid;
}
public function set_old_contextid($contextid) {
$this->oldcontextid = $contextid;
}
public function get_modulename() {
return $this->modulename;
}
public function get_moduleid() {
return $this->moduleid;
}
public function get_activityid() {
return $this->activityid;
}
public function get_old_activityid() {
return $this->oldactivityid;
}
public function get_contextid() {
return $this->contextid;
}
public function get_old_contextid() {
return $this->oldcontextid;
}
/**
@ -59,7 +117,39 @@ abstract class restore_activity_task extends restore_task {
return;
}
// TODO: Link all the activity steps here
// Load he course_module estructure, generating it (with instance = 0)
// but allowing the creation of the target context needed in following steps
$this->add_step(new restore_module_structure_step('module_info', 'module.xml'));
// Here we add all the common steps for any activity and, in the point of interest
// we call to define_my_steps() is order to get the particular ones inserted in place.
$this->define_my_steps();
// Roles (optionally role assignments and always role overrides)
$this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml'));
// Filters (conditionally)
if ($this->get_setting_value('filters')) {
$this->add_step(new restore_filters_structure_step('activity_filters', 'filters.xml'));
}
// Comments (conditionally)
if ($this->get_setting_value('comments')) {
$this->add_step(new restore_comments_structure_step('activity_comments', 'comments.xml'));
}
// TODO: Grades (module-related, rest of gradebook is restored later if possible: cats, calculations...)
//$this->add_step(new restore_activity_grades_structure_step('activity_grades', 'grades.xml'));
// TODO: Userscompletion (conditionally)
if ($this->get_setting_value('userscompletion')) {
//$this->add_step(new restore_userscompletion_structure_step('activity_userscompletion', 'completion.xml'));
}
// TODO: Logs (conditionally)
if ($this->get_setting_value('logs')) {
//$this->add_step(new restore_activity_logs_structure_step('activity_logs', 'logs.xml'));
}
// At the end, mark it as built
$this->built = true;
@ -106,6 +196,23 @@ abstract class restore_activity_task extends restore_task {
}
}
/**
* Define (add) particular steps that each activity can have
*/
abstract protected function define_my_steps();
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
abstract static public function define_decode_contents();
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
abstract static public function define_decode_rules();
// Protected API starts here
/**
@ -142,7 +249,7 @@ abstract class restore_activity_task extends restore_task {
$settingname = $settingprefix . 'userinfo';
$selectvalues = array(0=>get_string('no')); // Safer options
$defaultvalue = false; // Safer default
if (isset($info->settings[$settingname]) && $info->settings[$settingname]) { // Only enabled when available
if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
$selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
$defaultvalue = true;
}
@ -169,16 +276,4 @@ abstract class restore_activity_task extends restore_task {
* Define (add) particular settings that each activity can have
*/
abstract protected function define_my_settings();
/**
* Define (add) particular steps that each activity can have
*/
abstract protected function define_my_steps();
/**
* 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);
}

View File

@ -137,6 +137,29 @@ abstract class restore_block_task extends restore_task {
return $this->oldcontextid;
}
/**
* Define one array() of fileareas that each block controls
*/
abstract public function get_fileareas();
/**
* Define one array() of configdata attributes
* that need to be decoded
*/
abstract public function get_configdata_encoded_attributes();
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
abstract static public function define_decode_contents();
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
abstract static public function define_decode_rules();
// Protected API starts here
/**
@ -159,21 +182,4 @@ abstract class restore_block_task extends restore_task {
* Define (add) particular steps that each block can have
*/
abstract protected function define_my_steps();
/**
* Define one array() of fileareas that each block controls
*/
abstract public function get_fileareas();
/**
* 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);
}

View File

@ -92,14 +92,28 @@ class restore_course_task extends restore_task {
}
/**
* Code the transformations to perform in the course in
* order to get encoded transformed back to working links
* Define the contents in the course that must be
* processed by the link decoder
*/
static public function decode_content_links($content) {
static public function define_decode_contents() {
$contents = array();
// TODO: Decode COURSEVIEWBYID
$contents[] = new restore_decode_content('course', 'summary');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the course to be executed by the link decoder
*/
static public function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('COURSEVIEWBYID', '/course/view.php?id=$1', 'course');
return $rules;
return $content;
}
// Protected API starts here

View File

@ -45,8 +45,12 @@ class restore_default_block_task extends restore_block_task {
return array();
}
static public function decode_content_links($content) {
return $content;
static public function define_decode_contents() {
return array();
}
static public function define_decode_rules() {
return array();
}
}

View File

@ -43,7 +43,12 @@ class restore_final_task extends restore_task {
}
// TODO: Gradebook
// TODO: interlinks
// Decode all the interlinks
$this->add_step(new restore_decode_interlinks('decode_interlinks'));
// Rebuild course cache to see results, whoah!
$this->add_step(new restore_rebuild_course_cache('rebuild_course_cache'));
// Clean the temp dir (conditionally) and drop temp table
$this->add_step(new restore_drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'));

View File

@ -110,6 +110,26 @@ class restore_section_task extends restore_task {
}
}
/**
* Define the contents in the course that must be
* processed by the link decoder
*/
static public function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('course_sections', 'summary', 'course_section');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the sections to be executed by the link decoder
*/
static public function define_decode_rules() {
return array();
}
// Protected API starts here
/**
@ -133,7 +153,7 @@ class restore_section_task extends restore_task {
$settingname = $settingprefix . 'userinfo';
$selectvalues = array(0=>get_string('no')); // Safer options
$defaultvalue = false; // Safer default
if (isset($info->settings[$settingname]) && $info->settings[$settingname]) { // Only enabled when available
if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
$selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
$defaultvalue = true;
}