Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   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  /**
  18   * @package    mod_chat
  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
  22   */
  23  
  24  /**
  25   * Define all the restore steps that will be used by the restore_chat_activity_task
  26   */
  27  
  28  /**
  29   * Structure step to restore one chat activity
  30   */
  31  class restore_chat_activity_structure_step extends restore_activity_structure_step {
  32  
  33      protected function define_structure() {
  34  
  35          $paths = array();
  36          $userinfo = $this->get_setting_value('userinfo');
  37  
  38          $paths[] = new restore_path_element('chat', '/activity/chat');
  39          if ($userinfo) {
  40              $paths[] = new restore_path_element('chat_message', '/activity/chat/messages/message');
  41          }
  42  
  43          // Return the paths wrapped into standard activity structure.
  44          return $this->prepare_activity_structure($paths);
  45      }
  46  
  47      protected function process_chat($data) {
  48          global $DB;
  49  
  50          $data = (object)$data;
  51          $oldid = $data->id;
  52          $data->course = $this->get_courseid();
  53  
  54          // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
  55          // See MDL-9367.
  56          $data->chattime = $this->apply_date_offset($data->chattime);
  57  
  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);
  62      }
  63  
  64      protected function process_chat_message($data) {
  65          global $DB;
  66  
  67          $data = (object)$data;
  68          $oldid = $data->id;
  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;
  74  
  75          $newitemid = $DB->insert_record('chat_messages', $data);
  76          $this->set_mapping('chat_message', $oldid, $newitemid); // Because of decode.
  77      }
  78  
  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);
  82      }
  83  }