Merge branch 'MDL-47323-enrol-plugin-backup' of https://github.com/mpetrowi/moodle

This commit is contained in:
Dan Poltawski 2014-12-09 22:29:37 +00:00
commit e600e6ae50
8 changed files with 142 additions and 6 deletions

View File

@ -80,6 +80,9 @@ class backup_course_task extends backup_task {
$this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
}
// Annotate enrolment custom fields.
$this->add_step(new backup_enrolments_execution_step('annotate_enrol_custom_fields'));
// Annotate all the groups and groupings belonging to the course
$this->add_step(new backup_annotate_course_groups_and_groupings('annotate_course_groups'));

View File

@ -0,0 +1,39 @@
<?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/>.
/**
* Defines backup_enrol_plugin class.
*
* @package core_backup
* @subpackage moodle2
* @category backup
* @copyright 2014 University of Wisconsin
* @author Matt petro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Base class for enrol backup plugins.
*
* @package core_backup
* @copyright 2014 University of Wisconsin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class backup_enrol_plugin extends backup_plugin {
// Use default parent behaviour.
}

View File

@ -44,6 +44,7 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_enrol_plugin.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');

View File

@ -555,7 +555,8 @@ class backup_enrolments_structure_step extends backup_structure_step {
$enrol->annotate_ids('role', 'roleid');
//TODO: let plugins annotate custom fields too and add more children
// Add enrol plugin structure.
$this->add_plugin_structure('enrol', $enrol, false);
return $enrolments;
}
@ -1875,6 +1876,47 @@ class backup_activity_grade_items_to_ids extends backup_execution_step {
}
}
/**
* This step allows enrol plugins to annotate custom fields.
*
* @package core_backup
* @copyright 2014 University of Wisconsin
* @author Matt Petro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_enrolments_execution_step extends backup_execution_step {
/**
* Function that will contain all the code to be executed.
*/
protected function define_execution() {
global $DB;
$plugins = enrol_get_plugins(true);
$enrols = $DB->get_records('enrol', array(
'courseid' => $this->task->get_courseid()));
// Allow each enrol plugin to add annotations.
foreach ($enrols as $enrol) {
if (isset($plugins[$enrol->enrol])) {
$plugins[$enrol->enrol]->backup_annotate_custom_fields($this, $enrol);
}
}
}
/**
* Annotate a single name/id pair.
* This can be called from {@link enrol_plugin::backup_annotate_custom_fields()}.
*
* @param string $itemname
* @param int $itemid
*/
public function annotate_id($itemname, $itemid) {
backup_structure_dbops::insert_backup_ids_record($this->get_backupid(), $itemname, $itemid);
}
}
/**
* This step will annotate all the groups and groupings belonging to the course
*/

View File

@ -0,0 +1,39 @@
<?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/>.
/**
* Defines restore_enrol_plugin class.
*
* @package core_backup
* @subpackage moodle2
* @category backup
* @copyright 2014 University of Wisconsin
* @author Matt petro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Base class for enrol backup plugins.
*
* @package core_backup
* @copyright 2014 University of Wisconsin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class restore_enrol_plugin extends restore_plugin {
// Use default parent behaviour.
}

View File

@ -43,6 +43,7 @@ require_once($CFG->dirroot . '/backup/moodle2/restore_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_enrol_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
@ -52,6 +53,7 @@ require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_enrol_plugin.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');

View File

@ -1884,12 +1884,12 @@ class restore_enrolments_structure_step extends restore_structure_step {
protected function define_structure() {
$paths = array();
$enrol = new restore_path_element('enrol', '/enrolments/enrols/enrol');
$enrolment = new restore_path_element('enrolment', '/enrolments/enrols/enrol/user_enrolments/enrolment');
// Attach local plugin stucture to enrol element.
$this->add_plugin_structure('enrol', $enrol);
$paths[] = new restore_path_element('enrol', '/enrolments/enrols/enrol');
$paths[] = new restore_path_element('enrolment', '/enrolments/enrols/enrol/user_enrolments/enrolment');
return $paths;
return array($enrol, $enrolment);
}
/**

View File

@ -2278,6 +2278,16 @@ abstract class enrol_plugin {
force_current_language($oldforcelang);
}
/**
* Backup execution step hook to annotate custom fields.
*
* @param backup_enrolments_execution_step $step
* @param stdClass $enrol
*/
public function backup_annotate_custom_fields(backup_enrolments_execution_step $step, stdClass $enrol) {
// Override as necessary to annotate custom fields in the enrol table.
}
/**
* Automatic enrol sync executed during restore.
* Useful for automatic sync by course->idnumber or course category.