Skip to content

Commit

Permalink
Now group images are in backup & restore
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Mar 7, 2005
1 parent 93cf96f commit 80117b5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backup/CHANGES_14_15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Now I show the specific detailed status of every item in the process:
31. DONE: Change mail's priority (bug 2647) if something goes wrong in scheduled backups.
32. TODO: quiz_questions->hidden and quiz_responses->originalquestion
33. TODO: quiz_question_version
34. TODO: Group images aren't included at all in backup/restore. Bug 2674.
34. DONE: Group images aren't included at all in backup/restore. Bug 2674.

Eloy (stronk7)
23-01-2004
53 changes: 53 additions & 0 deletions backup/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,17 @@ function check_and_create_user_files_dir($backup_unique_code) {
return $status;
}

//Function to check and create the "group_files" dir to
//save all the user files we need from "groups" dir
function check_and_create_group_files_dir($backup_unique_code) {

global $CFG;

$status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code."/group_files",true);

return $status;
}

//Function to check and create the "course_files" dir to
//save all the course files we need from "CFG->datadir/course" dir
function check_and_create_course_files_dir($backup_unique_code) {
Expand Down Expand Up @@ -1437,6 +1448,11 @@ function backup_groups_info($bf,$preferences) {
}
//End groups tag
$status = fwrite ($bf,end_tag("GROUPS",2,true));

//Now save group_files
if ($status && $status2) {
$status2 = backup_copy_group_files($preferences);
}
}
return ($status && $status2);
}
Expand Down Expand Up @@ -1582,6 +1598,43 @@ function backup_copy_user_files ($preferences) {
}
}
}

return $status;
}

//This function copies all the needed files under the "groups" directory to the "group_files"
//directory under temp/backup
function backup_copy_group_files ($preferences) {

global $CFG;

$status = true;

//First we check if "group_files" exists and create it as necessary
//in temp/backup/$backup_code dir
$status = check_and_create_group_files_dir($preferences->backup_unique_code);

//Now iterate over directories under "groups" to check if that user must be
//copied to backup

$rootdir = $CFG->dataroot.'/groups';
//Check if directory exists
if (is_dir($rootdir)) {
$list = list_directories ($rootdir);
if ($list) {
//Iterate
foreach ($list as $dir) {
//Look for dir like group in groups table
$data = get_record ('groups', 'courseid', $preferences->backup_course,
'id',$dir);
//If exists, copy it
if ($data) {
$status = backup_copy_file($rootdir."/".$dir,
$CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/group_files/".$dir);
}
}
}
}
return $status;
}

Expand Down
61 changes: 60 additions & 1 deletion backup/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ function restore_create_groups($restore,$xml_file) {
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"group",
backup_putid($restore->backup_unique_code,"groups",
$group->id, $newid);
}
//Now restore members in the groups_members, only if
Expand All @@ -1725,6 +1725,10 @@ function restore_create_groups($restore,$xml_file) {
}
}
}
//Now, restore group_files
if ($status && $status2) {
$status2 = restore_group_files($restore);
}
}
} else {
$status = false;
Expand Down Expand Up @@ -1978,6 +1982,61 @@ function restore_user_files($restore) {
}
}

//This function restores the groupfiles from the temp (group_files) directory to the
//dataroot/groups directory
function restore_group_files($restore) {

global $CFG;

$status = true;

$counter = 0;

//First, we check to "groups" exists and create is as necessary
//in CFG->dataroot
$dest_dir = $CFG->dataroot.'/groups';
$status = check_dir_exists($dest_dir,true);

//Now, we iterate over "group_files" records to check if that user dir must be
//copied (and renamed) to the "groups" dir.
$rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/group_files";
//Check if directory exists
if (is_dir($rootdir)) {
$list = list_directories ($rootdir);
if ($list) {
//Iterate
$counter = 0;
foreach ($list as $dir) {
//Look for dir like groupid in backup_ids
$data = get_record ("backup_ids","backup_code",$restore->backup_unique_code,
"table_name","groups",
"old_id",$dir);
//If that group exists in backup_ids
if ($data) {
if (!file_exists($dest_dir."/".$data->new_id)) {
$status = backup_copy_file($rootdir."/".$dir, $dest_dir."/".$data->new_id);
$counter ++;
}
//Do some output
if ($counter % 2 == 0) {
echo ".";
if ($counter % 40 == 0) {
echo "<br />";
}
backup_flush(300);
}
}
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ($status and $counter) {
return $counter;
} else {
return $status;
}
}

//This function restores the course files from the temp (course_files) directory to the
//dataroot/course_id directory
function restore_course_files($restore) {
Expand Down

0 comments on commit 80117b5

Please sign in to comment.