on-demand release 4.0dev+
[moodle.git] / mod / chat / backup / moodle2 / backup_chat_stepslib.php
CommitLineData
79447c50 1<?php
79447c50
DC
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
a6be3193 18 * @package mod_chat
79447c50
DC
19 * @subpackage backup-moodle2
20 * @copyright 2010 onwards Dongsheng Cai <dongsheng@moodle.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24/**
25 * Define all the backup steps that will be used by the backup_chat_activity_task
26 */
27class backup_chat_activity_structure_step extends backup_activity_structure_step {
28 protected function define_structure() {
29 $userinfo = $this->get_setting_value('userinfo');
30
c52b4db5 31 // Define each element separated.
79447c50
DC
32 $chat = new backup_nested_element('chat', array('id'), array(
33 'name', 'intro', 'introformat', 'keepdays', 'studentlogs',
34 'chattime', 'schedule', 'timemodified'));
35 $messages = new backup_nested_element('messages');
36
967a68fd
EL
37 $message = new backup_nested_element('message', array('id'), array(
38 'userid', 'groupid', 'system', 'message_text', 'timestamp'));
79447c50 39
c52b4db5 40 // It is not cool to have two tags with same name, so we need to rename message field to message_text.
79447c50 41 $message->set_source_alias('message', 'message_text');
307dce6c
MS
42 // Renamed 'issystem' into 'system', for backward compatibility: 'system' is now a reserved word in MySQL 8.0.3+.
43 $message->set_source_alias('issystem', 'system');
79447c50 44
c52b4db5 45 // Build the tree.
79447c50 46 $chat->add_child($messages);
307dce6c 47 $messages->add_child($message);
79447c50 48
c52b4db5 49 // Define sources.
79447c50
DC
50 $chat->set_source_table('chat', array('id' => backup::VAR_ACTIVITYID));
51
c52b4db5 52 // User related messages only happen if we are including user info.
79447c50 53 if ($userinfo) {
c52b4db5 54 $message->set_source_table('chat_messages', array('chatid' => backup::VAR_PARENTID));
79447c50
DC
55 }
56
c52b4db5 57 // Define id annotations.
79447c50
DC
58 $message->annotate_ids('user', 'userid');
59 $message->annotate_ids('group', 'groupid');
60
c52b4db5
AD
61 // Annotate the file areas in chat module.
62 $chat->annotate_files('mod_chat', 'intro', null); // The chat_intro area doesn't use itemid.
79447c50 63
c52b4db5 64 // Return the root element (chat), wrapped into standard activity structure.
79447c50
DC
65 return $this->prepare_activity_structure($chat);
66 }
67}