3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @subpackage backup-moodle2
21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 * course task that provides all the properties and common steps to be performed
27 * when one course is being restored
29 * TODO: Finish phpdocs
31 class restore_course_task extends restore_task {
33 protected $info; // info related to course gathered from backup file
34 protected $contextid; // course context id
37 * Constructor - instantiates one object of this class
39 public function __construct($name, $info, $plan = null) {
41 parent::__construct($name, $plan);
45 * Course tasks have their own directory to read files
47 public function get_taskbasepath() {
49 return $this->get_basepath() . '/course';
52 public function get_contextid() {
53 return $this->contextid;
57 * Create all the steps that will be part of this task
59 public function build() {
61 // Define the task contextid (the course one)
62 $this->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
64 // Executed conditionally if restoring to new course or deleting or if overwrite_conf setting is enabled
65 if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) {
66 $this->add_step(new restore_course_structure_step('course_info', 'course.xml'));
69 // Restore course role assignments and overrides (internally will observe the role_assignments setting)
70 $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml'));
72 // Restore course enrolments (plugins and membership)
73 $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
75 // Restore course filters (conditionally)
76 if ($this->get_setting_value('filters')) {
77 $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml'));
80 // Restore course comments (conditionally)
81 if ($this->get_setting_value('comments')) {
82 $this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml'));
85 // Restore course logs (conditionally)
86 if ($this->get_setting_value('logs')) {
87 //$this->add_step(new restore_course_logs_structure_step('course_logs', 'logs.xml'));
90 // At the end, mark it as built
95 * Define the contents in the course that must be
96 * processed by the link decoder
98 static public function define_decode_contents() {
101 $contents[] = new restore_decode_content('course', 'summary');
107 * Define the decoding rules for links belonging
108 * to the course to be executed by the link decoder
110 static public function define_decode_rules() {
113 $rules[] = new restore_decode_rule('COURSEVIEWBYID', '/course/view.php?id=$1', 'course');
119 // Protected API starts here
122 * Define the common setting that any restore course will have
124 protected function define_settings() {
126 //$name, $vtype, $value = null, $visibility = self::VISIBLE, $status = self::NOT_LOCKED
127 $fullname = new restore_course_generic_text_setting('course_fullname', base_setting::IS_TEXT, $this->get_info()->original_course_fullname);
128 $fullname->get_ui()->set_label(get_string('setting_course_fullname', 'backup'));
129 $this->add_setting($fullname);
131 $shortname = new restore_course_generic_text_setting('course_shortname', base_setting::IS_TEXT, $this->get_info()->original_course_shortname);
132 $shortname->get_ui()->set_label(get_string('setting_course_shortname', 'backup'));
133 $this->add_setting($shortname);
135 $startdate = new restore_course_generic_text_setting('course_startdate', base_setting::IS_INTEGER, $this->get_info()->original_course_startdate);
136 $startdate->set_ui(new backup_setting_ui_dateselector($startdate, get_string('setting_course_startdate', 'backup')));
137 $this->add_setting($startdate);
139 // Define overwrite_conf to decide if course configuration will be restored over existing one
140 $overwrite = new restore_course_overwrite_conf_setting('overwrite_conf', base_setting::IS_BOOLEAN, false);
141 $overwrite->set_ui(new backup_setting_ui_select($overwrite, $overwrite->get_name(), array(1=>get_string('yes'), 0=>get_string('no'))));
142 $overwrite->get_ui()->set_label(get_string('setting_overwriteconf', 'backup'));
143 if ($this->get_target() == backup::TARGET_NEW_COURSE) {
144 $overwrite->set_value(true);
145 $overwrite->set_status(backup_setting::LOCKED_BY_CONFIG);
146 $overwrite->set_visibility(backup_setting::HIDDEN);
148 $this->add_setting($overwrite);