Permalink
Browse files

MDL-15095 towards restore lib dml conversion

  • Loading branch information...
skodak
skodak committed Jun 3, 2008
1 parent 785720d commit 9db7dab2caeef6611befe0fc01f49a30b0b00995
View
@@ -534,14 +534,11 @@ function backup_getid ($backup_unique_code, $table, $old_id) {
//This function is used to add slashes (and decode from UTF-8 if needed)
//It's used intensivelly when restoring modules and saving them in db
- function backup_todb ($data, $addslashes=true) {
+ function backup_todb ($data) {
// MDL-10770
if ($data === '$@NULL@$') {
return null;
} else {
- if ($addslashes) {
- $data = addslashes($data);
- }
return restore_decode_absolute_links($data);
}
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -23,8 +23,7 @@
//This function executes all the restore procedure about this mod
function assignment_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -87,17 +86,17 @@ function assignment_restore_mods($mod,$restore) {
if (!in_array($assignment->assignmenttype, $plugins)) {
if (!defined('RESTORE_SILENTLY')) {
- echo "<li><strong>".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\" - plugin '{$assignment->assignmenttype}' not available!</strong></li>";
+ echo "<li><strong>".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\" - plugin '{$assignment->assignmenttype}' not available!</strong></li>";
}
return true; // do not fail the restore
}
//The structure is equal to the db, so insert the assignment
- $newid = insert_record ("assignment",$assignment);
+ $newid = $DB->insert_record ("assignment",$assignment);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "<li>".get_string("modulename","assignment")." \"".format_string(stripslashes($assignment->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","assignment")." \"".format_string($assignment->name,true)."\"</li>";
}
backup_flush(300);
@@ -122,8 +121,7 @@ function assignment_restore_mods($mod,$restore) {
//This function restores the assignment_submissions
function assignment_submissions_restore_mods($old_assignment_id, $new_assignment_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -177,7 +175,7 @@ function assignment_submissions_restore_mods($old_assignment_id, $new_assignment
}
//The structure is equal to the db, so insert the assignment_submission
- $newid = insert_record ("assignment_submissions",$submission);
+ $newid = $DB->insert_record ("assignment_submissions",$submission);
//Do some output
if (($i+1) % 50 == 0) {
View
@@ -23,8 +23,7 @@
//This function executes all the restore procedure about this mod
function chat_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -53,11 +52,11 @@ function chat_restore_mods($mod,$restore) {
$chat->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the chat
- $newid = insert_record ("chat",$chat);
+ $newid = $db->insert_record ("chat",$chat);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "<li>".get_string("modulename","chat")." \"".format_string(stripslashes($chat->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","chat")." \"".format_string($chat->name,true)."\"</li>";
}
backup_flush(300);
@@ -82,8 +81,7 @@ function chat_restore_mods($mod,$restore) {
//This function restores the chat_messages
function chat_messages_restore_mods($old_chat_id, $new_chat_id,$info,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -123,7 +121,7 @@ function chat_messages_restore_mods($old_chat_id, $new_chat_id,$info,$restore) {
}
//The structure is equal to the db, so insert the chat_message
- $newid = insert_record ("chat_messages",$message);
+ $newid = $DB->insert_record ("chat_messages",$message);
//Do some output
if (($i+1) % 50 == 0) {
@@ -250,7 +248,6 @@ function chat_decode_content_links_caller($restore) {
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function chat_restore_logs($restore,$log) {
-
$status = false;
//Depending of the action, we recode different things
@@ -28,8 +28,7 @@
//This function executes all the restore procedure about this mod
function choice_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -84,7 +83,7 @@ function choice_restore_mods($mod,$restore) {
}
}
//The structure is equal to the db, so insert the choice
- $newid = insert_record ("choice",$choice);
+ $newid = $DB->insert_record ("choice",$choice);
if ($newid) {
//We have the newid, update backup_ids
@@ -114,7 +113,7 @@ function choice_restore_mods($mod,$restore) {
$option->choiceid = $newid;
$option->text = $options[$i];
$option->timemodified = $choice->timemodified;
- $newoptionid = insert_record ("choice_options",$option);
+ $newoptionid = $DB->insert_record ("choice_options",$option);
//Save this choice_option to backup_ids
backup_putid($restore->backup_unique_code,"choice_options",$i,$newoptionid);
}
@@ -134,7 +133,7 @@ function choice_restore_mods($mod,$restore) {
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "<li>".get_string("modulename","choice")." \"".format_string(stripslashes($choice->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","choice")." \"".format_string($choice->name,true)."\"</li>";
}
backup_flush(300);
View
@@ -37,8 +37,7 @@
//Return a content encoded to support interactivities linking. Every module
function data_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -100,11 +99,11 @@ function data_restore_mods($mod,$restore) {
unset($database->notification); /// Unset it if null to get proper Moodle 2.0 default (0) applied
}
- $newid = insert_record ('data', $database);
+ $newid = $DB->insert_record ('data', $database);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
- echo "<li>".get_string("modulename","data")." \"".format_string(stripslashes($database->name),true)."\"</li>";
+ echo "<li>".get_string("modulename","data")." \"".format_string($database->name,true)."\"</li>";
}
if ($newid) {
@@ -161,8 +160,7 @@ function data_restore_mods($mod,$restore) {
}
function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$fields = $info['MOD']['#']['FIELDS']['0']['#']['FIELD'];
@@ -187,7 +185,7 @@ function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore)
$field -> param9 = backup_todb($fie_info['#']['PARAM9']['0']['#']);
$field -> param10 = backup_todb($fie_info['#']['PARAM10']['0']['#']);
- $newid = insert_record ("data_fields",$field);
+ $newid = $DB->insert_record ("data_fields",$field);
$fieldids[$oldid] = $newid; //so we can use them in sub tables that depends on both fieldid and recordid
@@ -215,8 +213,7 @@ function data_fields_restore_mods ($old_data_id, $new_data_id, $info, $restore)
}
function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$status = true;
@@ -244,7 +241,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
$record->groupid= $group->new_id;
}
- $newid = insert_record ("data_records",$record);
+ $newid = $DB->insert_record ("data_records",$record);
//Do some output
if (($i+1) % 50 == 0) {
@@ -273,8 +270,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
}
function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id, $new_data_id, $recinfo, $restore) {
-
- global $CFG, $fieldids;
+ global $CFG, $fieldids, $DB;
$status = true;
@@ -294,7 +290,7 @@ function data_content_restore_mods ($old_record_id, $new_record_id, $old_data_id
$content -> content2 = backup_todb($con_info['#']['CONTENT2']['0']['#']);
$content -> content3 = backup_todb($con_info['#']['CONTENT3']['0']['#']);
$content -> content4 = backup_todb($con_info['#']['CONTENT4']['0']['#']);
- $newid = insert_record ("data_content",$content);
+ $newid = $DB->insert_record ("data_content",$content);
//Do some output
if (($i+1) % 50 == 0) {
@@ -374,8 +370,7 @@ function data_restore_files ($old_data_id, $new_data_id, $old_field_id, $new_fie
}
function data_ratings_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -392,16 +387,15 @@ 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']['#']);
- if (! insert_record ("data_ratings",$rating)) {
+ if (! $DB->insert_record ("data_ratings",$rating)) {
$status = false;
}
}
return $status;
}
function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
-
- global $CFG;
+ global $CFG, $DB;
$status = true;
@@ -420,7 +414,7 @@ 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']['#']);
- if (! insert_record ("data_comments",$comment)) {
+ if (! $DB->insert_record ("data_comments",$comment)) {
$status = false;
}
@@ -29,8 +29,7 @@
define('FEEDBACK_MULTICHOICERESTORE_TYPE_SEP', '>>>>>');
function feedback_restore_mods($mod,$restore) {
-
- global $CFG;
+ global $CFG, $DB;
// $allValues = array();
// $allTrackings = array();
@@ -63,7 +62,7 @@ function feedback_restore_mods($mod,$restore) {
$feedback->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
//The structure is equal to the db, so insert the feedback
- $newid = insert_record ("feedback",$feedback);
+ $newid = $DB->insert_record ("feedback",$feedback);
//create events
// the open-event
@@ -178,7 +177,7 @@ function feedback_restore_mods($mod,$restore) {
$item->position = backup_todb($item_info['#']['POSITION']['0']['#']);
$item->required = backup_todb($item_info['#']['REQUIRED']['0']['#']);
//put this new item into the database
- $newitemid = insert_record('feedback_item', $item);
+ $newitemid = $DB->insert_record('feedback_item', $item);
//Now check if want to restore user data and do it.
if ($restore_userdata) {
@@ -192,10 +191,10 @@ function feedback_restore_mods($mod,$restore) {
$value->completed = 0;
$value->tmp_completed = backup_todb($value_info['#']['COMPLETED']['0']['#']);
$value->value = backup_todb($value_info['#']['VAL']['0']['#']);
- $value->value = addslashes($value->value);
+ $value->value = $value->value;
$value->course_id = backup_todb($value_info['#']['COURSE_ID']['0']['#']);
//put this new value into the database
- $newvalueid = insert_record('feedback_value', $value);
+ $newvalueid = $DB->insert_record('feedback_value', $value);
$value->id = $newvalueid;
// $allValues[] = $value;
}
@@ -224,7 +223,7 @@ function feedback_restore_mods($mod,$restore) {
}
//save the tracking
- $newtrackingid = insert_record('feedback_tracking', $tracking);
+ $newtrackingid = $DB->insert_record('feedback_tracking', $tracking);
$tracking->id = $newtrackingid;
// $allTrackings[] = $tracking;
}
@@ -255,25 +254,25 @@ function feedback_restore_mods($mod,$restore) {
$oldcompletedid = backup_todb($completed_info['#']['ID']['0']['#']);
//save the completed
- $newcompletedid = insert_record('feedback_completed', $completed);
+ $newcompletedid = $DB->insert_record('feedback_completed', $completed);
//the newcompletedid have to be changed at every values
- $tochangevals = get_records('feedback_value', 'tmp_completed', $oldcompletedid);
+ $tochangevals = $DB->get_records('feedback_value', array('tmp_completed'=>$oldcompletedid));
if($tochangevals) {
foreach($tochangevals as $tmpVal) {
$tmpVal->completed = $newcompletedid;
$tmpVal->tmp_completed = 0;
- update_record('feedback_value', $tmpVal);
+ $DB->update_record('feedback_value', $tmpVal);
}
}
//the newcompletedid have to be changed at every tracking
- $tochangetracks = get_records('feedback_tracking', 'completed', $oldcompletedid);
+ $tochangetracks = $DB->get_records('feedback_tracking', array('completed'=>$oldcompletedid));
if($tochangetracks) {
foreach($tochangetracks as $tmpTrack) {
$tmpTrack->completed = $newcompletedid;
$tmpTrack->tmp_completed = 0;
- update_record('feedback_tracking', $tmpTrack);
+ $DB->update_record('feedback_tracking', $tmpTrack);
}
}
}
Oops, something went wrong.

0 comments on commit 9db7dab

Please sign in to comment.