Skip to content
Browse files

Scales are now supported in backup/restore.

Updated version to 0.8.8 alpha. Please test.
  • Loading branch information...
1 parent e38411a commit 42f1ff47b441a43a7ef336ad6e03d27f1505f62d stronk7 committed Aug 18, 2003
Showing with 234 additions and 8 deletions.
  1. +3 −3 backup/STATUS.txt
  2. +6 −0 backup/backup_execute.html
  3. +42 −0 backup/backuplib.php
  4. +6 −0 backup/restore_execute.html
  5. +175 −3 backup/restorelib.php
  6. +2 −2 backup/version.php
View
6 backup/STATUS.txt
@@ -3,7 +3,7 @@ STATUS $Id$
This documment shows the current status of the backup/restore option.
-Backup: WORKING. COMPLETED except workshops and scales.
+Backup: WORKING. COMPLETED except workshops.
Restore: WORKING. COMPLETED except workshops, logs and scales.
@@ -48,7 +48,7 @@ Backup Details:
- Course.......................................DONE
- All..........................................DONE
- Logs...............................................DONE
- - Scales.............................................IN PROGRESS
+ - Scales.............................................DONE
- Categories and Questions.(STEP 1)..................DONE
+ categories......................................DONE
+ questions structure.............................DONE
@@ -155,6 +155,7 @@ Restore Details:
- Categories and Questions.(STEP 1)..................DONE
+ categories......................................DONE
+ questions structure.............................DONE
+ - Scales.............................................DONE
- Mods Info Prepare..................................DONE
x read modules zone...............................DONE
x separate every mod..............................DONE
@@ -200,7 +201,6 @@ Restore Details:
- User files from temp.......................................DONE
- Course files from temp.....................................DONE
- Log entries................................................NO EXISTS
- - Scales.....................................................IN PROGRESS
- Readjust instance in course_modules........................DONE
- Readjust modinfo in course (serialize).....................DONE
- Delete old entries at restore end. .......................DONE
View
6 backup/backup_execute.html
@@ -192,6 +192,12 @@
}
}
+ //Print scales info
+ if ($status) {
+ echo "<li>".get_string("writingscalesinfo");
+ $status = backup_scales_info($backup_file,$preferences);
+ }
+
//Module info, this unique function makes all the work!!
//db export and module fileis copy
if ($status) {
View
42 backup/backuplib.php
@@ -757,6 +757,48 @@ function backup_log_info($bf,$preferences) {
return $status;
}
+
+ //Backup scales info (common and course scales)
+ function backup_scales_info($bf,$preferences) {
+
+ global $CFG;
+
+ $status = true;
+
+ //Counter, points to current record
+ $counter = 0;
+
+ //Get scales (common and course scales)
+ $scales = get_records_sql("SELECT id, courseid, userid, name, scale, description, timemodified
+ FROM {$CFG->prefix}scale
+ WHERE courseid = '0' or courseid = $preferences->backup_course");
+
+ //Pring scales header
+ if ($scales) {
+ //Pring scales header
+ fwrite ($bf,start_tag("SCALES",2,true));
+ //Iterate
+ foreach ($scales as $scale) {
+ //Begin scale tag
+ fwrite ($bf,start_tag("SCALE",3,true));
+ //Output scale tag
+ fwrite ($bf,full_tag("ID",4,false,$scale->id));
+ fwrite ($bf,full_tag("COURSEID",4,false,$scale->courseid));
+ fwrite ($bf,full_tag("USERID",4,false,$scale->userid));
+ fwrite ($bf,full_tag("NAME",4,false,$scale->name));
+ fwrite ($bf,full_tag("SCALETEXT",4,false,$scale->scale));
+ fwrite ($bf,full_tag("DESCRIPTION",4,false,$scale->description));
+ fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$scale->timemodified));
+ //End scale tag
+ fwrite ($bf,end_tag("SCALE",3,true));
+ }
+ //End scales tag
+ $status = fwrite ($bf,end_tag("SCALES",2,true));
+ }
+ return $status;
+ }
+
+
//Start the modules tag
function backup_modules_start ($bf,$preferences) {
View
6 backup/restore_execute.html
@@ -216,6 +216,12 @@
}
}
+ //Now create scales as needed
+ if ($status) {
+ echo "<li>".get_string("creatingscales");
+ $status = restore_create_scales($restore,$xml_file);
+ }
+
//Now create course modules as needed
if ($status) {
echo "<li>".get_string("creatingcoursemodules");
View
178 backup/restorelib.php
@@ -94,6 +94,16 @@ function restore_read_xml_questions ($restore,$xml_file) {
return $info;
}
+ //This function read the xml file and store its data from the scales in
+ //backup_ids->info db (and scale's id in $info)
+ function restore_read_xml_scales ($restore,$xml_file) {
+
+ //We call the main read_xml function, with todo = SCALES
+ $info = restore_read_xml ($xml_file,"SCALES",$restore);
+
+ 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) {
@@ -621,6 +631,95 @@ function restore_create_questions($restore,$xml_file) {
return $status;
}
+ //This function creates all the scales
+ function restore_create_scales($restore,$xml_file) {
+
+ global $CFG, $db;
+
+ $status = true;
+ //Check it exists
+ if (!file_exists($xml_file)) {
+ $status = false;
+ }
+ //Get info from xml
+ if ($status) {
+ //scales will contain the old_id of every scale
+ //in backup_ids->info will be the real info (serialized)
+ $scales = restore_read_xml_scales($restore,$xml_file);
+ }
+ //Now, if we have anything in scales, we have to restore that
+ //scales
+ if ($scales) {
+ if ($scales !== true) {
+ //Iterate over each scale
+ foreach ($scales as $scale) {
+ //Get record from backup_ids
+ $data = backup_getid($restore->backup_unique_code,"scale",$scale->id);
+ //Init variables
+ $create_scale = false;
+
+ if ($data) {
+ //Now get completed xmlized object
+ $info = $data->info;
+ //traverse_xmlize($info); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+
+ //Now build the SCALE record structure
+ $sca->id = backup_todb($info['SCALE']['#']['ID']['0']['#']);
+ $sca->courseid = backup_todb($info['SCALE']['#']['COURSEID']['0']['#']);
+ $sca->userid = backup_todb($info['SCALE']['#']['USERID']['0']['#']);
+ $sca->name = backup_todb($info['SCALE']['#']['NAME']['0']['#']);
+ $sca->scale = backup_todb($info['SCALE']['#']['SCALETEXT']['0']['#']);
+ $sca->description = backup_todb($info['SCALE']['#']['DESCRIPTION']['0']['#']);
+ $sca->timemodified = backup_todb($info['SCALE']['#']['TIMEMODIFIED']['0']['#']);
+
+ //Now search if that scale exists (by scale field)
+ $sca_db = get_record("scale","scale",$sca->scale);
+ //If it doesn't exist, create
+ if (!$sca_db) {
+ $create_scale = true;
+ } else {
+ //Exists. If the courseid in db is <> 0 and <> current course,
+ //we must create the scale too
+ if ($sca_db->courseid != 0 and $sca_db->courseid != $restore->course_id) {
+ $create_scale = true;
+ }
+ }
+ //If we must create the scale
+ if ($create_scale) {
+ //Me must recode the courseid if it's <> 0 (common scale)
+ if ($sca->courseid != 0) {
+ $sca->courseid = $restore->course_id;
+ }
+ //We must recode the userid
+ $user = backup_getid($restore->backup_unique_code,"user",$sca->userid);
+ if ($user) {
+ $sca->userid = $user->new_id;
+ } else {
+ //Assign it to admin
+ $sca->userid = 1;
+ }
+ //The structure is equal to the db, so insert the scale
+ $newid = insert_record ("scale",$sca);
+ } else {
+ //get current scale id
+ $newid = $sca_db->id;
+ }
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code,"scale",
+ $scale->id, $newid);
+ }
+ }
+ }
+ }
+ } else {
+ $status = false;
+ }
+ return $status;
+ }
+
//This function restores the userfiles from the temp (user_files) directory to the
//dataroot/users directory
function restore_user_files($restore) {
@@ -918,6 +1017,29 @@ function startElementQuestions($parser, $tagName, $attrs) {
}
}
+ //This is the startTag handler we use where we are reading the scales zone (todo="SCALES")
+ function startElementScales($parser, $tagName, $attrs) {
+ //Refresh properties
+ $this->level++;
+ $this->tree[$this->level] = $tagName;
+
+ //if ($tagName == "SCALE" && $this->tree[3] == "SCALES") { //Debug
+ // echo "<P>SCALE: ".strftime ("%X",time()),"-"; //Debug
+ //} //Debug
+
+ //Output something to avoid browser timeouts...
+ backup_flush();
+
+ //Check if we are into SCALES zone
+ //if ($this->tree[3] == "SCALES") //Debug
+ // echo $this->level.str_repeat("&nbsp;",$this->level*2)."&lt;".$tagName."&gt;<br>\n"; //Debug
+
+ //If we are under a SCALE tag under a SCALES zone, accumule it
+ if (($this->tree[4] == "SCALE") and ($this->tree[3] == "SCALES")) {
+ $this->temp .= "<".$tagName.">";
+ }
+ }
+
//This is the startTag handler we use where we are reading the modules zone (todo="MODULES")
function startElementModules($parser, $tagName, $attrs) {
//Refresh properties
@@ -1415,7 +1537,7 @@ function endElementUsers($parser, $tagName) {
$this->content = "";
}
- //This is the endTag handler we use where we are reading the modules zone (todo="QUESTIONS")
+ //This is the endTag handler we use where we are reading the questions zone (todo="QUESTIONS")
function endElementQuestions($parser, $tagName) {
//Check if we are into QUESTION_CATEGORIES zone
if ($this->tree[3] == "QUESTION_CATEGORIES") {
@@ -1429,15 +1551,15 @@ function endElementQuestions($parser, $tagName) {
if (($this->level == 4) and ($tagName == "QUESTION_CATEGORY")) {
//Prepend XML standard header to info gathered
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
- //Call to xmlize for this portion of xml data (one MOD)
+ //Call to xmlize for this portion of xml data (one QUESTION_CATEGORY)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize($xml_data,0);
//echo strftime ("%X",time())."<p>"; //Debug
//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
+ //Get id from data
$category_id = $data["QUESTION_CATEGORY"]["#"]["ID"]["0"]["#"];
//Save to db
$status = backup_putid($this->preferences->backup_unique_code,"quiz_categories",$category_id,
@@ -1462,6 +1584,53 @@ function endElementQuestions($parser, $tagName) {
$this->content = "";
}
+ //This is the endTag handler we use where we are reading the scales zone (todo="SCALES")
+ function endElementScales($parser, $tagName) {
+ //Check if we are into SCALES zone
+ if ($this->tree[3] == "SCALES") {
+ //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: strip htmlchars again and trim to generate xml data
+ $this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";
+ //If we've finished a scale, xmlize it an save to db
+ if (($this->level == 4) and ($tagName == "SCALE")) {
+ //Prepend XML standard header to info gathered
+ $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
+ //Call to xmlize for this portion of xml data (one SCALE)
+ //echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
+ $data = xmlize($xml_data,0);
+ //echo strftime ("%X",time())."<p>"; //Debug
+ //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 from data
+ $scale_id = $data["SCALE"]["#"]["ID"]["0"]["#"];
+ //Save to db
+ $status = backup_putid($this->preferences->backup_unique_code,"scale",$scale_id,
+ null,$data);
+ //Create returning info
+ $ret_info->id = $scale_id;
+ $this->info[] = $ret_info;
+ //Reset temp
+ unset($this->temp);
+ }
+ }
+
+ //Stop parsing if todo = SCALES and tagName = SCALE (en of the tag, of course)
+ //Speed up a lot (avoid parse all)
+ if ($tagName == "SCALES" and $this->level == 3) {
+ $this->finished = true;
+ }
+
+ //Clear things
+ $this->tree[$this->level] = "";
+ $this->level--;
+ $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
@@ -1559,6 +1728,9 @@ function restore_read_xml ($xml_file,$todo,$preferences) {
} else if ($todo == "QUESTIONS") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementQuestions", "endElementQuestions");
+ } else if ($todo == "SCALES") {
+ //Define handlers to that zone
+ xml_set_element_handler($xml_parser, "startElementScales", "endElementScales");
} else if ($todo == "MODULES") {
//Define handlers to that zone
xml_set_element_handler($xml_parser, "startElementModules", "endElementModules");
View
4 backup/version.php
@@ -5,6 +5,6 @@
// database (backup_version) to determine whether upgrades should
// be performed (see db/backup_*.php)
-$backup_version = 2003081500; // The current version is a date (YYYYMMDDXX)
+$backup_version = 2003081800; // The current version is a date (YYYYMMDDXX)
-$backup_release = "0.8.7 alpha"; // User-friendly version number
+$backup_release = "0.8.8 alpha"; // User-friendly version number

0 comments on commit 42f1ff4

Please sign in to comment.
Something went wrong with that request. Please try again.