Permalink
Browse files

MDL-31390 Convert set_source_sql with order clauses to set_source_table

  • Loading branch information...
1 parent d9bae60 commit 5251450372822d6d41282dd6269d899039c23ffc @andrewnicols andrewnicols committed with andrewnicols Jan 29, 2013
@@ -58,12 +58,7 @@ protected function add_question_question_answers($element) {
$answers->add_child($answer);
// Set the sources
- $answer->set_source_sql('
- SELECT *
- FROM {question_answers}
- WHERE question = :question
- ORDER BY id',
- array('question' => backup::VAR_PARENTID));
+ $answer->set_source_table('question_answers', array('question' => backup::VAR_PARENTID), 'id ASC');
// Aliases
$answer->set_source_alias('answer', 'answertext');
@@ -92,12 +87,7 @@ protected function add_question_numerical_units($element) {
$units->add_child($unit);
// Set the sources
- $unit->set_source_sql('
- SELECT *
- FROM {question_numerical_units}
- WHERE question = :question
- ORDER BY id',
- array('question' => backup::VAR_PARENTID));
+ $unit->set_source_table('question_numerical_units', array('question' => backup::VAR_PARENTID), 'id ASC');
// don't need to annotate ids nor files
}
@@ -232,20 +232,9 @@ protected function add_question_usages($element, $usageidname, $nameprefix = '')
// Set the sources
$quba->set_source_table('question_usages',
array('id' => '../' . $usageidname));
- $qa->set_source_sql('
- SELECT *
- FROM {question_attempts}
- WHERE questionusageid = :questionusageid
- ORDER BY slot',
- array('questionusageid' => backup::VAR_PARENTID));
- $step->set_source_sql('
- SELECT *
- FROM {question_attempt_steps}
- WHERE questionattemptid = :questionattemptid
- ORDER BY sequencenumber',
- array('questionattemptid' => backup::VAR_PARENTID));
- $variable->set_source_table('question_attempt_step_data',
- array('attemptstepid' => backup::VAR_PARENTID));
+ $qa->set_source_table('question_attempts', array('questionusageid' => backup::VAR_PARENTID), 'slot ASC');
+ $step->set_source_table('question_attempt_steps', array('questionattemptid' => backup::VAR_PARENTID), 'sequencenumber ASC');
+ $variable->set_source_table('question_attempt_step_data', array('attemptstepid' => backup::VAR_PARENTID));
// Annotate ids
$qa->annotate_ids('question', 'questionid');
@@ -569,7 +558,7 @@ protected function define_structure() {
$userenrolments->add_child($enrolment);
// Define sources - the instances are restored using the same sortorder, we do not need to store it in xml and deal with it afterwards.
- $enrol->set_source_sql("SELECT * FROM {enrol} WHERE courseid = :courseid ORDER BY sortorder", array('courseid' => backup::VAR_COURSEID));
+ $enrol->set_source_table('enrol', array('courseid' => backup::VAR_COURSEID), 'sortorder ASC');
// User enrolments only added only if users included
if ($users) {
@@ -63,12 +63,7 @@ protected function define_structure() {
// Define sources
$choice->set_source_table('choice', array('id' => backup::VAR_ACTIVITYID));
- $option->set_source_sql('
- SELECT *
- FROM {choice_options}
- WHERE choiceid = ?
- ORDER BY id',
- array(backup::VAR_PARENTID));
+ $option->set_source_table('choice_options', array('choiceid' => backup::VAR_PARENTID), 'id ASC');
// All the rest of elements only happen if we are including user info
if ($userinfo) {
@@ -114,10 +114,7 @@ protected function define_structure() {
array(backup::VAR_PARENTID));
// Need posts ordered by id so parents are always before childs on restore
- $post->set_source_sql("SELECT *
- FROM {forum_posts}
- WHERE discussion = :discussion
- ORDER BY id", array('discussion' => backup::VAR_PARENTID));
+ $post->set_source_table('forum_posts', array('discussion' => backup::VAR_PARENTID), 'id ASC');
$subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID));
@@ -165,19 +165,10 @@ protected function define_structure() {
// at this point (lesson, lesson_pages, lesson_answers)
$lesson->set_source_table('lesson', array('id' => backup::VAR_ACTIVITYID));
//we use SQL here as it must be ordered by prevpageid so that restore gets the pages in the right order.
- $page->set_source_sql("
- SELECT *
- FROM {lesson_pages}
- WHERE lessonid = ? ORDER BY prevpageid",
- array(backup::VAR_PARENTID));
+ $page->set_source_table('lesson_pages', array('lessonid' => backup::VAR_PARENTID), 'prevpageid ASC');
// We use SQL here as answers must be ordered by id so that the restore gets them in the right order
- $answer->set_source_sql('
- SELECT *
- FROM {lesson_answers}
- WHERE pageid = :pageid
- ORDER BY id',
- array('pageid' => backup::VAR_PARENTID));
+ $answer->set_source_table('lesson_answers', array('pageid' => backup::VAR_PARENTID), 'id ASC');
// Check if we are also backing up user information
if ($this->get_setting_value('userinfo')) {
@@ -127,72 +127,19 @@ protected function define_structure() {
// Define sources
$scorm->set_source_table('scorm', array('id' => backup::VAR_ACTIVITYID));
- // Use set_source_sql for other calls as set_source_table returns records in reverse order
- // and order is important for several SCORM fields - esp scorm_scoes.
- $sco->set_source_sql('
- SELECT *
- FROM {scorm_scoes}
- WHERE scorm = :scorm
- ORDER BY id',
- array('scorm' => backup::VAR_PARENTID));
-
- $scodata->set_source_sql('
- SELECT *
- FROM {scorm_scoes_data}
- WHERE scoid = :scoid
- ORDER BY id',
- array('scoid' => backup::VAR_PARENTID));
-
- $seqrulecond->set_source_sql('
- SELECT *
- FROM {scorm_seq_ruleconds}
- WHERE scoid = :scoid
- ORDER BY id',
- array('scoid' => backup::VAR_PARENTID));
-
- $seqrulecondsdata->set_source_sql('
- SELECT *
- FROM {scorm_seq_rulecond}
- WHERE ruleconditionsid = :ruleconditionsid
- ORDER BY id',
- array('ruleconditionsid' => backup::VAR_PARENTID));
-
- $seqrolluprule->set_source_sql('
- SELECT *
- FROM {scorm_seq_rolluprule}
- WHERE scoid = :scoid
- ORDER BY id',
- array('scoid' => backup::VAR_PARENTID));
-
- $seqrolluprulecond->set_source_sql('
- SELECT *
- FROM {scorm_seq_rolluprulecond}
- WHERE rollupruleid = :rollupruleid
- ORDER BY id',
- array('rollupruleid' => backup::VAR_PARENTID));
-
- $seqobjective->set_source_sql('
- SELECT *
- FROM {scorm_seq_objective}
- WHERE scoid = :scoid
- ORDER BY id',
- array('scoid' => backup::VAR_PARENTID));
-
- $seqmapinfo->set_source_sql('
- SELECT *
- FROM {scorm_seq_mapinfo}
- WHERE objectiveid = :objectiveid
- ORDER BY id',
- array('objectiveid' => backup::VAR_PARENTID));
+ // Order is important for several SCORM calls (especially scorm_scoes) in the following calls to set_source_table
+ $sco->set_source_table('scorm_scoes', array('scorm' => backup::VAR_PARENTID), 'id ASC');
+ $scodata->set_source_table('scorm_scoes_data', array('scoid' => backup::VAR_PARENTID), 'id ASC');
+ $seqrulecond->set_source_table('scorm_seq_ruleconds', array('scoid' => backup::VAR_PARENTID), 'id ASC');
+ $seqrulecondsdata->set_source_table('scorm_seq_rulecond', array('ruleconditionsid' => backup::VAR_PARENTID), 'id ASC');
+ $seqrolluprule->set_source_table('scorm_seq_rolluprule', array('scoid' => backup::VAR_PARENTID), 'id ASC');
+ $seqrolluprulecond->set_source_table('scorm_seq_rolluprulecond', array('rollupruleid' => backup::VAR_PARENTID), 'id ASC');
+ $seqobjective->set_source_table('scorm_seq_objective', array('scoid' => backup::VAR_PARENTID), 'id ASC');
+ $seqmapinfo->set_source_table('scorm_seq_mapinfo', array('objectiveid' => backup::VAR_PARENTID), 'id ASC');
// All the rest of elements only happen if we are including user info
if ($userinfo) {
- $scotrack->set_source_sql('
- SELECT *
- FROM {scorm_scoes_track}
- WHERE scoid = :scoid
- ORDER BY id',
- array('scoid' => backup::VAR_PARENTID));
+ $scotrack->set_source_table('scorm_scoes_track', array('scoid' => backup::VAR_PARENTID), 'id ASC');
}
// Define id annotations
@@ -66,12 +66,7 @@ protected function define_question_plugin_structure() {
// Set source to populate the data.
$matchoptions->set_source_table('qtype_match_options',
array('questionid' => backup::VAR_PARENTID));
- $match->set_source_sql('
- SELECT *
- FROM {qtype_match_subquestions}
- WHERE questionid = :questionid
- ORDER BY id',
- array('questionid' => backup::VAR_PARENTID));
+ $match->set_source_table('qtype_match_subquestions', array('questionid' => backup::VAR_PARENTID), 'id ASC');
// Don't need to annotate ids nor files.

0 comments on commit 5251450

Please sign in to comment.