2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * @subpackage backup-moodle2
20 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 * Define all the restore steps that will be used by the restore_chat_activity_task
29 * Structure step to restore one chat activity
31 class restore_chat_activity_structure_step extends restore_activity_structure_step {
33 protected function define_structure() {
36 $userinfo = $this->get_setting_value('userinfo');
38 $paths[] = new restore_path_element('chat', '/activity/chat');
40 $paths[] = new restore_path_element('chat_message', '/activity/chat/messages/message');
43 // Return the paths wrapped into standard activity structure.
44 return $this->prepare_activity_structure($paths);
47 protected function process_chat($data) {
50 $data = (object)$data;
52 $data->course = $this->get_courseid();
54 // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
56 $data->chattime = $this->apply_date_offset($data->chattime);
58 // Insert the chat record.
59 $newitemid = $DB->insert_record('chat', $data);
60 // Immediately after inserting "activity" record, call this.
61 $this->apply_activity_instance($newitemid);
64 protected function process_chat_message($data) {
67 $data = (object)$data;
69 $data->chatid = $this->get_new_parentid('chat');
70 $data->userid = $this->get_mappingid('user', $data->userid);
71 $data->groupid = $this->get_mappingid('group', $data->groupid);
72 $data->message = $data->message_text;
73 $data->issystem = $data->system;
75 $newitemid = $DB->insert_record('chat_messages', $data);
76 $this->set_mapping('chat_message', $oldid, $newitemid); // Because of decode.
79 protected function after_execute() {
80 // Add chat related files, no need to match by itemname (just internally handled context).
81 $this->add_related_files('mod_chat', 'intro', null);