From 15a6cf334fd3268f40dea55c8138ade33d13717f Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 13 Jul 2006 15:38:03 +0000 Subject: [PATCH] Bug #6099 - Restore alternatively failing on data module - fixed status codes of module restore process; merged from MOODLE_16_STABLE --- backup/lib.php | 6 ++++-- backup/restorelib.php | 2 +- mod/data/restorelib.php | 37 ++++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/backup/lib.php b/backup/lib.php index 6bcee82997..465719130b 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -413,8 +413,10 @@ $rec->old_id = $old_id; $rec->new_id = ($new_id === null? 0 : $new_id); $rec->info = $info_to_save; - - $status = insert_record('backup_ids', $rec, false); + + if (!insert_record('backup_ids', $rec, false)) { + $status = false; + } } return $status; } diff --git a/backup/restorelib.php b/backup/restorelib.php index 2eab43b028..ff015ab75c 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -2489,7 +2489,7 @@ $modrestore = $mod->modtype."_restore_mods"; if (function_exists($modrestore)) { //print_object ($mod); //Debug - $status &= $modrestore($mod,$restore); + $status = $status and $modrestore($mod,$restore); //bit operator & not reliable here! } else { //Something was wrong. Function should exist. $status = false; diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php index 9999910c01..1adf4d45f5 100644 --- a/mod/data/restorelib.php +++ b/mod/data/restorelib.php @@ -100,9 +100,9 @@ function data_restore_mods($mod,$restore) { } if ($restore_userdata_selected) { //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 = data_records_restore_mods ($mod->id, $newid, $info, $restore); - + $status = $status and data_fields_restore_mods ($mod->id, $newid, $info, $restore); + $status = $status and data_records_restore_mods ($mod->id, $newid, $info, $restore); + } } else { $status = false; @@ -172,6 +172,8 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore) global $CFG, $fieldids; + $status = true; + $records = $info['MOD']['#']['RECORDS']['0']['#']['RECORD']; for ($i = 0; $i < sizeof($records); $i++) { @@ -206,12 +208,12 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore) if ($newid) { //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 { $status = false; } @@ -223,6 +225,8 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id global $CFG, $fieldids; + $status = true; + $contents = $recinfo['#']['CONTENTS']['0']['#']['CONTENT']; for ($i = 0; $i < sizeof($contents); $i++) { @@ -254,10 +258,9 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id if ($newid) { //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 = backup_putid($restore->backup_unique_code,"data_content",$oldid, $newid); + $status = $status and data_restore_files ($old_data_id, $new_data_id, $oldfieldid, $content->fieldid, $oldrecordid, $content->recordid, $recinfo, $restore); + $status = $status and backup_putid($restore->backup_unique_code,"data_content",$oldid, $newid); } else { $status = false; } @@ -324,6 +327,8 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) { global $CFG; + $status = true; + $ratings= $rec_info['#']['RATINGS']['0']['#']['RATING']; if (empty($ratings)) { // no ratings to restore @@ -337,7 +342,9 @@ function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) { $rating -> userid = backup_todb($rat_info['#']['USERID']['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; } @@ -346,6 +353,8 @@ function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) { global $CFG; + $status = true; + $comments= $rec_info['#']['COMMENTS']['0']['#']['COMMENT']; if (empty($comments)) { // no comments to restore @@ -361,7 +370,9 @@ function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) { $comment -> content = backup_todb($com_info['#']['CONTENT']['0']['#']); $comment -> created = backup_todb($com_info['#']['CREATED']['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; -- 2.39.5