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  
   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-helper
  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  require_once($CFG->dirroot.'/backup/util/xml/parser/processors/grouped_parser_processor.class.php');
  26  
  27  /**
  28   * helper implementation of grouped_parser_processor that will
  29   * load all the contents of one users.xml file to the backup_ids table
  30   * storing the whole structure there for later processing.
  31   * Note: only "needed" users are loaded (must have userref record in backup_ids)
  32   * Note: parentitemid will contain the user->contextid
  33   * Note: althought included in backup, we don't restore user context ras/caps
  34   * in same site they will be already there and it doesn't seem a good idea
  35   * to make them "transportable" arround sites.
  36   *
  37   * TODO: Complete phpdocs
  38   */
  39  class restore_users_parser_processor extends grouped_parser_processor {
  40  
  41      protected $restoreid;
  42  
  43      public function __construct($restoreid) {
  44          $this->restoreid = $restoreid;
  45          parent::__construct(array());
  46          // Set the paths we are interested on, returning all them grouped under user
  47          $this->add_path('/users/user', true);
  48          $this->add_path('/users/user/custom_fields/custom_field');
  49          $this->add_path('/users/user/tags/tag');
  50          $this->add_path('/users/user/preferences/preference');
  51          // As noted above, we skip user context ras and caps
  52          // $this->add_path('/users/user/roles/role_overrides/override');
  53          // $this->add_path('/users/user/roles/role_assignments/assignment');
  54      }
  55  
  56      protected function dispatch_chunk($data) {
  57          // Received one user chunck, we are going to store it into backup_ids
  58          // table, with name = user and parentid = contextid for later use
  59          $itemname = 'user';
  60          $itemid   = $data['tags']['id'];
  61          $parentitemid = $data['tags']['contextid'];
  62          $info = $data['tags'];
  63          // Only load it if needed (exist same userref itemid in table)
  64          if (restore_dbops::get_backup_ids_record($this->restoreid, 'userref', $itemid)) {
  65              restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, $parentitemid, $info);
  66          }
  67      }
  68  
  69      protected function notify_path_start($path) {
  70          // nothing to do
  71      }
  72  
  73      protected function notify_path_end($path) {
  74          // nothing to do
  75      }
  76  
  77      /**
  78       * Provide NULL decoding
  79       */
  80      public function process_cdata($cdata) {
  81          if ($cdata === '$@NULL@$') {
  82              return null;
  83          }
  84          return $cdata;
  85      }
  86  }