2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the dialogue mod:
12 // dialogue_conversations
13 // (UL,pk->id, fk->dialogueid)
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) {
36 //Get record from backup_ids
37 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
40 //Now get completed xmlized object
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);
60 echo "<li>".get_string("modulename","dialogue")." \"".$dialogue->name
."\"</li>";
64 //We have the newid, update backup_ids
65 backup_putid($restore->backup_unique_code
,$mod->modtype
,
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);
83 //This function restores the dialogue_conversations
84 function dialogue_conversations_restore($old_dialogue_id, $new_dialogue_id,$info,$restore) {
90 //Get the entries array
91 $conversations = $info['MOD']['#']['CONVERSATIONS']['0']['#']['CONVERSATION'];
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
);
119 $conversation->userid
= $user->new_id
;
121 $user = backup_getid($restore->backup_unique_code
,"user",$conversation->recipientid
);
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);
130 if (($i+
1) %
50 == 0) {
132 if (($i+
1) %
1000 == 0) {
139 //We have the newid, update backup_ids
140 backup_putid($restore->backup_unique_code
, "dialogue_conversations",
142 //Now check if want to restore user data and do it.
144 //Restore dialogue_entries
145 $status = dialogue_entries_restore($new_dialogue_id, $newid,$conversation_info,
158 //This function restores the dialogue_entries
159 function dialogue_entries_restore($new_dialogue_id, $new_conversation_id,$info,$restore) {
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
);
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);
198 if (($i+
1) %
50 == 0) {
200 if (($i+
1) %
1000 == 0) {
207 //We have the newid, update backup_ids
208 backup_putid($restore->backup_unique_code
,"dialogue_entry",$oldid,