]> git.mjollnir.org Git - moodle.git/commitdiff
Reading more info...
authorstronk7 <stronk7>
Sat, 17 May 2003 11:40:27 +0000 (11:40 +0000)
committerstronk7 <stronk7>
Sat, 17 May 2003 11:40:27 +0000 (11:40 +0000)
backup/restore_precheck.html
backup/restorelib.php

index 8060138aa1aff7b316ca1ba88530bb3aa5047233..e038cb0a31625dda34881a704096c0f1a51dbc86 100644 (file)
@@ -69,6 +69,7 @@
         echo "<li>Reading info from file";
         //Reading info from file
         $info = restore_read_xml_info ($xml_file);
+        print_object ($info);
     }
 
     //End the main ul
index d6c9c4577aa6edf4b0ed2d1055e24e4b6f46a404..3e7fca7e8d6a1919a584f646880fea61c5b01733 100644 (file)
@@ -54,8 +54,6 @@
         $info = restore_read_xml ($xml_file,"INFO",false);
 
         return $info;
-
-        echo "finished";
     }
 
     //=====================================================================================
         var $tree = array();   //Array of levels we are
         var $content = "";     //Content under current level
         var $todo = "";        //What we hav to do when parsing
-        var $info = array();   //Information collected (todo = INFO)
+        var $info = "";        //Information collected. Temp storage.
         var $preferences = ""; //Preferences about what to load !!
         var $finished = false; //Flag to say xml_parse to stop
+        //This is the startTag handler we use where we are reading the info zone (todo="INFO")
+        function startElementInfo($parser, $tagName, $attrs) {
+            //Refresh properties
+            $this->level++;
+            $this->tree[$this->level] = $tagName;
+
+            //Check if we are into INFO zone
+            //if ($this->tree[2] == "INFO")                                                             //Debug
+            //    echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br>\n";   //Debug
+        }
 
+        //This is the startTag default handler we use when todo is undefined
         function startElement($parser, $tagName, $attrs) {
             $this->level++;
             $this->tree[$this->level] = $tagName;
             echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br>\n";   //Debug
         }
+        //This is the endTag handler we use where we are reading the info zone (todo="INFO")
+        function endElementInfo($parser, $tagName) {
+            //Check if we are into INFO zone
+            if ($this->tree[2] == "INFO") {
+                //if (trim($this->content))                                                                     //Debug
+                //    echo "C".utf8_decode(str_repeat("&nbsp;",($this->level+2)*2).$this->content."<br>\n");    //Debug
+                //echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;/".$tagName."&gt;<br>\n";          //Debug
+                //Dependig of different combinations, do different things
+                if ($this->level == 3) {
+                    switch ($tagName) {
+                        case "NAME":
+                            $this->info->backup_name = trim($this->content);
+                            break;
+                        case "MOODLE_VERSION":
+                            $this->info->backup_moodle_version = trim($this->content);
+                            break;
+                        case "MOODLE_RELEASE":
+                            $this->info->backup_moodle_release = trim($this->content);
+                            break;
+                        case "BACKUP_VERSION":
+                            $this->info->backup_backup_version = trim($this->content);
+                            break;
+                        case "BACKUP_RELEASE":
+                            $this->info->backup_backup_release = trim($this->content);
+                            break;
+                        case "DATE":
+                            $this->info->backup_date = trim($this->content);
+                            break;
+                    }
+                }
+                if ($this->tree[3] == "DETAILS") {
+                    if ($this->level == 4) {
+                        switch ($tagName) {
+                            case "USERS":
+                                $this->info->backup_users = trim($this->content);
+                                break;
+                            case "LOGS":
+                                $this->info->backup_logs = trim($this->content);
+                                break;
+                            case "USERFILES":
+                                $this->info->backup_user_files = trim($this->content);
+                                break;
+                            case "COURSEFILES":
+                                $this->info->backup_course_files = trim($this->content);
+                                break;
+                        }
+                    }
+                    if ($this->level == 5) {
+                        switch ($tagName) {
+                            case "NAME":
+                                $this->info->tempName = trim($this->content);
+                                break;
+                            case "INCLUDED":
+                                $this->info->mods[$this->info->tempName] = trim($this->content);
+                                break;
+                        }
+                    }
+                }
+
 
+                //Clear things
+                $this->tree[$this->level] = "";
+                $this->level--;
+                $this->content = "";
+            }
+
+            //Stop parsing if todo = INFO and tagName = INFO (en of the tag, of course)
+            //Speed up a lot (avoid parse all)
+            if ($tagName == "INFO") {
+                $this->finished = true;
+            }
+        }
+
+        //This is the endTag default handler we use when todo is undefined
         function endElement($parser, $tagName) {
             if (trim($this->content))                                                                     //Debug
                 echo "C".utf8_decode(str_repeat("&nbsp;",($this->level+2)*2).$this->content."<br>\n");    //Debug
             echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;/".$tagName."&gt;<br>\n";          //Debug
-            $this->level--;
+
+            //Clear things
             $this->tree[$this->level] = "";
+            $this->level--;
             $this->content = "";
-
-            //Stop parsing if todo = INFO and tagName = INFO (en of the tag, of course)
-            //Speed up a lot (avoid parse all)
-            if (($this->todo == "INFO") and ($tagName == "INFO")) {
-                $this->finished = true;
-            }
         }
 
+        //This is the handler to read data contents (simple accumule it)
         function characterData($parser, $data) {
             $this->content .= $data;
         }
     
     //This function executes the MoodleParser
     function restore_read_xml ($xml_file,$todo,$preferences) {
-
+        
         $status = true;
 
         $xml_parser = xml_parser_create();
         $moodle_parser->todo = $todo;
         $moodle_parser->preferences = $preferences;
         xml_set_object($xml_parser,&$moodle_parser);
-        xml_set_element_handler($xml_parser, "startElement", "endElement");
+        //Depending of the todo we use some element_handler or another
+        if ($todo == "INFO") {
+            //Define handlers to that zone
+            xml_set_element_handler($xml_parser, "startElementInfo", "endElementInfo");
+        } else {
+            //Define default handlers (must no be invoked when everything become finished)
+            xml_set_element_handler($xml_parser, "startElementInfo", "endElementInfo");
+        }
         xml_set_character_data_handler($xml_parser, "characterData");
         $fp = fopen($xml_file,"r")
             or $status = false;
         //Clear parser mem
         xml_parser_free($xml_parser);
 
-        if ($Status) {
+        if ($status) {
             return $info;
         } else {
             return $status;