forked from netspotau/moodle-mod_groupselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restorelib.php
151 lines (132 loc) · 5.82 KB
/
restorelib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
//This php script contains all the stuff to backup/restore
//groupselect mods
//This is the "graphical" structure of the groupselect mod:
//
// groupselect
// (CL,pk->id)
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// CL->course level info
// UL->user level info
// files->table may have files)
//
//-----------------------------------------------------------
//This function executes all the restore procedure about this mod
function groupselect_restore_mods($mod,$restore) {
global $CFG;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the LABEL record structure
$groupselect = new object();
$groupselect->course = $restore->course_id;
$groupselect->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$groupselect->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
$groupselect->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
$groupselect->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']);
$groupselect->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']);
$groupselect->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the groupselect
$newid = insert_record ("groupselect",$groupselect);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("modulename","groupselect")." \"".format_string(stripslashes($groupselect->name),true)."\"</li>";
}
backup_flush(300);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,$mod->modtype,
$mod->id, $newid);
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}
function groupselect_decode_content_links_caller($restore) {
global $CFG;
$status = true;
if ($groupselects = get_records_sql ("SELECT l.id, l.intro
FROM {$CFG->prefix}groupselect l
WHERE l.course = $restore->course_id")) {
$i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($groupselects as $groupselect) {
//Increment counter
$i++;
$intro = $groupselect->intro;
$result = restore_decode_content_links_worker($intro,$restore);
if ($result != $intro) {
//Update record
$groupselect->intro = addslashes($result);
$status = update_record("groupselect", $groupselect);
if (debugging()) {
if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($intro).'<br />changed to<br />'.s($result).'<hr /><br />';
}
}
}
//Do some output
if (($i+1) % 5 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 100 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
}
return $status;
}
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function groupselect_restore_logs($restore,$log) {
$status = false;
//Depending of the action, we recode different things
switch ($log->action) {
case "add":
if ($log->cmid) {
//Get the new_id of the module (to recode the info field)
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
if ($mod) {
$log->url = "view.php?id=".$log->cmid;
$log->info = $mod->new_id;
$status = true;
}
}
break;
case "update":
if ($log->cmid) {
//Get the new_id of the module (to recode the info field)
$mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
if ($mod) {
$log->url = "view.php?id=".$log->cmid;
$log->info = $mod->new_id;
$status = true;
}
}
break;
default:
if (!defined('RESTORE_SILENTLY')) {
echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
}
break;
}
if ($status) {
$status = $log;
}
return $status;
}
?>