Permalink
Browse files

Begin restoring mods. Now they are readed and saved to db

(backup_ids) in serialized form.
  • Loading branch information...
1 parent 5f94815 commit e3df3ece17d9b40906f948a59c67f014e4a310fd stronk7 committed May 30, 2003
Showing with 118 additions and 2 deletions.
  1. +10 −0 backup/restore_execute.html
  2. +108 −2 backup/restorelib.php
@@ -156,6 +156,16 @@
}
}
+ //Now create course modules as needed
+ if ($status) {
+ echo "<li>Creating Course Modules";
+ $status = restore_create_modules($restore,$xml_file);
+ //If all is ok (and we have a counter)
+ if ($status and ($status !== true)) {
+ //Inform about modules restores
+ }
+ }
+
View
@@ -84,6 +84,16 @@ function restore_read_xml_users ($restore,$xml_file) {
return $info;
}
+ //This function read the xml file and store its data from the modules in
+ //backup_ids->info
+ function restore_read_xml_modules ($restore,$xml_file) {
+
+ //We call the main read_xml function, with todo = MODULES
+ $info = restore_read_xml ($xml_file,"MODULES",$restore);
+
+ return $info;
+ }
+
//This function prints the contents from the info parammeter passed
function restore_print_info ($info) {
@@ -421,7 +431,10 @@ function restore_create_users($restore,$xml_file) {
//For each, user, take its info from backup_ids
foreach ($info->users as $userid) {
$rec = backup_getid($restore->backup_unique_code,"user",$userid);
- $user = unserialize($rec->info);
+ //First strip slashes
+ $temp = stripslashes($rec->info);
+ //Now unserialize
+ $user = unserialize($temp);
//Calculate if it is a course user
//Has role teacher or student or admin or coursecreator
$is_course_user = ($user->roles[teacher] or $user->roles[student] or
@@ -631,6 +644,26 @@ function restore_course_files($restore) {
}
+ //This function creates all the structures for every module in backup file
+ //Depending what has been selected.
+ function restore_create_modules($restore,$xml_file) {
+
+ global $CFG;
+
+ $status = true;
+ //Check it exists
+ if (!file_exists($xml_file)) {
+ $status = false;
+ }
+ //Get info from xml
+ if ($status) {
+ //info will contain the old_id of every module
+ //in backup_ids->info will be the real info (serialized)
+ $info = restore_read_xml_modules($restore,$xml_file);
+ }
+
+ }
+
//=====================================================================================
//== ==
//== XML Functions (SAX) ==
@@ -697,6 +730,20 @@ function startElementUsers($parser, $tagName, $attrs) {
// echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br>\n"; //Debug
}
+ //This is the startTag handler we use where we are reading the modules zone (todo="MODULES")
+ function startElementModules($parser, $tagName, $attrs) {
+ //Refresh properties
+ $this->level++;
+ $this->tree[$this->level] = $tagName;
+ //Check if we are into MODULES zone
+ //if ($this->tree[3] == "MODULES") //Debug
+ // echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br>\n"; //Debug
+ //If we are under a MOD tag under a MODULES zone, accumule it
+ if (($this->tree[4] == "MOD") and ($this->tree[3] == "MODULES")) {
+ $this->info .= "<".$tagName.">";
+ }
+ }
+
//This is the startTag default handler we use when todo is undefined
function startElement($parser, $tagName, $attrs) {
$this->level++;
@@ -976,8 +1023,13 @@ function endElementUsers($parser, $tagName) {
switch ($tagName) {
case "USER":
//We've finalized a user, get it and save to db
+ //First serialize
+ $ser_temp = serialize($this->info->tempuser);
+ //Now add slashes
+ $sla_temp = addslashes($ser_temp);
+ //Save to db
backup_putid($this->preferences->backup_unique_code,"user",$this->info->tempuser->id,
- null,serialize($this->info->tempuser));
+ null,$sla_temp);
//Delete temp obejct
unset($this->info->tempuser);
break;
@@ -1141,6 +1193,57 @@ function endElementUsers($parser, $tagName) {
$this->content = "";
}
+ //This is the endTag handler we use where we are reading the modules zone (todo="MODULES")
+ function endElementModules($parser, $tagName) {
+ //Check if we are into MODULES zone
+ if ($this->tree[3] == "MODULES") {
+ //if (trim($this->content)) //Debug
+ // echo "C".str_repeat("&nbsp;",($this->level+2)*2).$this->getContents()."<br>\n"; //Debug
+ //echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;/".$tagName."&gt;<br>\n"; //Debug
+ //Acumulate data to info (content + close tag)
+ //Reconvert it to utf & htmlchars and trim to generate xml data
+ $this->info .= utf8_encode(htmlspecialchars(trim($this->content)))."</".$tagName.">";
+ //If we've finished a mod, xmlize it an save to db
+ if (($this->level == 4) and ($tagName == "MOD")) {
+ //Prepend XML standard header to info gathered
+ $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->info;
+ //Call to xmlize for this portion of xml data (one MOD)
+ $data = xmlize($xml_data);
+ //traverse_xmlize($data); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+ //Now, save data to db. We'll use it later
+ //Get id and modtype from data
+ $mod_id = $data["MOD"]["#"]["ID"]["0"]["#"];
+ $mod_type = $data["MOD"]["#"]["MODTYPE"]["0"]["#"];
+ //Serialize it
+ $mod_temp = serialize($data);
+ //Now add slashes
+ $sla_mod_temp = addslashes($mod_temp);
+ //Save to db
+ backup_putid($this->preferences->backup_unique_code,$mod_type,$mod_id,
+ null,$sla_mod_temp);
+ //Reset info to empty
+ $this->info = "";
+ }
+
+
+
+
+ }
+
+ //Stop parsing if todo = MODULES and tagName = MODULES (en of the tag, of course)
+ //Speed up a lot (avoid parse all)
+ if ($tagName == "MODULES" and $this->level == 3) {
+ $this->finished = true;
+ }
+
+ //Clear things
+ $this->tree[$this->level] = "";
+ $this->level--;
+ $this->content = "";
+ }
+
//This is the endTag default handler we use when todo is undefined
function endElement($parser, $tagName) {
if (trim($this->content)) //Debug
@@ -1182,6 +1285,9 @@ function restore_read_xml ($xml_file,$todo,$preferences) {
} else if ($todo == "USERS") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementUsers", "endElementUsers");
+ } else if ($todo == "MODULES") {
+ //Define handlers to that zone
+ xml_set_element_handler($xml_parser, "startElementModules", "endElementModules");
} else {
//Define default handlers (must no be invoked when everything become finished)
xml_set_element_handler($xml_parser, "startElementInfo", "endElementInfo");

0 comments on commit e3df3ec

Please sign in to comment.