3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Defines various element classes used in specific areas
21 * @package core_backup
24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 * Implementation of backup_final_element that provides one interceptor for anonymization of data
33 * This class overwrites the standard set_value() method, in order to get (by name)
34 * functions from backup_anonymizer_helper executed, producing anonymization of information
35 * to happen in a clean way
37 * TODO: Finish phpdocs
39 class anonymizer_final_element
extends backup_final_element
{
41 public function set_value($value) {
43 $pname = $this->get_parent()->get_name();
45 $myname = $this->get_name();
46 // Define class and function name
47 $classname = 'backup_anonymizer_helper';
48 $methodname= 'process_' . $pname . '_' . $myname;
49 // Invoke the interception method
50 $result = call_user_func(array($classname, $methodname), $value);
52 parent
::set_value($result);
57 * Implementation of backup_final_element that provides special handling of mnethosturl
59 * This class overwrites the standard set_value() method, in order to decide,
60 * based on various config options, what to do with the field.
62 * TODO: Finish phpdocs
64 class mnethosturl_final_element
extends backup_final_element
{
66 public function set_value($value) {
69 $localhostwwwroot = backup_plan_dbops
::get_mnet_localhost_wwwroot();
71 // If user wwwroot matches mnet local host one or if
72 // there isn't associated wwwroot, skip sending it to file
73 if ($localhostwwwroot == $value ||
empty($value)) {
76 parent
::set_value($value);
82 * Implementation of backup_nested_element that provides special handling of files
84 * This class overwrites the standard fill_values() method, so it gets intercepted
85 * for each file record being set to xml, in order to copy, at the same file, the
86 * physical file from moodle file storage to backup file storage
88 * TODO: Finish phpdocs
90 class file_nested_element
extends backup_nested_element
{
94 public function process($processor) {
95 // Get current backupid from processor, we'll need later
96 if (is_null($this->backupid
)) {
97 $this->backupid
= $processor->get_var(backup
::VAR_BACKUPID
);
99 return parent
::process($processor);
102 public function fill_values($values) {
104 parent
::fill_values($values);
105 // Do our own tasks (copy file from moodle to backup)
107 backup_file_manager
::copy_file_moodle2backup($this->backupid
, $values);
108 } catch (file_exception
$e) {
109 $this->add_result(array('missing_files_in_pool' => true));
111 // Build helpful log message with all information necessary to identify
113 $context = context
::instance_by_id($values->contextid
, IGNORE_MISSING
);
116 $contextname = ' \'' . $context->get_context_name() . '\'';
118 $message = 'Missing file in pool: ' . $values->filepath
. $values->filename
.
119 ' (context ' . $values->contextid
. $contextname . ', component ' .
120 $values->component
. ', filearea ' . $values->filearea
. ', itemid ' .
121 $values->itemid
. ') [' . $e->debuginfo
. ']';
122 $this->add_log($message, backup
::LOG_WARNING
);
128 * Implementation of backup_optigroup_element to be used by plugins stuff.
129 * Split just for better separation and future specialisation
131 class backup_plugin_element
extends backup_optigroup_element
{ }
134 * Implementation of backup_optigroup_element to be used by subplugins stuff.
135 * Split just for better separation and future specialisation
137 class backup_subplugin_element
extends backup_optigroup_element
{ }