Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / label / restorelib.php
blobab6259955ec62d9cd4c63b623794a36d984cf2a9
1 <?php //$Id$
2 //This php script contains all the stuff to backup/restore
3 //label mods
5 //This is the "graphical" structure of the label mod:
6 //
7 // label
8 // (CL,pk->id)
9 //
10 // Meaning: pk->primary key field of the table
11 // fk->foreign key to link with parent
12 // nt->nested field (recursive data)
13 // CL->course level info
14 // UL->user level info
15 // files->table may have files)
17 //-----------------------------------------------------------
19 //This function executes all the restore procedure about this mod
20 function label_restore_mods($mod,$restore) {
22 global $CFG;
24 $status = true;
26 //Get record from backup_ids
27 $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
29 if ($data) {
30 //Now get completed xmlized object
31 $info = $data->info;
32 //traverse_xmlize($info); //Debug
33 //print_object ($GLOBALS['traverse_array']); //Debug
34 //$GLOBALS['traverse_array']=""; //Debug
36 //Now, build the LABEL record structure
37 $label->course = $restore->course_id;
38 $label->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
39 $label->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
40 $label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
42 //The structure is equal to the db, so insert the label
43 $newid = insert_record ("label",$label);
45 //Do some output
46 if (!defined('RESTORE_SILENTLY')) {
47 echo "<li>".get_string("modulename","label")." \"".format_string(stripslashes($label->name),true)."\"</li>";
49 backup_flush(300);
51 if ($newid) {
52 //We have the newid, update backup_ids
53 backup_putid($restore->backup_unique_code,$mod->modtype,
54 $mod->id, $newid);
56 } else {
57 $status = false;
59 } else {
60 $status = false;
63 return $status;
66 function label_decode_content_links_caller($restore) {
67 global $CFG;
68 $status = true;
70 if ($labels = get_records_sql ("SELECT l.id, l.content
71 FROM {$CFG->prefix}label l
72 WHERE l.course = $restore->course_id")) {
73 $i = 0; //Counter to send some output to the browser to avoid timeouts
74 foreach ($labels as $label) {
75 //Increment counter
76 $i++;
77 $content = $label->content;
78 $result = restore_decode_content_links_worker($content,$restore);
80 if ($result != $content) {
81 //Update record
82 $label->content = addslashes($result);
83 $status = update_record("label", $label);
84 if (debugging()) {
85 if (!defined('RESTORE_SILENTLY')) {
86 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
90 //Do some output
91 if (($i+1) % 5 == 0) {
92 if (!defined('RESTORE_SILENTLY')) {
93 echo ".";
94 if (($i+1) % 100 == 0) {
95 echo "<br />";
98 backup_flush(300);
102 return $status;
105 //This function returns a log record with all the necessay transformations
106 //done. It's used by restore_log_module() to restore modules log.
107 function label_restore_logs($restore,$log) {
109 $status = false;
111 //Depending of the action, we recode different things
112 switch ($log->action) {
113 case "add":
114 if ($log->cmid) {
115 //Get the new_id of the module (to recode the info field)
116 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
117 if ($mod) {
118 $log->url = "view.php?id=".$log->cmid;
119 $log->info = $mod->new_id;
120 $status = true;
123 break;
124 case "update":
125 if ($log->cmid) {
126 //Get the new_id of the module (to recode the info field)
127 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
128 if ($mod) {
129 $log->url = "view.php?id=".$log->cmid;
130 $log->info = $mod->new_id;
131 $status = true;
134 break;
135 default:
136 if (!defined('RESTORE_SILENTLY')) {
137 echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
139 break;
142 if ($status) {
143 $status = $log;
145 return $status;