Skip to content

Commit

Permalink
DL-22146 backup & restore - course formats remaining hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 10, 2011
1 parent e5169d5 commit a90659d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
19 changes: 18 additions & 1 deletion backup/moodle2/backup_format_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,22 @@
* TODO: Finish phpdocs
*/
abstract class backup_format_plugin extends backup_plugin {
// Love these classes. :-) Nothing special to customize here for now

protected $courseformat; // To store the format (course->format) of the instance

public function __construct($plugintype, $pluginname, $optigroup, $step) {

parent::__construct($plugintype, $pluginname, $optigroup, $step);

$this->courseformat = backup_plan_dbops::get_courseformat_from_courseid($this->task->get_courseid());

}

/**
* Return the condition encapsulated into sqlparam format
* to get evaluated by value, not by path nor processor setting
*/
protected function get_format_condition() {
return array('sqlparam' => $this->courseformat);
}
}
6 changes: 6 additions & 0 deletions backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ protected function define_structure() {
$availability = new backup_nested_element('availability', array('id'), array(
'sourcecmid', 'requiredcompletion', 'gradeitemid', 'grademin', 'grademax'));

// attach format plugin structure to $module element, only one allowed
$this->add_plugin_structure('format', $module, false);

// Define the tree
$module->add_child($availinfo);
$availinfo->add_child($availability);
Expand Down Expand Up @@ -354,6 +357,9 @@ protected function define_structure() {
$section = new backup_nested_element('section', array('id'), array(
'number', 'name', 'summary', 'summaryformat', 'sequence', 'visible'));

// attach format plugin structure to $section element, only one allowed
$this->add_plugin_structure('format', $section, false);

// Define sources

$section->set_source_table('course_sections', array('id' => backup::VAR_SECTIONID));
Expand Down
10 changes: 10 additions & 0 deletions backup/moodle2/restore_section_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class restore_section_task extends restore_task {

protected $info; // info related to section gathered from backup file
protected $contextid; // course context id
protected $sectionid; // new (target) id of the course section

/**
* Constructor - instantiates one object of this class
*/
public function __construct($name, $info, $plan = null) {
$this->info = $info;
$this->sectionid = 0;
parent::__construct($name, $plan);
}

Expand All @@ -49,10 +51,18 @@ public function get_taskbasepath() {
return $this->get_basepath() . '/sections/section_' . $this->info->sectionid;
}

public function set_sectionid($sectionid) {
$this->sectionid = $sectionid;
}

public function get_contextid() {
return $this->contextid;
}

public function get_sectionid() {
return $this->sectionid;
}

/**
* Create all the steps that will be part of this task
*/
Expand Down
17 changes: 15 additions & 2 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,12 @@ protected function define_execution() {
class restore_section_structure_step extends restore_structure_step {

protected function define_structure() {
return array(new restore_path_element('section', '/section'));
$section = new restore_path_element('section', '/section');

// Apply for 'format' plugins optional paths at section level
$this->add_plugin_structure('format', $section);

return array($section);
}

public function process_section($data) {
Expand Down Expand Up @@ -962,6 +967,10 @@ public function process_section($data) {
// Annotate the section mapping, with restorefiles option if needed
$this->set_mapping('course_section', $oldid, $newitemid, $restorefiles);

// set the new course_section id in the task
$this->task->set_sectionid($newitemid);


// Commented out. We never modify course->numsections as far as that is used
// by a lot of people to "hide" sections on purpose (so this remains as used to be in Moodle 1.x)
// Note: We keep the code here, to know about and because of the possibility of making this
Expand Down Expand Up @@ -1985,11 +1994,15 @@ protected function define_structure() {

$paths = array();

$paths[] = new restore_path_element('module', '/module');
$module = new restore_path_element('module', '/module');
$paths[] = $module;
if ($CFG->enableavailability) {
$paths[] = new restore_path_element('availability', '/module/availability_info/availability');
}

// Apply for 'format' plugins optional paths at module level
$this->add_plugin_structure('format', $module);

return $paths;
}

Expand Down
9 changes: 9 additions & 0 deletions backup/util/dbops/backup_plan_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public static function get_sections_from_courseid($courseid) {
return $sectionsarr;
}

/**
* Given one course id, return its format in DB
*/
public static function get_courseformat_from_courseid($courseid) {
global $DB;

return $DB->get_field('course', 'format', array('id' => $courseid));
}

/**
* Return the wwwroot of the $CFG->mnet_localhost_id host
* caching it along the request
Expand Down

0 comments on commit a90659d

Please sign in to comment.