Some important changes:
- Now course events are supported in backup & restore.
- in manual backups
- in scheduled backups
- Fixed important bug when restoring groups.
- Added support to the "user change password" action
(with some changes done in login/change_password.php)
Please, test it !!!!
This commit is contained in:
+3
-1
@@ -5,7 +5,7 @@ This documment shows the current status of the backup/restore option.
|
||||
|
||||
Backup: WORKING. COMPLETED !!
|
||||
|
||||
Restore: WORKING. COMPLETED except events and some (forums and lessons)
|
||||
Restore: WORKING. COMPLETED except some (forums and lessons)
|
||||
logs restore (the rest should be working).
|
||||
|
||||
========== ========== ========== ========== ========== ==========
|
||||
@@ -49,6 +49,7 @@ Backup Details:
|
||||
- All..........................................DONE
|
||||
- Logs...............................................DONE
|
||||
- Scales.............................................DONE
|
||||
- Events.(course)....................................DONE
|
||||
- Groups.............................................DONE
|
||||
- Categories and Questions.(STEP 1)..................DONE
|
||||
+ categories......................................DONE
|
||||
@@ -178,6 +179,7 @@ Restore Details:
|
||||
+ categories......................................DONE
|
||||
+ questions structure.............................DONE
|
||||
- Scales.............................................DONE
|
||||
- Events.(course)....................................DONE
|
||||
- Groups.............................................DONE
|
||||
- Mods Info Prepare..................................DONE
|
||||
x read modules zone...............................DONE
|
||||
|
||||
@@ -220,6 +220,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
//Print events info
|
||||
if ($status) {
|
||||
echo "<li>".get_string("writingeventsinfo");
|
||||
if (!$status = backup_events_info($backup_file,$preferences)) {
|
||||
notify("An error occurred while backing up events");
|
||||
}
|
||||
}
|
||||
|
||||
//Module info, this unique function makes all the work!!
|
||||
//db export and module fileis copy
|
||||
if ($status) {
|
||||
|
||||
@@ -527,13 +527,19 @@ function schedule_backup_course_execute($preferences,$starttime = 0) {
|
||||
schedule_backup_log($starttime,$preferences->backup_course," scales");
|
||||
$status = backup_scales_info($backup_file,$preferences);
|
||||
}
|
||||
|
||||
|
||||
//Print groups info
|
||||
if ($status) {
|
||||
schedule_backup_log($starttime,$preferences->backup_course," groups");
|
||||
$status = backup_groups_info($backup_file,$preferences);
|
||||
}
|
||||
|
||||
//Print events info
|
||||
if ($status) {
|
||||
schedule_backup_log($starttime,$preferences->backup_course," events");
|
||||
$status = backup_events_info($backup_file,$preferences);
|
||||
}
|
||||
|
||||
//Module info, this unique function makes all the work!!
|
||||
//db export and module fileis copy
|
||||
if ($status) {
|
||||
|
||||
@@ -961,6 +961,46 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup events info (course events)
|
||||
function backup_events_info($bf,$preferences) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Counter, points to current record
|
||||
$counter = 0;
|
||||
|
||||
//Get events (course events)
|
||||
$events = get_records_select("event","courseid='$preferences->backup_course' AND instance='0'","id");
|
||||
|
||||
//Pring events header
|
||||
if ($events) {
|
||||
//Pring events header
|
||||
fwrite ($bf,start_tag("EVENTS",2,true));
|
||||
//Iterate
|
||||
foreach ($events as $event) {
|
||||
//Begin event tag
|
||||
fwrite ($bf,start_tag("EVENT",3,true));
|
||||
//Output event tag
|
||||
fwrite ($bf,full_tag("ID",4,false,$event->id));
|
||||
fwrite ($bf,full_tag("NAME",4,false,$event->name));
|
||||
fwrite ($bf,full_tag("DESCRIPTION",4,false,$event->description));
|
||||
fwrite ($bf,full_tag("GROUPID",4,false,$event->groupid));
|
||||
fwrite ($bf,full_tag("USERID",4,false,$event->userid));
|
||||
fwrite ($bf,full_tag("EVENTTYPE",4,false,$event->eventtype));
|
||||
fwrite ($bf,full_tag("TIMESTART",4,false,$event->timestart));
|
||||
fwrite ($bf,full_tag("TIMEDURATION",4,false,$event->timeduration));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$event->timemodified));
|
||||
//End event tag
|
||||
fwrite ($bf,end_tag("EVENT",3,true));
|
||||
}
|
||||
//End events tag
|
||||
$status = fwrite ($bf,end_tag("EVENTS",2,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup groups info
|
||||
function backup_groups_info($bf,$preferences) {
|
||||
|
||||
|
||||
@@ -235,6 +235,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
//Now create events as needed
|
||||
if ($status) {
|
||||
echo "<li>".get_string("creatingevents");
|
||||
if (!$status = restore_create_events($restore,$xml_file)) {
|
||||
notify("Could not restore course events!");
|
||||
}
|
||||
}
|
||||
|
||||
//Now create course modules as needed
|
||||
if ($status) {
|
||||
echo "<li>".get_string("creatingcoursemodules");
|
||||
|
||||
+189
-1
@@ -119,6 +119,16 @@
|
||||
return $info;
|
||||
}
|
||||
|
||||
//This function read the xml file and store its data from the events (course) in
|
||||
//backup_ids->info db (and event's id in $info)
|
||||
function restore_read_xml_events ($restore,$xml_file) {
|
||||
|
||||
//We call the main read_xml function, with todo = EVENTS
|
||||
$info = restore_read_xml ($xml_file,"EVENTS",$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) {
|
||||
@@ -841,7 +851,6 @@
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
//Now build the GROUP record structure
|
||||
$gro->id = backup_todb($info['GROUP']['#']['ID']['0']['#']);
|
||||
$gro->courseid = backup_todb($info['GROUP']['#']['COURSEID']['0']['#']);
|
||||
$gro->name = backup_todb($info['GROUP']['#']['NAME']['0']['#']);
|
||||
$gro->description = backup_todb($info['GROUP']['#']['DESCRIPTION']['0']['#']);
|
||||
@@ -932,6 +941,95 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function creates all the course events
|
||||
function restore_create_events($restore,$xml_file) {
|
||||
|
||||
global $CFG, $db;
|
||||
|
||||
$status = true;
|
||||
//Check it exists
|
||||
if (!file_exists($xml_file)) {
|
||||
$status = false;
|
||||
}
|
||||
//Get info from xml
|
||||
if ($status) {
|
||||
//events will contain the old_id of every event
|
||||
//in backup_ids->info will be the real info (serialized)
|
||||
$events = restore_read_xml_events($restore,$xml_file);
|
||||
}
|
||||
//Now, if we have anything in events, we have to restore that
|
||||
//events
|
||||
if ($events) {
|
||||
if ($events !== true) {
|
||||
//Iterate over each event
|
||||
foreach ($events as $event) {
|
||||
//Get record from backup_ids
|
||||
$data = backup_getid($restore->backup_unique_code,"event",$event->id);
|
||||
//Init variables
|
||||
$create_event = 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 EVENT record structure
|
||||
$eve->name = backup_todb($info['EVENT']['#']['NAME']['0']['#']);
|
||||
$eve->description = backup_todb($info['EVENT']['#']['DESCRIPTION']['0']['#']);
|
||||
$eve->courseid = $restore->course_id;
|
||||
$eve->groupid = backup_todb($info['EVENT']['#']['GROUPID']['0']['#']);
|
||||
$eve->userid = backup_todb($info['EVENT']['#']['USERID']['0']['#']);
|
||||
$eve->modulename = "";
|
||||
$eve->instance = 0;
|
||||
$eve->eventtype = backup_todb($info['EVENT']['#']['EVENTTYPE']['0']['#']);
|
||||
$eve->timestart = backup_todb($info['EVENT']['#']['TIMESTART']['0']['#']);
|
||||
$eve->timeduration = backup_todb($info['EVENT']['#']['TIMEDURATION']['0']['#']);
|
||||
$eve->timemodified = backup_todb($info['EVENT']['#']['TIMEMODIFIED']['0']['#']);
|
||||
|
||||
|
||||
//Now search if that event exists (by description and timestart field) in
|
||||
//restore->course_id course
|
||||
$eve_db = get_record("event","courseid",$restore->course_id,"description",$eve->description,"timestart",$eve->timestart);
|
||||
//If it doesn't exist, create
|
||||
if (!$eve_db) {
|
||||
$create_event = true;
|
||||
}
|
||||
//If we must create the event
|
||||
if ($create_event) {
|
||||
|
||||
//We must recode the userid
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$eve->userid);
|
||||
if ($user) {
|
||||
$eve->userid = $user->new_id;
|
||||
} else {
|
||||
//Assign it to admin
|
||||
$eve->userid = 1;
|
||||
}
|
||||
//We have to recode the groupid field
|
||||
$group = backup_getid($restore->backup_unique_code,"group",$eve->groupid);
|
||||
if ($group) {
|
||||
$eve->groupid = $group->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the event
|
||||
$newid = insert_record ("event",$eve);
|
||||
}
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"event",
|
||||
$event->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) {
|
||||
@@ -1341,6 +1439,15 @@
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "change password":
|
||||
//recode the info field (it's the user id)
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$log->info);
|
||||
if ($user) {
|
||||
$log->info = $user->new_id;
|
||||
$log->url = "view.php?id=".$log->info."&course=".$log->course;
|
||||
$toinsert = true;
|
||||
}
|
||||
break;
|
||||
case "view all":
|
||||
$log->url = "view.php?id=".$log->course;
|
||||
$log->info = "";
|
||||
@@ -1613,6 +1720,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
//This is the startTag handler we use where we are reading the events zone (todo="EVENTS")
|
||||
function startElementEvents($parser, $tagName, $attrs) {
|
||||
//Refresh properties
|
||||
$this->level++;
|
||||
$this->tree[$this->level] = $tagName;
|
||||
|
||||
//if ($tagName == "EVENT" && $this->tree[3] == "EVENTS") { //Debug
|
||||
// echo "<P>EVENT: ".strftime ("%X",time()),"-"; //Debug
|
||||
//} //Debug
|
||||
|
||||
//Output something to avoid browser timeouts...
|
||||
backup_flush();
|
||||
|
||||
//Check if we are into EVENTS zone
|
||||
//if ($this->tree[3] == "EVENTS") //Debug
|
||||
// echo $this->level.str_repeat(" ",$this->level*2)."<".$tagName."><br>\n"; //Debug
|
||||
|
||||
//If we are under a EVENT tag under a EVENTS zone, accumule it
|
||||
if (isset($this->tree[4]) and isset($this->tree[3])) {
|
||||
if (($this->tree[4] == "EVENT") and ($this->tree[3] == "EVENTS")) {
|
||||
if (!isset($this->temp)) {
|
||||
$this->temp = "";
|
||||
}
|
||||
$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
|
||||
@@ -2322,6 +2457,56 @@
|
||||
$this->content = "";
|
||||
}
|
||||
|
||||
//This is the endTag handler we use where we are reading the events zone (todo="EVENTS")
|
||||
function endElementEvents($parser, $tagName) {
|
||||
//Check if we are into EVENTS zone
|
||||
if ($this->tree[3] == "EVENTS") {
|
||||
//if (trim($this->content)) //Debug
|
||||
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br>\n"; //Debug
|
||||
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br>\n"; //Debug
|
||||
//Acumulate data to info (content + close tag)
|
||||
//Reconvert: strip htmlchars again and trim to generate xml data
|
||||
if (!isset($this->temp)) {
|
||||
$this->temp = "";
|
||||
}
|
||||
$this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";
|
||||
//If we've finished a event, xmlize it an save to db
|
||||
if (($this->level == 4) and ($tagName == "EVENT")) {
|
||||
//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 EVENT)
|
||||
//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
|
||||
$event_id = $data["EVENT"]["#"]["ID"]["0"]["#"];
|
||||
//Save to db
|
||||
$status = backup_putid($this->preferences->backup_unique_code,"event",$event_id,
|
||||
null,$data);
|
||||
//Create returning info
|
||||
$ret_info->id = $event_id;
|
||||
$this->info[] = $ret_info;
|
||||
//Reset temp
|
||||
unset($this->temp);
|
||||
}
|
||||
}
|
||||
|
||||
//Stop parsing if todo = EVENTS and tagName = EVENT (en of the tag, of course)
|
||||
//Speed up a lot (avoid parse all)
|
||||
if ($tagName == "EVENTS" 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
|
||||
@@ -2491,6 +2676,9 @@
|
||||
} else if ($todo == "GROUPS") {
|
||||
//Define handlers to that zone
|
||||
xml_set_element_handler($xml_parser, "startElementGroups", "endElementGroups");
|
||||
} else if ($todo == "EVENTS") {
|
||||
//Define handlers to that zone
|
||||
xml_set_element_handler($xml_parser, "startElementEvents", "endElementEvents");
|
||||
} else if ($todo == "MODULES") {
|
||||
//Define handlers to that zone
|
||||
xml_set_element_handler($xml_parser, "startElementModules", "endElementModules");
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@
|
||||
// database (backup_version) to determine whether upgrades should
|
||||
// be performed (see db/backup_*.php)
|
||||
|
||||
$backup_version = 2004022000; // The current version is a date (YYYYMMDDXX)
|
||||
$backup_version = 2004022100; // The current version is a date (YYYYMMDDXX)
|
||||
|
||||
$backup_release = "1.2 alpha"; // User-friendly version number
|
||||
|
||||
Reference in New Issue
Block a user