Commit | Line | Data |
---|---|---|
77547b46 EL |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
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. | |
9 | // | |
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. | |
14 | // | |
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/>. | |
17 | ||
18 | /** | |
19 | * @package moodlecore | |
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 | |
23 | */ | |
24 | ||
25 | /** | |
26 | * course task that provides all the properties and common steps to be performed | |
27 | * when one course is being backup | |
28 | * | |
29 | * TODO: Finish phpdocs | |
30 | */ | |
31 | class backup_course_task extends backup_task { | |
32 | ||
33 | protected $courseid; | |
34 | protected $contextid; | |
35 | ||
36 | /** | |
37 | * Constructor - instantiates one object of this class | |
38 | */ | |
39 | public function __construct($name, $courseid, $plan = null) { | |
40 | ||
41 | $this->courseid = $courseid; | |
42 | $this->contextid = get_context_instance(CONTEXT_COURSE, $this->courseid)->id; | |
43 | ||
44 | parent::__construct($name, $plan); | |
45 | } | |
46 | ||
47 | public function get_contextid() { | |
48 | return $this->contextid; | |
49 | } | |
50 | ||
51 | /** | |
52 | * Course tasks have their own directory to write files | |
53 | */ | |
54 | public function get_taskbasepath() { | |
55 | ||
56 | return $this->get_basepath() . '/course'; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Create all the steps that will be part of this task | |
61 | */ | |
62 | public function build() { | |
63 | ||
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)); | |
67 | ||
68 | // Create the course directory | |
69 | $this->add_step(new create_taskbasepath_directory('create_course_directory')); | |
70 | ||
71 | // Create the course.xml file with course & category information | |
df997f84 | 72 | // annotating some bits, tags and module restrictions |
77547b46 EL |
73 | $this->add_step(new backup_course_structure_step('course_info', 'course.xml')); |
74 | ||
cb34c4cd PS |
75 | // Generate the enrolment file |
76 | $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml')); | |
df997f84 | 77 | |
f70676a7 EL |
78 | // Annotate all the groups and groupings belonging to the course |
79 | $this->add_step(new backup_annotate_course_groups_and_groupings('annotate_course_groups')); | |
80 | ||
81 | // Annotate the groups used in already annotated groupings (note this may be | |
82 | // unnecessary now that we are annotating all the course groups and groupings in the | |
83 | // step above. But we keep it working in case we decide, someday, to introduce one | |
84 | // setting to transform the step above into an optional one. This is here to support | |
85 | // course->defaultgroupingid | |
86 | $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups_from_groupings')); | |
77547b46 | 87 | |
767cb7f0 EL |
88 | // Annotate the question_categories belonging to the course context |
89 | $this->add_step(new backup_calculate_question_categories('course_question_categories')); | |
90 | ||
77547b46 EL |
91 | // Generate the roles file (optionally role assignments and always role overrides) |
92 | $this->add_step(new backup_roles_structure_step('course_roles', 'roles.xml')); | |
93 | ||
94 | // Generate the filter file (conditionally) | |
95 | if ($this->get_setting_value('filters')) { | |
96 | $this->add_step(new backup_filters_structure_step('course_filters', 'filters.xml')); | |
97 | } | |
98 | ||
99 | // Generate the comments file (conditionally) | |
100 | if ($this->get_setting_value('comments')) { | |
101 | $this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml')); | |
102 | } | |
103 | ||
104 | // Generate the logs file (conditionally) | |
105 | if ($this->get_setting_value('logs')) { | |
0f66aced | 106 | $this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml')); |
77547b46 EL |
107 | } |
108 | ||
109 | // Generate the inforef file (must be after ALL steps gathering annotations of ANY type) | |
110 | $this->add_step(new backup_inforef_structure_step('course', 'inforef.xml')); | |
111 | ||
112 | // Migrate the already exported inforef entries to final ones | |
113 | $this->add_step(new move_inforef_annotations_to_final('migrate_inforef')); | |
114 | ||
115 | // At the end, mark it as built | |
116 | $this->built = true; | |
117 | } | |
118 | ||
9dbe1980 EL |
119 | /** |
120 | * Code the transformations to perform in the course in | |
121 | * order to get transportable (encoded) links | |
122 | */ | |
123 | static public function encode_content_links($content) { | |
124 | global $CFG; | |
125 | ||
5ab8d2de | 126 | $base = preg_quote($CFG->wwwroot, '/'); |
9dbe1980 EL |
127 | |
128 | // Link to the course main page (it also covers "&topic=xx" and "&week=xx" | |
129 | // because they don't become transformed (section number) in backup/restore | |
130 | $search = '/(' . $base . '\/course\/view.php\?id\=)([0-9]+)/'; | |
131 | $content= preg_replace($search, '$@COURSEVIEWBYID*$2@$', $content); | |
132 | ||
133 | return $content; | |
134 | } | |
135 | ||
77547b46 EL |
136 | // Protected API starts here |
137 | ||
138 | /** | |
139 | * Define the common setting that any backup section will have | |
140 | */ | |
141 | protected function define_settings() { | |
142 | ||
143 | // Nothing to add, sections doesn't have common settings (for now) | |
144 | ||
145 | } | |
146 | } |