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 {@link backup_final_element} that provides base64 encoding.
84 * This final element transparently encodes with base64_encode() contents that
85 * normally are not safe for being stored in utf-8 xml files (binaries, serialized
88 class base64_encode_final_element
extends backup_final_element
{
91 * Set the value for the final element, encoding it as utf-8/xml safe base64.
93 * @param string $value Original value coming from backup step source, usually db.
95 public function set_value($value) {
96 parent
::set_value(base64_encode($value));
101 * Implementation of backup_nested_element that provides special handling of files
103 * This class overwrites the standard fill_values() method, so it gets intercepted
104 * for each file record being set to xml, in order to copy, at the same file, the
105 * physical file from moodle file storage to backup file storage
107 * TODO: Finish phpdocs
109 class file_nested_element
extends backup_nested_element
{
113 public function process($processor) {
114 // Get current backupid from processor, we'll need later
115 if (is_null($this->backupid
)) {
116 $this->backupid
= $processor->get_var(backup
::VAR_BACKUPID
);
118 return parent
::process($processor);
121 public function fill_values($values) {
123 parent
::fill_values($values);
124 // Do our own tasks (copy file from moodle to backup)
126 backup_file_manager
::copy_file_moodle2backup($this->backupid
, $values);
127 } catch (file_exception
$e) {
128 $this->add_result(array('missing_files_in_pool' => true));
130 // Build helpful log message with all information necessary to identify
132 $context = context
::instance_by_id($values->contextid
, IGNORE_MISSING
);
135 $contextname = ' \'' . $context->get_context_name() . '\'';
137 $message = 'Missing file in pool: ' . $values->filepath
. $values->filename
.
138 ' (context ' . $values->contextid
. $contextname . ', component ' .
139 $values->component
. ', filearea ' . $values->filearea
. ', itemid ' .
140 $values->itemid
. ') [' . $e->debuginfo
. ']';
141 $this->add_log($message, backup
::LOG_WARNING
);
147 * Implementation of backup_optigroup_element to be used by plugins stuff.
148 * Split just for better separation and future specialisation
150 class backup_plugin_element
extends backup_optigroup_element
{ }
153 * Implementation of backup_optigroup_element to be used by subplugins stuff.
154 * Split just for better separation and future specialisation
156 class backup_subplugin_element
extends backup_optigroup_element
{ }