Commit | Line | Data |
---|---|---|
864842aa 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 | * section task that provides all the properties and common steps to be performed | |
27 | * when one section is being restored | |
28 | * | |
29 | * TODO: Finish phpdocs | |
30 | */ | |
31 | class restore_section_task extends restore_task { | |
32 | ||
33 | protected $info; // info related to section gathered from backup file | |
34 | ||
35 | /** | |
36 | * Constructor - instantiates one object of this class | |
37 | */ | |
38 | public function __construct($name, $info, $plan = null) { | |
39 | $this->info = $info; | |
40 | parent::__construct($name, $plan); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Section tasks have their own directory to read files | |
45 | */ | |
46 | public function get_taskbasepath() { | |
47 | ||
48 | return $this->get_basepath() . '/sections/section_' . $info->sectionid; | |
49 | } | |
50 | ||
51 | /** | |
52 | * Create all the steps that will be part of this task | |
53 | */ | |
54 | public function build() { | |
55 | ||
56 | // TODO: Link all the section steps here | |
57 | ||
58 | // At the end, mark it as built | |
59 | $this->built = true; | |
60 | } | |
61 | ||
62 | // Protected API starts here | |
63 | ||
64 | /** | |
65 | * Define the common setting that any restore section will have | |
66 | */ | |
67 | protected function define_settings() { | |
68 | ||
69 | // All the settings related to this activity will include this prefix | |
70 | $settingprefix = 'section_' . $this->info->sectionid . '_'; | |
71 | ||
72 | // All these are common settings to be shared by all sections | |
73 | ||
74 | // Define section_included (to decide if the whole task must be really executed) | |
75 | $settingname = $settingprefix . 'included'; | |
76 | $section_included = new restore_section_included_setting($settingname, base_setting::IS_BOOLEAN, true); | |
77 | $this->add_setting($section_included); | |
78 | ||
79 | // Define section_userinfo. Dependent of: | |
80 | // - users root setting | |
81 | // - section_included setting | |
82 | $settingname = $settingprefix . 'userinfo'; | |
83 | $selectvalues = array(0=>get_string('no')); // Safer options | |
84 | $defaultvalue = false; // Safer default | |
85 | if (isset($info->settings[$settingname]) && $info->settings[$settingname]) { // Only enabled when available | |
86 | $selectvalues = array(1=>get_string('yes'), 0=>get_string('no')); | |
87 | $defaultvalue = true; | |
88 | } | |
89 | $section_userinfo = new restore_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue); | |
90 | $section_userinfo->set_ui(new backup_setting_ui_select($section_userinfo, get_string('includeuserinfo','backup'), $selectvalues)); | |
91 | $this->add_setting($section_userinfo); | |
92 | // Look for "users" root setting | |
93 | $users = $this->plan->get_setting('users'); | |
94 | $users->add_dependency($section_userinfo); | |
95 | // Look for "section_included" section setting | |
96 | $section_included->add_dependency($section_userinfo); | |
97 | } | |
98 | } |