[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Defines various element classes used in specific areas 20 * 21 * @package core_backup 22 * @subpackage moodle2 23 * @category 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 26 */ 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 /** 31 * Implementation of backup_final_element that provides one interceptor for anonymization of data 32 * 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 36 * 37 * TODO: Finish phpdocs 38 */ 39 class anonymizer_final_element extends backup_final_element { 40 41 public function set_value($value) { 42 // Get parent name 43 $pname = $this->get_parent()->get_name(); 44 // Get my 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); 51 // Finally set it 52 parent::set_value($result); 53 } 54 } 55 56 /** 57 * Implementation of backup_final_element that provides special handling of mnethosturl 58 * 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. 61 * 62 * TODO: Finish phpdocs 63 */ 64 class mnethosturl_final_element extends backup_final_element { 65 66 public function set_value($value) { 67 global $CFG; 68 69 $localhostwwwroot = backup_plan_dbops::get_mnet_localhost_wwwroot(); 70 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)) { 74 // Do nothing 75 } else { 76 parent::set_value($value); 77 } 78 } 79 } 80 81 /** 82 * Implementation of {@link backup_final_element} that provides base64 encoding. 83 * 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 86 * data...). 87 */ 88 class base64_encode_final_element extends backup_final_element { 89 90 /** 91 * Set the value for the final element, encoding it as utf-8/xml safe base64. 92 * 93 * @param string $value Original value coming from backup step source, usually db. 94 */ 95 public function set_value($value) { 96 parent::set_value(base64_encode($value)); 97 } 98 } 99 100 /** 101 * Implementation of backup_nested_element that provides special handling of files 102 * 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 106 * 107 * TODO: Finish phpdocs 108 */ 109 class file_nested_element extends backup_nested_element { 110 111 protected $backupid; 112 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); 117 } 118 return parent::process($processor); 119 } 120 121 public function fill_values($values) { 122 // Fill values 123 parent::fill_values($values); 124 // Do our own tasks (copy file from moodle to backup) 125 try { 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)); 129 130 // Build helpful log message with all information necessary to identify 131 // file location. 132 $context = context::instance_by_id($values->contextid, IGNORE_MISSING); 133 $contextname = ''; 134 if ($context) { 135 $contextname = ' \'' . $context->get_context_name() . '\''; 136 } 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); 142 } 143 } 144 } 145 146 /** 147 * Implementation of backup_optigroup_element to be used by plugins stuff. 148 * Split just for better separation and future specialisation 149 */ 150 class backup_plugin_element extends backup_optigroup_element { } 151 152 /** 153 * Implementation of backup_optigroup_element to be used by subplugins stuff. 154 * Split just for better separation and future specialisation 155 */ 156 class backup_subplugin_element extends backup_optigroup_element { }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |