Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / dialogue / restorelib.php
blob24133021b3e992c62c068e7e5afd5f78486f1a8e
1 <?php //$Id$
2 //This php script contains all the stuff to backup/restore
3 //dialogue mods
5 //This is the "graphical" structure of the dialogue mod:
6 //
7 // dialogue
8 // (CL,pk->id)
9 // |
10 // |
11 // |
12 // dialogue_conversations
13 // (UL,pk->id, fk->dialogueid)
14 // |
15 // |
16 // |
17 // dialogue_entries
18 // (UL,pk->id, fk->conversationid)
20 // Meaning: pk->primary key field of the table
21 // fk->foreign key to link with parent
22 // nt->nested field (recursive data)
23 // CL->course level info
24 // UL->user level info
25 // files->table may have files)
27 //-----------------------------------------------------------
29 //This function executes all the restore procedure about this mod
30 function dialogue_restore_mods($mod,$restore) {
32 global $CFG;
34 $status = true;
36 //Get record from backup_ids
37 $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
39 if ($data) {
40 //Now get completed xmlized object
41 $info = $data->info;
42 //traverse_xmlize($info); //Debug
43 //print_object ($GLOBALS['traverse_array']); //Debug
44 //$GLOBALS['traverse_array']=""; //Debug
46 //Now, build the dialogue record structure
47 $dialogue->course = $restore->course_id;
48 $dialogue->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
49 $dialogue->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
50 $dialogue->deleteafter = backup_todb($info['MOD']['#']['DELETEAFTER']['0']['#']);
51 $dialogue->dialoguetype = backup_todb($info['MOD']['#']['DIALOGUETYPE']['0']['#']);
52 $dialogue->multipleconversations = backup_todb($info['MOD']['#']['MULTIPLECONVERSATIONS']['0']['#']);
53 $dialogue->maildefault = backup_todb($info['MOD']['#']['MAILDEFAULT']['0']['#']);
54 $dialogue->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
56 //The structure is equal to the db, so insert the dialogue
57 $newid = insert_record ("dialogue",$dialogue);
59 //Do some output
60 echo "<li>".get_string("modulename","dialogue")." \"".$dialogue->name."\"</li>";
61 backup_flush(300);
63 if ($newid) {
64 //We have the newid, update backup_ids
65 backup_putid($restore->backup_unique_code,$mod->modtype,
66 $mod->id, $newid);
67 //Now check if want to restore user data and do it.
68 if ($restore->mods['dialogue']->userinfo) {
69 //Restore dialogue_conversations
70 $status = dialogue_conversations_restore($mod->id, $newid,$info,$restore);
72 } else {
73 $status = false;
75 } else {
76 $status = false;
79 return $status;
83 //This function restores the dialogue_conversations
84 function dialogue_conversations_restore($old_dialogue_id, $new_dialogue_id,$info,$restore) {
86 global $CFG;
88 $status = true;
90 //Get the entries array
91 $conversations = $info['MOD']['#']['CONVERSATIONS']['0']['#']['CONVERSATION'];
93 if ($conversations) {
94 //Iterate over conversations
95 for($i = 0; $i < sizeof($conversations); $i++) {
96 $conversation_info = $conversations[$i];
97 //traverse_xmlize($conversation_info); //Debug
98 //print_object ($GLOBALS['traverse_array']); //Debug
99 //$GLOBALS['traverse_array']=""; //Debug
101 //We'll need this later!!
102 $oldid = backup_todb($conversation_info['#']['ID']['0']['#']);
103 $olduserid = backup_todb($conversation_info['#']['USERID']['0']['#']);
105 //Now, build the dialogue_ENTRIES record structure
106 $conversation->dialogueid = $new_dialogue_id;
107 $conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']);
108 $conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']);
109 $conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']);
110 $conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']);
111 $conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']);
112 $conversation->seenon = backup_todb($conversation_info['#']['SEENON']['0']['#']);
113 $conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']);
114 $conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']);
115 $conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']);
116 //We have to recode the userid and recipientid fields
117 $user = backup_getid($restore->backup_unique_code,"user",$conversation->userid);
118 if ($user) {
119 $conversation->userid = $user->new_id;
121 $user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid);
122 if ($user) {
123 $conversation->recipientid = $user->new_id;
126 //The structure is equal to the db, so insert the dialogue_conversation
127 $newid = insert_record ("dialogue_conversations",$conversation);
129 //Do some output
130 if (($i+1) % 50 == 0) {
131 echo ".";
132 if (($i+1) % 1000 == 0) {
133 echo "<br />";
135 backup_flush(300);
138 if ($newid) {
139 //We have the newid, update backup_ids
140 backup_putid($restore->backup_unique_code, "dialogue_conversations",
141 $oldid, $newid);
142 //Now check if want to restore user data and do it.
143 if ($status) {
144 //Restore dialogue_entries
145 $status = dialogue_entries_restore($new_dialogue_id, $newid,$conversation_info,
146 $restore);
148 } else {
149 $status = false;
155 return $status;
158 //This function restores the dialogue_entries
159 function dialogue_entries_restore($new_dialogue_id, $new_conversation_id,$info,$restore) {
161 global $CFG;
163 $status = true;
165 //Get the entries array
166 if (isset($info['#']['ENTRIES']['0']['#']['ENTRY'])) {
167 $entries = $info['#']['ENTRIES']['0']['#']['ENTRY'];
169 //Iterate over entries
170 for($i = 0; $i < sizeof($entries); $i++) {
171 $entry_info = $entries[$i];
172 //traverse_xmlize($entry_info); //Debug
173 //print_object ($GLOBALS['traverse_array']); //Debug
174 //$GLOBALS['traverse_array']=""; //Debug
176 //We'll need this later!!
177 $oldid = backup_todb($entry_info['#']['ID']['0']['#']);
178 $olduserid = backup_todb($entry_info['#']['USERID']['0']['#']);
180 //Now, build the dialogue_ENTRIES record structure
181 $entry->dialogueid = $new_dialogue_id;
182 $entry->conversationid = $new_conversation_id;
183 $entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']);
184 $entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']);
185 $entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']);
186 $entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']);
188 //We have to recode the userid field
189 $user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
190 if ($user) {
191 $entry->userid = $user->new_id;
194 //The structure is equal to the db, so insert the dialogue_entry
195 $newid = insert_record ("dialogue_entries",$entry);
197 //Do some output
198 if (($i+1) % 50 == 0) {
199 echo ".";
200 if (($i+1) % 1000 == 0) {
201 echo "<br />";
203 backup_flush(300);
206 if ($newid) {
207 //We have the newid, update backup_ids
208 backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid,
209 $newid);
210 } else {
211 $status = false;
216 return $status;