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 | |
77547b46 EL |
78 | // Annotate the groups used in already annotated groupings |
79 | $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups')); | |
80 | ||
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')); | |
83 | ||
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')); | |
87 | } | |
88 | ||
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')); | |
92 | } | |
93 | ||
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')); | |
97 | } | |
98 | ||
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')); | |
101 | ||
102 | // Migrate the already exported inforef entries to final ones | |
103 | $this->add_step(new move_inforef_annotations_to_final('migrate_inforef')); | |
104 | ||
105 | // At the end, mark it as built | |
106 | $this->built = true; | |
107 | } | |
108 | ||
9dbe1980 EL |
109 | /** |
110 | * Code the transformations to perform in the course in | |
111 | * order to get transportable (encoded) links | |
112 | */ | |
113 | static public function encode_content_links($content) { | |
114 | global $CFG; | |
115 | ||
116 | $base = preg_quote($CFG->wwwroot,"/"); | |
117 | ||
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); | |
122 | ||
123 | return $content; | |
124 | } | |
125 | ||
77547b46 EL |
126 | // Protected API starts here |
127 | ||
128 | /** | |
129 | * Define the common setting that any backup section will have | |
130 | */ | |
131 | protected function define_settings() { | |
132 | ||
133 | // Nothing to add, sections doesn't have common settings (for now) | |
134 | ||
135 | } | |
136 | } |