MDL-23479 backup - various fixes in feedback backup & restore + delete old code ...
[moodle.git] / mod / feedback / backup / moodle2 / restore_feedback_stepslib.php
CommitLineData
731ca13c
DM
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 * Define all the restore steps that will be used by the restore_feedback_activity_task
27 */
28
29/**
30 * Structure step to restore one feedback activity
31 */
32class restore_feedback_activity_structure_step extends restore_activity_structure_step {
33
34 protected function define_structure() {
35
36 $paths = array();
37 $userinfo = $this->get_setting_value('userinfo');
38
39 $paths[] = new restore_path_element('feedback', '/activity/feedback');
40 $paths[] = new restore_path_element('feedback_item', '/activity/feedback/items/item');
41 if ($userinfo) {
42 $paths[] = new restore_path_element('feedback_completed', '/activity/feedback/completeds/completed');
d68c337f 43 $paths[] = new restore_path_element('feedback_value', '/activity/feedback/completeds/completed/values/value');
731ca13c
DM
44 $paths[] = new restore_path_element('feedback_tracking', '/activity/feedback/trackings/tracking');
45 }
46
47 // Return the paths wrapped into standard activity structure
48 return $this->prepare_activity_structure($paths);
49 }
50
51 protected function process_feedback($data) {
52 global $DB;
53
54 $data = (object)$data;
55 $oldid = $data->id;
56 $data->course = $this->get_courseid();
57
58 $data->timeopen = $this->apply_date_offset($data->timeopen);
59 $data->timeclose = $this->apply_date_offset($data->timeclose);
76187215 60 $data->timemodified = $this->apply_date_offset($data->timemodified);
731ca13c
DM
61
62 // insert the feedback record
63 $newitemid = $DB->insert_record('feedback', $data);
64 // inmediately after inserting "activity" record, call this
65 $this->apply_activity_instance($newitemid);
66 }
67
68 protected function process_feedback_item($data) {
69 global $DB;
70
71 $data = (object)$data;
72 $oldid = $data->id;
73 $data->feedback = $this->get_new_parentid('feedback');
74
75 $newitemid = $DB->insert_record('feedback_item', $data);
d68c337f 76 $this->set_mapping('feedback_item', $oldid, $newitemid, true); // Can have files
731ca13c
DM
77 }
78
79 protected function process_feedback_completed($data) {
80 global $DB;
81
82 $data = (object)$data;
83 $oldid = $data->id;
84 $data->feedback = $this->get_new_parentid('feedback');
85 $data->userid = $this->get_mappingid('user', $data->userid);
f49c5361 86 $data->timemodified = $this->apply_date_offset($data->timemodified);
731ca13c
DM
87
88 $newitemid = $DB->insert_record('feedback_completed', $data);
89 $this->set_mapping('feedback_completed', $oldid, $newitemid);
90 }
91
92 protected function process_feedback_value($data) {
93 global $DB;
94
95 $data = (object)$data;
96 $oldid = $data->id;
731ca13c 97 $data->completed = $this->get_new_parentid('feedback_completed');
d68c337f 98 $data->item = $this->get_mappingid('feedback_item', $data->item);
731ca13c
DM
99 $data->course_id = $this->get_courseid();
100
101 $newitemid = $DB->insert_record('feedback_value', $data);
102 $this->set_mapping('feedback_value', $oldid, $newitemid);
103 }
104
105 protected function process_feedback_tracking($data) {
106 global $DB;
107
108 $data = (object)$data;
109 $oldid = $data->id;
110 $data->feedback = $this->get_new_parentid('feedback');
d68c337f 111 $data->completed = $this->get_mappingid('feedback_completed', $data->completed);
731ca13c
DM
112 $data->userid = $this->get_mappingid('user', $data->userid);
113
114 $newitemid = $DB->insert_record('feedback_tracking', $data);
731ca13c 115 }
d68c337f 116
731ca13c
DM
117
118 protected function after_execute() {
119 // Add feedback related files, no need to match by itemname (just internally handled context)
120 $this->add_related_files('mod_feedback', 'intro', null);
d68c337f 121 $this->add_related_files('mod_feedback', 'item', 'feedback_item');
731ca13c
DM
122 }
123}