2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the journal mod:
13 // (UL,pk->id, fk->journal)
15 // Meaning: pk->primary key field of the table
16 // fk->foreign key to link with parent
17 // nt->nested field (recursive data)
18 // CL->course level info
19 // UL->user level info
20 // files->table may have files)
22 //-----------------------------------------------------------
24 //This function executes all the restore procedure about this mod
25 function journal_restore_mods($mod,$restore) {
31 //Get record from backup_ids
32 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
35 //Now get completed xmlized object
37 //if necessary, write to restorelog and adjust date/time fields
38 if ($restore->course_startdateoffset
) {
39 restore_log_date_changes('Journal', $restore, $info['MOD']['#'], array('TIMEMODIFIED'));
41 //traverse_xmlize($info); //Debug
42 //print_object ($GLOBALS['traverse_array']); //Debug
43 //$GLOBALS['traverse_array']=""; //Debug
45 //Now, build the JOURNAL record structure
46 $journal->course
= $restore->course_id
;
47 $journal->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
48 $journal->intro
= backup_todb($info['MOD']['#']['INTRO']['0']['#']);
49 $journal->introformat
= backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
50 $journal->days
= backup_todb($info['MOD']['#']['DAYS']['0']['#']);
51 $journal->assessed
= backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
52 $journal->timemodified
= backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
54 //We have to recode the assessed field if it is <0 (scale)
55 if ($journal->assessed
< 0) {
56 $scale = backup_getid($restore->backup_unique_code
,"scale",abs($journal->assessed
));
58 $journal->assessed
= -($scale->new_id
);
62 //The structure is equal to the db, so insert the journal
63 $newid = insert_record ("journal",$journal);
66 if (!defined('RESTORE_SILENTLY')) {
67 echo "<li>".get_string("modulename","journal")." \"".format_string(stripslashes($journal->name
),true)."\"</li>";
72 //We have the newid, update backup_ids
73 backup_putid($restore->backup_unique_code
,$mod->modtype
,
75 //Now check if want to restore user data and do it.
76 if (restore_userdata_selected($restore,'journal',$mod->id
)) {
77 //Restore journal_entries
78 $status = journal_entries_restore_mods ($mod->id
, $newid,$info,$restore);
91 //This function restores the journal_entries
92 function journal_entries_restore_mods($old_journal_id, $new_journal_id,$info,$restore) {
98 //Get the entries array
99 $entries = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'];
101 //Iterate over entries
102 for($i = 0; $i < sizeof($entries); $i++
) {
103 $entry_info = $entries[$i];
104 //traverse_xmlize($entry_info); //Debug
105 //print_object ($GLOBALS['traverse_array']); //Debug
106 //$GLOBALS['traverse_array']=""; //Debug
108 //We'll need this later!! $sub_info changed to $entry_info
109 $oldid = backup_todb($entry_info['#']['ID']['0']['#']);
110 $olduserid = backup_todb($entry_info['#']['USERID']['0']['#']);
112 //Now, build the JOURNAL_ENTRIES record structure
113 $entry->journal
= $new_journal_id;
114 $entry->userid
= backup_todb($entry_info['#']['USERID']['0']['#']);
115 $entry->modified
= backup_todb($entry_info['#']['MODIFIED']['0']['#']);
116 $entry->modified +
= $restore->course_startdateoffset
;
117 $entry->text
= backup_todb($entry_info['#']['TEXT']['0']['#']);
118 $entry->format
= backup_todb($entry_info['#']['FORMAT']['0']['#']);
119 $entry->rating
= backup_todb($entry_info['#']['RATING']['0']['#']);
120 if (isset($entry_info['#']['COMMENT']['0']['#'])) {
121 $entry->entrycomment
= backup_todb($entry_info['#']['COMMENT']['0']['#']);
123 $entry->entrycomment
= backup_todb($entry_info['#']['ENTRYCOMMENT']['0']['#']);
125 $entry->teacher
= backup_todb($entry_info['#']['TEACHER']['0']['#']);
126 $entry->timemarked
= backup_todb($entry_info['#']['TIMEMARKED']['0']['#']);
127 $entry->timemarked +
= $restore->course_startdateoffset
;
128 $entry->mailed
= backup_todb($entry_info['#']['MAILED']['0']['#']);
130 //We have to recode the userid field
131 $user = backup_getid($restore->backup_unique_code
,"user",$entry->userid
);
133 $entry->userid
= $user->new_id
;
136 //We have to recode the teacher field
137 $user = backup_getid($restore->backup_unique_code
,"user",$entry->teacher
);
139 $entry->teacher
= $user->new_id
;
142 //The structure is equal to the db, so insert the journal_entry
143 $newid = insert_record ("journal_entries",$entry);
146 if (($i+
1) %
50 == 0) {
147 if (!defined('RESTORE_SILENTLY')) {
149 if (($i+
1) %
1000 == 0) {
157 //We have the newid, update backup_ids
158 backup_putid($restore->backup_unique_code
,"journal_entry",$oldid,
168 //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
169 //some texts in the module
170 function journal_restore_wiki2markdown ($restore) {
176 //Convert journal_entries->text
177 if ($records = get_records_sql ("SELECT e.id, e.text, e.format
178 FROM {$CFG->prefix}journal_entries e,
179 {$CFG->prefix}journal j,
180 {$CFG->prefix}backup_ids b
181 WHERE j.id = e.journal AND
182 j.course = $restore->course_id AND
183 e.format = ".FORMAT_WIKI
. " AND
184 b.backup_code = $restore->backup_unique_code AND
185 b.table_name = 'journal_entries' AND
187 foreach ($records as $record) {
189 $record->text
= restore_decode_wiki_content($record->text
, $restore);
190 //Convert to Markdown
191 $wtm = new WikiToMarkdown();
192 $record->text
= $wtm->convert($record->text
, $restore->course_id
);
193 $record->format
= FORMAT_MARKDOWN
;
194 $status = update_record('journal_entries', addslashes_object($record));
197 if (($i+
1) %
1 == 0) {
198 if (!defined('RESTORE_SILENTLY')) {
200 if (($i+
1) %
20 == 0) {
210 //Convert journal->intro
211 if ($records = get_records_sql ("SELECT j.id, j.intro, j.introformat
212 FROM {$CFG->prefix}journal j,
213 {$CFG->prefix}backup_ids b
214 WHERE j.course = $restore->course_id AND
215 j.introformat = ".FORMAT_WIKI
. " AND
216 b.backup_code = $restore->backup_unique_code AND
217 b.table_name = 'journal' AND
219 foreach ($records as $record) {
221 $record->intro
= restore_decode_wiki_content($record->intro
, $restore);
222 //Convert to Markdown
223 $wtm = new WikiToMarkdown();
224 $record->intro
= $wtm->convert($record->intro
, $restore->course_id
);
225 $record->introformat
= FORMAT_MARKDOWN
;
226 $status = update_record('journal', addslashes_object($record));
229 if (($i+
1) %
1 == 0) {
230 if (!defined('RESTORE_SILENTLY')) {
232 if (($i+
1) %
20 == 0) {
245 //This function returns a log record with all the necessay transformations
246 //done. It's used by restore_log_module() to restore modules log.
247 function journal_restore_logs($restore,$log) {
251 //Depending of the action, we recode different things
252 switch ($log->action
) {
255 //Get the new_id of the module (to recode the info field)
256 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
258 $log->url
= "view.php?id=".$log->cmid
;
259 $log->info
= $mod->new_id
;
266 //Get the new_id of the module (to recode the info field)
267 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
269 $log->url
= "view.php?id=".$log->cmid
;
270 $log->info
= $mod->new_id
;
277 //Get the new_id of the module (to recode the info field)
278 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
280 $log->url
= "view.php?id=".$log->cmid
;
281 $log->info
= $mod->new_id
;
288 //Get the new_id of the module (to recode the info field)
289 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
291 $log->url
= "view.php?id=".$log->cmid
;
292 $log->info
= $mod->new_id
;
299 //Get the new_id of the module (to recode the info field)
300 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
302 $log->url
= "view.php?id=".$log->cmid
;
303 $log->info
= $mod->new_id
;
308 case "view responses":
310 //Get the new_id of the module (to recode the info field)
311 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
313 $log->url
= "report.php?id=".$log->cmid
;
314 $log->info
= $mod->new_id
;
319 case "update feedback":
321 $log->url
= "report.php?id=".$log->cmid
;
326 $log->url
= "index.php?id=".$log->course
;
330 if (!defined('RESTORE_SILENTLY')) {
331 echo "action (".$log->module
."-".$log->action
.") unknown. Not restored<br />"; //Debug