1 |
efrain |
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 |
* Restore implementation for the (tool_log) logstore_standard subplugin.
|
|
|
19 |
*
|
|
|
20 |
* @package logstore_standard
|
|
|
21 |
* @category backup
|
|
|
22 |
* @copyright 2015 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
class restore_logstore_standard_subplugin extends restore_tool_log_logstore_subplugin {
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Returns the subplugin structure to attach to the 'logstore' XML element.
|
|
|
32 |
*
|
|
|
33 |
* @return restore_path_element[] array of elements to be processed on restore.
|
|
|
34 |
*/
|
|
|
35 |
protected function define_logstore_subplugin_structure() {
|
|
|
36 |
|
|
|
37 |
// If the logstore is not enabled we don't add structures for it.
|
|
|
38 |
$enabledlogstores = explode(',', get_config('tool_log', 'enabled_stores'));
|
|
|
39 |
if (!in_array('logstore_standard', $enabledlogstores)) {
|
|
|
40 |
return array(); // The logstore is not enabled, nothing to restore.
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
$paths = array();
|
|
|
44 |
|
|
|
45 |
$elename = $this->get_namefor('log');
|
|
|
46 |
$elepath = $this->get_pathfor('/logstore_standard_log');
|
|
|
47 |
$paths[] = new restore_path_element($elename, $elepath);
|
|
|
48 |
|
|
|
49 |
return $paths;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Process logstore_standard_log entries.
|
|
|
54 |
*
|
|
|
55 |
* This method proceeds to read, complete, remap and, finally,
|
|
|
56 |
* discard or save every log entry.
|
|
|
57 |
*
|
|
|
58 |
* @param array() $data log entry.
|
|
|
59 |
*/
|
|
|
60 |
public function process_logstore_standard_log($data) {
|
|
|
61 |
global $DB;
|
|
|
62 |
|
|
|
63 |
$data = $this->process_log($data, get_config('logstore_standard', 'jsonformat'));
|
|
|
64 |
|
|
|
65 |
if ($data) {
|
|
|
66 |
$DB->insert_record('logstore_standard_log', $data);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|