Skip to content

Commit

Permalink
Bug #6099 - Restore alternatively failing on data module - fixed stat…
Browse files Browse the repository at this point in the history
…us codes of module restore process
  • Loading branch information
skodak committed Jul 13, 2006
1 parent e9dbe49 commit bbdb1c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
6 changes: 4 additions & 2 deletions backup/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -411,8 +411,10 @@ function backup_putid ($backup_unique_code, $table, $old_id, $new_id, $info="")
$rec->old_id = $old_id; $rec->old_id = $old_id;
$rec->new_id = ($new_id === null? 0 : $new_id); $rec->new_id = ($new_id === null? 0 : $new_id);
$rec->info = $info_to_save; $rec->info = $info_to_save;


$status = insert_record('backup_ids', $rec, false); if (!insert_record('backup_ids', $rec, false)) {
$status = false;
}
} }
return $status; return $status;
} }
Expand Down
2 changes: 1 addition & 1 deletion backup/restorelib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ function restore_create_modules($restore,$xml_file) {
$modrestore = $mod->modtype."_restore_mods"; $modrestore = $mod->modtype."_restore_mods";
if (function_exists($modrestore)) { if (function_exists($modrestore)) {
//print_object ($mod); //Debug //print_object ($mod); //Debug
$status &= $modrestore($mod,$restore); $status = $status and $modrestore($mod,$restore); //bit operator & not reliable here!
} else { } else {
//Something was wrong. Function should exist. //Something was wrong. Function should exist.
$status = false; $status = false;
Expand Down
37 changes: 24 additions & 13 deletions mod/data/restorelib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ function data_restore_mods($mod,$restore) {
} }
if ($restore_userdata_selected) { if ($restore_userdata_selected) {
//Restore data_fields first!!! need to hold an array of [oldid]=>newid due to double dependencies //Restore data_fields first!!! need to hold an array of [oldid]=>newid due to double dependencies
$status = data_fields_restore_mods ($mod->id, $newid, $info, $restore); $status = $status and data_fields_restore_mods ($mod->id, $newid, $info, $restore);
$status = data_records_restore_mods ($mod->id, $newid, $info, $restore); $status = $status and data_records_restore_mods ($mod->id, $newid, $info, $restore);

} }
} else { } else {
$status = false; $status = false;
Expand Down Expand Up @@ -172,6 +172,8 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)


global $CFG, $fieldids; global $CFG, $fieldids;


$status = true;

$records = $info['MOD']['#']['RECORDS']['0']['#']['RECORD']; $records = $info['MOD']['#']['RECORDS']['0']['#']['RECORD'];


for ($i = 0; $i < sizeof($records); $i++) { for ($i = 0; $i < sizeof($records); $i++) {
Expand Down Expand Up @@ -206,12 +208,12 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)


if ($newid) { if ($newid) {
//We have the newid, update backup_ids //We have the newid, update backup_ids
$status = backup_putid($restore->backup_unique_code,"data_records",$oldid, $newid); $status = $status and backup_putid($restore->backup_unique_code,"data_records",$oldid, $newid);

$status = $status and data_content_restore_mods ($oldid, $newid, $old_data_id, $new_data_id, $rec_info, $restore);
$status = $status and data_ratings_restore_mods ($oldid, $newid, $info, $rec_info);
$status = $status and data_comments_restore_mods ($oldid, $newid, $info, $rec_info);


$status = data_content_restore_mods ($oldid, $newid, $old_data_id, $new_data_id, $rec_info, $restore);
$status = data_ratings_restore_mods ($oldid, $newid, $info, $rec_info);
$status = data_comments_restore_mods ($oldid, $newid, $info, $rec_info);

} else { } else {
$status = false; $status = false;
} }
Expand All @@ -223,6 +225,8 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id


global $CFG, $fieldids; global $CFG, $fieldids;


$status = true;

$contents = $recinfo['#']['CONTENTS']['0']['#']['CONTENT']; $contents = $recinfo['#']['CONTENTS']['0']['#']['CONTENT'];


for ($i = 0; $i < sizeof($contents); $i++) { for ($i = 0; $i < sizeof($contents); $i++) {
Expand Down Expand Up @@ -254,10 +258,9 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id


if ($newid) { if ($newid) {
//We have the newid, update backup_ids //We have the newid, update backup_ids



$status = data_restore_files ($old_data_id, $new_data_id, $oldfieldid, $content->fieldid, $oldrecordid, $content->recordid, $recinfo, $restore); $status = $status and data_restore_files ($old_data_id, $new_data_id, $oldfieldid, $content->fieldid, $oldrecordid, $content->recordid, $recinfo, $restore);
$status = backup_putid($restore->backup_unique_code,"data_content",$oldid, $newid); $status = $status and backup_putid($restore->backup_unique_code,"data_content",$oldid, $newid);
} else { } else {
$status = false; $status = false;
} }
Expand Down Expand Up @@ -324,6 +327,8 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {


global $CFG; global $CFG;


$status = true;

$ratings= $rec_info['#']['RATINGS']['0']['#']['RATING']; $ratings= $rec_info['#']['RATINGS']['0']['#']['RATING'];


if (empty($ratings)) { // no ratings to restore if (empty($ratings)) { // no ratings to restore
Expand All @@ -337,7 +342,9 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
$rating -> userid = backup_todb($rat_info['#']['USERID']['0']['#']); $rating -> userid = backup_todb($rat_info['#']['USERID']['0']['#']);
$rating -> rating = backup_todb($rat_info['#']['RATING']['0']['#']); $rating -> rating = backup_todb($rat_info['#']['RATING']['0']['#']);


$status = insert_record ("data_ratings",$rating); if (! insert_record ("data_ratings",$rating)) {
$status = false;
}
} }
return $status; return $status;
} }
Expand All @@ -346,6 +353,8 @@ function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {


global $CFG; global $CFG;


$status = true;

$comments= $rec_info['#']['COMMENTS']['0']['#']['COMMENT']; $comments= $rec_info['#']['COMMENTS']['0']['#']['COMMENT'];


if (empty($comments)) { // no comments to restore if (empty($comments)) { // no comments to restore
Expand All @@ -361,7 +370,9 @@ function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
$comment -> content = backup_todb($com_info['#']['CONTENT']['0']['#']); $comment -> content = backup_todb($com_info['#']['CONTENT']['0']['#']);
$comment -> created = backup_todb($com_info['#']['CREATED']['0']['#']); $comment -> created = backup_todb($com_info['#']['CREATED']['0']['#']);
$comment -> modified = backup_todb($com_info['#']['MODIFIED']['0']['#']); $comment -> modified = backup_todb($com_info['#']['MODIFIED']['0']['#']);
$status = insert_record ("data_comments",$comment); if (! insert_record ("data_comments",$comment)) {
$status = false;
}


} }
return $status; return $status;
Expand Down

0 comments on commit bbdb1c3

Please sign in to comment.