MDL-21432 backup 2.0 - initial commit. util dir
[moodle.git] / backup / util / helper / backup_anonymizer_helper.class.php
CommitLineData
69dd0c8c
EL
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/**
26 * Helper class for anonymization of data
27 *
28 * This functions includes a collection of methods that are invoked
29 * from the backup process when anonymization services have been
30 * requested.
31 *
32 * The name of each method must be "process_parentname_name", as defined
33 * byt the @anonymizer_final_element final element class, where
34 * parentname is the name ob the parent tag and name the name of the tag
35 * contents to be anonymized (i.e. process_user_username) with one param
36 * being the value to anonymize.
37 *
38 * Note: current implementation of anonymization is pretty simple, just some
39 * sequential values are used. If we want more elaborated generation, it
40 * can be replaced later (using generators or wathever). Don't forget we must
41 * ensure some fields (username, idnumber, email) are unique always.
42 *
43 * TODO: Improve to use more advanced anonymization
44 *
45 * TODO: Finish phpdocs
46 */
47class backup_anonymizer_helper {
48
49 public static function process_user_auth($value) {
50 return 'manual'; // Set them to manual always
51 }
52
53 public static function process_user_username($value) {
54 static $counter = 0;
55 $counter++;
56 return 'anon' . $counter; // Just a counter
57 }
58
59 public static function process_user_idnumber($value) {
60 return ''; // Just blank it
61 }
62
63 public static function process_user_firstname($value) {
64 static $counter = 0;
65 $counter++;
66 return 'anonfirstname' . $counter; // Just a counter
67 }
68
69 public static function process_user_lastname($value) {
70 static $counter = 0;
71 $counter++;
72 return 'anonlastname' . $counter; // Just a counter
73 }
74
75 public static function process_user_email($value) {
76 static $counter = 0;
77 $counter++;
78 return 'anon' . $counter . '@doesntexist.com'; // Just a counter
79 }
80
81 public static function process_user_emailstop($value) {
82 return 1; // Stop email for anon users
83 }
84
85 public static function process_user_lastip($value) {
86 return '127.0.0.1'; // Set lastip to localhost
87 }
88
89 public static function process_user_picture($value) {
90 return 0; // No picture
91 }
92
93 public static function process_user_url($value) {
94 return ''; // No url
95 }
96
97 public static function process_user_description($value) {
98 return ''; // No user description
99 }
100
101 public static function process_user_imagealt($value) {
102 return ''; // No user imagealt
103 }
104}