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 backup
29 * TODO: Finish phpdocs
31 class backup_course_task extends backup_task {
37 * Constructor - instantiates one object of this class
39 public function __construct($name, $courseid, $plan = null) {
41 $this->courseid = $courseid;
42 $this->contextid = get_context_instance(CONTEXT_COURSE, $this->courseid)->id;
44 parent::__construct($name, $plan);
47 public function get_contextid() {
48 return $this->contextid;
52 * Course tasks have their own directory to write files
54 public function get_taskbasepath() {
56 return $this->get_basepath() . '/course';
60 * Create all the steps that will be part of this task
62 public function build() {
64 // Add some extra settings that related processors are going to need
65 $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));
66 $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid));
68 // Create the course directory
69 $this->add_step(new create_taskbasepath_directory('create_course_directory'));
71 // Create the course.xml file with course & category information
72 // annotating some bits, tags and module restrictions
73 $this->add_step(new backup_course_structure_step('course_info', 'course.xml'));
75 // Generate the enrolment file
76 $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
78 // Annotate the groups used in already annotated groupings
79 $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups'));
81 // Generate the roles file (optionally role assignments and always role overrides)
82 $this->add_step(new backup_roles_structure_step('course_roles', 'roles.xml'));
84 // Generate the filter file (conditionally)
85 if ($this->get_setting_value('filters')) {
86 $this->add_step(new backup_filters_structure_step('course_filters', 'filters.xml'));
89 // Generate the comments file (conditionally)
90 if ($this->get_setting_value('comments')) {
91 $this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml'));
94 // Generate the logs file (conditionally)
95 if ($this->get_setting_value('logs')) {
96 //$this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
99 // Generate the inforef file (must be after ALL steps gathering annotations of ANY type)
100 $this->add_step(new backup_inforef_structure_step('course', 'inforef.xml'));
102 // Migrate the already exported inforef entries to final ones
103 $this->add_step(new move_inforef_annotations_to_final('migrate_inforef'));
105 // At the end, mark it as built
110 * Code the transformations to perform in the course in
111 * order to get transportable (encoded) links
113 static public function encode_content_links($content) {
116 $base = preg_quote($CFG->wwwroot,"/");
118 // Link to the course main page (it also covers "&topic=xx" and "&week=xx"
119 // because they don't become transformed (section number) in backup/restore
120 $search = '/(' . $base . '\/course\/view.php\?id\=)([0-9]+)/';
121 $content= preg_replace($search, '$@COURSEVIEWBYID*$2@$', $content);
126 // Protected API starts here
129 * Define the common setting that any backup section will have
131 protected function define_settings() {
133 // Nothing to add, sections doesn't have common settings (for now)