1 |
efrain |
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 roles.xml (roles description) file to the backup_ids table
|
|
|
30 |
* storing the whole structure there for later processing.
|
|
|
31 |
* Note: only "needed" roles are loaded (must have roleref record in backup_ids)
|
|
|
32 |
*
|
|
|
33 |
* TODO: Complete phpdocs
|
|
|
34 |
*/
|
|
|
35 |
class restore_roles_parser_processor extends grouped_parser_processor {
|
|
|
36 |
|
|
|
37 |
protected $restoreid;
|
|
|
38 |
|
|
|
39 |
public function __construct($restoreid) {
|
|
|
40 |
$this->restoreid = $restoreid;
|
|
|
41 |
parent::__construct(array());
|
|
|
42 |
// Set the paths we are interested on, returning all them grouped under user
|
|
|
43 |
$this->add_path('/roles_definition/role');
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
protected function dispatch_chunk($data) {
|
|
|
47 |
// Received one role chunck, we are going to store it into backup_ids
|
|
|
48 |
// table, with name = role
|
|
|
49 |
$itemname = 'role';
|
|
|
50 |
$itemid = $data['tags']['id'];
|
|
|
51 |
$info = $data['tags'];
|
|
|
52 |
// Only load it if needed (exist same roleref itemid in table)
|
|
|
53 |
if (restore_dbops::get_backup_ids_record($this->restoreid, 'roleref', $itemid)) {
|
|
|
54 |
restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, null, $info);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
protected function notify_path_start($path) {
|
|
|
59 |
// nothing to do
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
protected function notify_path_end($path) {
|
|
|
63 |
// nothing to do
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Provide NULL decoding
|
|
|
68 |
*/
|
|
|
69 |
public function process_cdata($cdata) {
|
|
|
70 |
if ($cdata === '$@NULL@$') {
|
|
|
71 |
return null;
|
|
|
72 |
}
|
|
|
73 |
return $cdata;
|
|
|
74 |
}
|
|
|
75 |
}
|