-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestorelib.php
executable file
·197 lines (170 loc) · 6.8 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright © 2011 The Regents of the University of California.
// All Rights Reserved.
/**
* restorelib.php
*
* @copyright © 2011 The Regents of the University of California
* @author carson.tam@ucsf.edu
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package mod_resourcelist
*/
//This php script contains all the stuff to backup/restore
//resourcelist mods
//This is the "graphical" structure of the resourcelist mod:
//
// resourcelist
// (CL,pk->id,files)
//
// 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 resourcelist_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 RESOURCELIST record structure
$resourcelist->course = $restore->course_id;
$resourcelist->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$resourcelist->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
$resourcelist->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
//The structure is equal to the db, so insert the resourcelist
$newid = insert_record ("resourcelist",$resourcelist);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("modulename","resourcelist")." \"".format_string(stripslashes($resourcelist->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);
$status = resourcelist_items_restore_mods($newid,$info,$restore);
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}
function resourcelist_items_restore_mods($resourcelistid,$info,$restore) {
global $CFG;
$status = true;
$listitems = $info['MOD']['#']['LISTITEMS']['0']['#']['LISTITEM'];
// Iterate over listitems
for($i=0;$i<sizeof($listitems);$i++) {
$item_info = $listitems[$i];
$oldid = backup_todb($item_info['#']['ID']['0']['#']);
$listitem->resourcelistid = $resourcelistid;
$resource_old_id = backup_todb($item_info['#']['RESOURCEID']['0']['#']);
$resource_data = backup_getid($restore->backup_unique_code,"resource",$resource_old_id);
if (!empty($resource_data)) {
$listitem->resourceid = $resource_data->new_id;
$newid = insert_record('resourcelist_items', $listitem);
// Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
if ($newid) {
backup_putid($restore->backup_unique_code,"resourcelist_items",$oldid,$newid);
} else {
$status = false;
}
}
}
return $status;
}
/* function resourcelist_decode_content_links($content,$restore) { */
/* } */
/* function resourcelist_decode_content_links_caller($restore) { */
/* } */
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function resourcelist_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;
case "view":
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 "view all":
$log->url = "index.php?id=".$log->course;
$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;
}
?>