diff --git a/question/type/calculated/db/upgrade.php b/question/type/calculated/db/upgrade.php index 7d49e4247ae..f141e0224ac 100644 --- a/question/type/calculated/db/upgrade.php +++ b/question/type/calculated/db/upgrade.php @@ -36,199 +36,6 @@ function xmldb_qtype_calculated_upgrade($oldversion) { $dbman = $DB->get_manager(); - // MDL-16505. - if ($oldversion < 2008091700 ) { //New version in version.php - if (get_config('qtype_calculated', 'version')) { - unset_config('version', 'qtype_calculated'); - } - upgrade_plugin_savepoint(true, 2008091700, 'qtype', 'calculated'); - } - - if ($oldversion < 2009082000) { //New version in version.php - - // Define table question_calculated_options to be created - $table = new xmldb_table('question_calculated_options'); - - // Adding fields to table question_calculated_options - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - $table->add_field('synchronize', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - - // Adding keys to table question_calculated_options - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Conditionally launch create table for question_calculated_options - if (!$dbman->table_exists($table)) { - // $dbman->create_table doesnt return a result, we just have to trust it - $dbman->create_table($table); - } - upgrade_plugin_savepoint(true, 2009082000 , 'qtype', 'calculated'); - } - - if ( $oldversion < 2009092000) { //New version in version.php - - // Define field single to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('single', XMLDB_TYPE_INTEGER, '4', null, - XMLDB_NOTNULL, null, '0', 'synchronize'); - - // Conditionally launch add field single - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field shuffleanswers to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('shuffleanswers', XMLDB_TYPE_INTEGER, '4', null, - XMLDB_NOTNULL, null, '0', 'single'); - - // Conditionally launch add field shuffleanswers - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - // Define field correctfeedback to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'shuffleanswers'); - - // Conditionally launch add field correctfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field partiallycorrectfeedback to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'correctfeedback'); - - // Conditionally launch add field partiallycorrectfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - // Define field incorrectfeedback to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'partiallycorrectfeedback'); - - // Conditionally launch add field incorrectfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - // Define field answernumbering to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('answernumbering', XMLDB_TYPE_CHAR, '10', null, - XMLDB_NOTNULL, null, 'abc', 'incorrectfeedback'); - - // Conditionally launch add field answernumbering - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - upgrade_plugin_savepoint(true, 2009092000, 'qtype', 'calculated'); - } - - if ($oldversion < 2010020800) { - - // Define field multiplechoice to be dropped from question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('multichoice'); - - // Conditionally launch drop field multiplechoice - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // calculated savepoint reached - upgrade_plugin_savepoint(true, 2010020800, 'qtype', 'calculated'); - } - - if ($oldversion < 2010020801) { - - // Define field correctfeedbackformat to be added to question_calculated_options - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'correctfeedback'); - - // Conditionally launch add field correctfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field partiallycorrectfeedbackformat to be added to question_calculated_options - $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback'); - - // Conditionally launch add field partiallycorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field incorrectfeedbackformat to be added to question_calculated_options - $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedback'); - - // Conditionally launch add field incorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // In the past, the correctfeedback, partiallycorrectfeedback, - // incorrectfeedback columns were assumed to contain content of the same - // form as questiontextformat. If we are using the HTML editor, then - // convert FORMAT_MOODLE content to FORMAT_HTML. - $rs = $DB->get_recordset_sql(' - SELECT qco.*, q.oldquestiontextformat - FROM {question_calculated_options} qco - JOIN {question} q ON qco.question = q.id'); - foreach ($rs as $record) { - if ($CFG->texteditors !== 'textarea' && - $record->oldquestiontextformat == FORMAT_MOODLE) { - $record->correctfeedback = text_to_html( - $record->correctfeedback, false, false, true); - $record->correctfeedbackformat = FORMAT_HTML; - $record->partiallycorrectfeedback = text_to_html( - $record->partiallycorrectfeedback, false, false, true); - $record->partiallycorrectfeedbackformat = FORMAT_HTML; - $record->incorrectfeedback = text_to_html( - $record->incorrectfeedback, false, false, true); - $record->incorrectfeedbackformat = FORMAT_HTML; - } else { - $record->correctfeedbackformat = $record->oldquestiontextformat; - $record->partiallycorrectfeedbackformat = $record->oldquestiontextformat; - $record->incorrectfeedbackformat = $record->oldquestiontextformat; - } - $DB->update_record('question_calculated_options', $record); - } - $rs->close(); - - // calculated savepoint reached - upgrade_plugin_savepoint(true, 2010020801, 'qtype', 'calculated'); - } - - // Add new shownumcorrect field. If this is true, then when the user gets a - // multiple-response question partially correct, tell them how many choices - // they got correct alongside the feedback. - if ($oldversion < 2011051900) { - - // Define field shownumcorrect to be added to question_multichoice - $table = new xmldb_table('question_calculated_options'); - $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'answernumbering'); - - // Launch add field shownumcorrect - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // multichoice savepoint reached - upgrade_plugin_savepoint(true, 2011051900, 'qtype', 'calculated'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this diff --git a/question/type/essay/db/upgrade.php b/question/type/essay/db/upgrade.php index f5938bdf3f9..7a80f4dba34 100644 --- a/question/type/essay/db/upgrade.php +++ b/question/type/essay/db/upgrade.php @@ -36,59 +36,6 @@ function xmldb_qtype_essay_upgrade($oldversion) { $dbman = $DB->get_manager(); - if ($oldversion < 2011031000) { - // Define table qtype_essay_options to be created - $table = new xmldb_table('qtype_essay_options'); - - // Adding fields to table qtype_essay_options - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, null); - $table->add_field('responseformat', XMLDB_TYPE_CHAR, '16', null, - XMLDB_NOTNULL, null, 'editor'); - $table->add_field('responsefieldlines', XMLDB_TYPE_INTEGER, '4', null, - XMLDB_NOTNULL, null, '15'); - $table->add_field('attachments', XMLDB_TYPE_INTEGER, '4', null, - XMLDB_NOTNULL, null, '0'); - $table->add_field('graderinfo', XMLDB_TYPE_TEXT, 'small', null, - null, null, null); - $table->add_field('graderinfoformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - - // Adding keys to table qtype_essay_options - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, - array('questionid'), 'question', array('id')); - - // Conditionally launch create table for qtype_essay_options - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // essay savepoint reached - upgrade_plugin_savepoint(true, 2011031000, 'qtype', 'essay'); - } - - if ($oldversion < 2011060300) { - // Insert a row into the qtype_essay_options table for each existing essay question. - $DB->execute(" - INSERT INTO {qtype_essay_options} (questionid, responseformat, - responsefieldlines, attachments, graderinfo, graderinfoformat) - SELECT q.id, 'editor', 15, 0, '', " . FORMAT_MOODLE . " - FROM {question} q - WHERE q.qtype = 'essay' - AND NOT EXISTS ( - SELECT 'x' - FROM {qtype_essay_options} qeo - WHERE qeo.questionid = q.id)"); - - // essay savepoint reached - upgrade_plugin_savepoint(true, 2011060300, 'qtype', 'essay'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this diff --git a/question/type/match/db/upgrade.php b/question/type/match/db/upgrade.php index e799034226a..62770689c6b 100644 --- a/question/type/match/db/upgrade.php +++ b/question/type/match/db/upgrade.php @@ -36,179 +36,6 @@ function xmldb_qtype_match_upgrade($oldversion) { $dbman = $DB->get_manager(); - if ($oldversion < 2009072100) { - - // Define field questiontextformat to be added to question_match_sub - $table = new xmldb_table('question_match_sub'); - $field = new xmldb_field('questiontextformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'questiontext'); - - // Conditionally launch add field questiontextformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // In the past, question_match_sub.questiontext assumed to contain - // content of the same form as question.questiontextformat. If we are - // using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML. - $rs = $DB->get_recordset_sql(' - SELECT qms.*, q.oldquestiontextformat - FROM {question_match_sub} qms - JOIN {question} q ON qms.question = q.id'); - foreach ($rs as $record) { - if ($CFG->texteditors !== 'textarea' && - $record->oldquestiontextformat == FORMAT_MOODLE) { - $record->questiontext = text_to_html($record->questiontext, false, false, true); - $record->questiontextformat = FORMAT_HTML; - } else { - $record->questiontextformat = $record->oldquestiontextformat; - } - $DB->update_record('question_match_sub', $record); - } - $rs->close(); - - // match savepoint reached - upgrade_plugin_savepoint(true, 2009072100, 'qtype', 'match'); - } - - if ($oldversion < 2011011300) { - - // Define field correctfeedback to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'shuffleanswers'); - - // Conditionally launch add field correctfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''; - $DB->set_field('question_match', 'correctfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'shuffleanswers'); - $dbman->change_field_notnull($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011300, 'qtype', 'match'); - } - - if ($oldversion < 2011011301) { - - // Define field correctfeedbackformat to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'correctfeedback'); - - // Conditionally launch add field correctfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011301, 'qtype', 'match'); - } - - if ($oldversion < 2011011302) { - - // Define field partiallycorrectfeedback to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'correctfeedbackformat'); - - // Conditionally launch add field partiallycorrectfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''; - $DB->set_field('question_match', 'partiallycorrectfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'correctfeedbackformat'); - $dbman->change_field_notnull($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011302, 'qtype', 'match'); - } - - if ($oldversion < 2011011303) { - - // Define field partiallycorrectfeedbackformat to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback'); - - // Conditionally launch add field partiallycorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011303, 'qtype', 'match'); - } - - if ($oldversion < 2011011304) { - - // Define field incorrectfeedback to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - null, null, null, 'partiallycorrectfeedbackformat'); - - // Conditionally launch add field incorrectfeedback - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - - // Now fill it with ''; - $DB->set_field('question_match', 'incorrectfeedback', ''); - - // Now add the not null constraint. - $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, - XMLDB_NOTNULL, null, null, 'partiallycorrectfeedbackformat'); - $dbman->change_field_notnull($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011304, 'qtype', 'match'); - } - - if ($oldversion < 2011011305) { - - // Define field incorrectfeedbackformat to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedback'); - - // Conditionally launch add field incorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011305, 'qtype', 'match'); - } - - if ($oldversion < 2011011306) { - - // Define field shownumcorrect to be added to question_match - $table = new xmldb_table('question_match'); - $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedbackformat'); - - // Conditionally launch add field shownumcorrect - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // match savepoint reached - upgrade_plugin_savepoint(true, 2011011306, 'qtype', 'match'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this diff --git a/question/type/multianswer/db/upgrade.php b/question/type/multianswer/db/upgrade.php index ce7a57cfeba..8c7e04e379a 100644 --- a/question/type/multianswer/db/upgrade.php +++ b/question/type/multianswer/db/upgrade.php @@ -36,28 +36,6 @@ function xmldb_qtype_multianswer_upgrade($oldversion) { $dbman = $DB->get_manager(); - if ($oldversion < 2008050800) { - //hey - no functions here in this file !!!!!!! - - $rs = $DB->get_recordset_sql("SELECT q.id, q.category, qma.sequence - FROM {question} q - JOIN {question_multianswer} qma ON q.id = qma.question"); - foreach ($rs as $q) { - if (!empty($q->sequence)) { - $DB->execute("UPDATE {question} - SET parent = ?, category = ? - WHERE id IN ($q->sequence) AND parent <> 0", - array($q->id, $q->category)); - } - } - $rs->close(); - - /// multianswer savepoint reached - upgrade_plugin_savepoint(true, 2008050800, 'qtype', 'multianswer'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php index a26790ac8c1..41b56bf5a26 100644 --- a/question/type/multichoice/db/upgrade.php +++ b/question/type/multichoice/db/upgrade.php @@ -36,120 +36,6 @@ function xmldb_qtype_multichoice_upgrade($oldversion) { $dbman = $DB->get_manager(); - // This upgrade actually belongs to the random question type, - // but that does not have a DB upgrade script. Therefore, multichoice - // is doing it. - // Rename random questions to give them more helpful names. - if ($oldversion < 2008021800) { - require_once($CFG->dirroot . '/question/type/random/questiontype.php'); - $randomqtype = new qtype_random(); - - // Get all categories containing random questions. - $categories = $DB->get_recordset_sql(" - SELECT qc.id, qc.name - FROM {question_categories} qc - JOIN {question} q ON q.category = qc.id - WHERE q.qtype = 'random' - GROUP BY qc.id, qc.name"); - - // Rename the random qusetions in those categories. - $where = "qtype = 'random' AND category = ? AND " . - $DB->sql_compare_text('questiontext') . " = " . $DB->sql_compare_text('?'); - foreach ($categories as $cat) { - $randomqname = $randomqtype->question_name($cat, false); - $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0')); - - $randomqname = $randomqtype->question_name($cat, true); - $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1')); - } - - upgrade_plugin_savepoint(true, 2008021800, 'qtype', 'multichoice'); - } - - if ($oldversion < 2009021801) { - - // Define field correctfeedbackformat to be added to question_multichoice - $table = new xmldb_table('question_multichoice'); - $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'correctfeedback'); - - // Conditionally launch add field correctfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field partiallycorrectfeedbackformat to be added to question_multichoice - $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback'); - - // Conditionally launch add field partiallycorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Define field incorrectfeedbackformat to be added to question_multichoice - $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'incorrectfeedback'); - - // Conditionally launch add field incorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // In the past, the correctfeedback, partiallycorrectfeedback, - // incorrectfeedback columns were assumed to contain content of the same - // form as questiontextformat. If we are using the HTML editor, then - // convert FORMAT_MOODLE content to FORMAT_HTML. - $rs = $DB->get_recordset_sql(' - SELECT qm.*, q.oldquestiontextformat - FROM {question_multichoice} qm - JOIN {question} q ON qm.question = q.id'); - foreach ($rs as $record) { - if ($CFG->texteditors !== 'textarea' && - $record->oldquestiontextformat == FORMAT_MOODLE) { - $record->correctfeedback = text_to_html( - $record->correctfeedback, false, false, true); - $record->correctfeedbackformat = FORMAT_HTML; - $record->partiallycorrectfeedback = text_to_html( - $record->partiallycorrectfeedback, false, false, true); - $record->partiallycorrectfeedbackformat = FORMAT_HTML; - $record->incorrectfeedback = text_to_html( - $record->incorrectfeedback, false, false, true); - $record->incorrectfeedbackformat = FORMAT_HTML; - } else { - $record->correctfeedbackformat = $record->oldquestiontextformat; - $record->partiallycorrectfeedbackformat = $record->oldquestiontextformat; - $record->incorrectfeedbackformat = $record->oldquestiontextformat; - } - $DB->update_record('question_multichoice', $record); - } - $rs->close(); - - // multichoice savepoint reached - upgrade_plugin_savepoint(true, 2009021801, 'qtype', 'multichoice'); - } - - // Add new shownumcorrect field. If this is true, then when the user gets a - // multiple-response question partially correct, tell them how many choices - // they got correct alongside the feedback. - if ($oldversion < 2011011200) { - - // Define field shownumcorrect to be added to question_multichoice - $table = new xmldb_table('question_multichoice'); - $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'answernumbering'); - - // Launch add field shownumcorrect - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // multichoice savepoint reached - upgrade_plugin_savepoint(true, 2011011200, 'qtype', 'multichoice'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this // Moodle v2.2.0 release upgrade line // Put any upgrade step following this diff --git a/question/type/numerical/db/upgrade.php b/question/type/numerical/db/upgrade.php index 91224cad484..43db9a67c1d 100644 --- a/question/type/numerical/db/upgrade.php +++ b/question/type/numerical/db/upgrade.php @@ -36,270 +36,6 @@ function xmldb_qtype_numerical_upgrade($oldversion) { $dbman = $DB->get_manager(); - //===== 1.9.0 upgrade line ======// - if ($oldversion < 2009100100 ) { //New version in version.php - - // Define table question_numerical_options to be created - $table = new xmldb_table('question_numerical_options'); - - // Adding fields to table question_numerical_options - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - $table->add_field('instructions', XMLDB_TYPE_TEXT, 'small', null, - null, null, null); - $table->add_field('showunits', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - $table->add_field('unitsleft', XMLDB_TYPE_INTEGER, '4', null, - XMLDB_NOTNULL, null, '0'); - $table->add_field('unitgradingtype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0'); - $table->add_field('unitpenalty', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, - XMLDB_NOTNULL, null, '0.1'); - - // Adding keys to table question_numerical_options - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id')); - - // Conditionally launch create table for question_calculated_options - if (!$dbman->table_exists($table)) { - // $dbman->create_table doesnt return a result, we just have to trust it - $dbman->create_table($table); - } - - // Set a better default for questions without units. - $DB->execute(' - UPDATE {question_numerical_options} - SET showunits = 3 - WHERE NOT EXISTS ( - SELECT 1 - FROM {question_numerical_units} - WHERE {question_numerical_units}.question = - {question_numerical_options}.question - )'); - - upgrade_plugin_savepoint(true, 2009100100, 'qtype', 'numerical'); - } - - if ($oldversion < 2009100101) { - - // Define field instructionsformat to be added to question_numerical_options - $table = new xmldb_table('question_numerical_options'); - $field = new xmldb_field('instructionsformat', XMLDB_TYPE_INTEGER, '2', null, - XMLDB_NOTNULL, null, '0', 'instructions'); - - // Conditionally launch add field instructionsformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // In the past, question_numerical_options.instructions assumed to contain - // content of the same form as question.questiontextformat. If we are - // using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML. - $rs = $DB->get_recordset_sql(' - SELECT qno.*, q.oldquestiontextformat - FROM {question_numerical_options} qno - JOIN {question} q ON qno.question = q.id'); - foreach ($rs as $record) { - if ($CFG->texteditors !== 'textarea' && - $record->oldquestiontextformat == FORMAT_MOODLE) { - $record->instructions = text_to_html($record->instructions, false, false, true); - $record->instructionsformat = FORMAT_HTML; - } else { - $record->instructionsformat = $record->oldquestiontextformat; - } - $DB->update_record('question_numerical_options', $record); - } - $rs->close(); - - // numerical savepoint reached - upgrade_plugin_savepoint(true, 2009100101, 'qtype', 'numerical'); - } - - if ($oldversion < 2011042600) { - // Get rid of the instructions field by adding it to the qestion - // text. Also, if the unit was set to be displayed beside the input, - // deal with that within the question text too. - - // The hard-coded constants used here are: - // 2 = the old qtype_numerical::UNITDISPLAY for ->showunits - // 3 = qtype_numerical::UNITNONE - - $fs = get_file_storage(); - - $rs = $DB->get_recordset_sql(' - SELECT q.id AS questionid, - q.questiontext, - q.questiontextformat, - qc.contextid, - qno.id AS qnoid, - qno.instructions, - qno.instructionsformat, - qno.showunits, - qno.unitsleft, - qnu.unit AS defaultunit - - FROM {question} q - JOIN {question_categories} qc ON qc.id = q.category - JOIN {question_numerical_options} qno ON qno.question = q.id - JOIN {question_numerical_units} qnu ON qnu.id = ( - SELECT min(id) - FROM {question_numerical_units} - WHERE question = q.id AND ABS(multiplier - 1) < 0.0000000001)'); - foreach ($rs as $numericaloptions) { - if ($numericaloptions->showunits != 2 && empty($numericaloptions->instructions)) { - // Nothing to do for this question. - continue; - } - - $ishtml = qtype_numerical_convert_text_format($numericaloptions); - - $response = '_______________'; - if ($numericaloptions->showunits == 2) { - if ($numericaloptions->unitsleft) { - $response = $numericaloptions->defaultunit . ' _______________'; - } else { - $response = '_______________ ' . $numericaloptions->defaultunit; - } - - $DB->set_field('question_numerical_options', 'showunits', 3, - array('id' => $numericaloptions->qnoid)); - } - - if ($ishtml) { - $numericaloptions->questiontext .= '

' . $response . '

'; - } else { - $numericaloptions->questiontext .= "\n\n" . $response; - } - - if (!empty($numericaloptions->instructions)) { - if ($ishtml) { - $numericaloptions->questiontext .= $numericaloptions->instructions; - } else { - $numericaloptions->questiontext .= "\n\n" . $numericaloptions->instructions; - } - - $oldfiles = $fs->get_area_files($numericaloptions->contextid, - 'qtype_numerical', 'instruction', $numericaloptions->questionid, - 'id', false); - foreach ($oldfiles as $oldfile) { - $filerecord = new stdClass(); - $filerecord->component = 'question'; - $filerecord->filearea = 'questiontext'; - $fs->create_file_from_storedfile($filerecord, $oldfile); - } - - if ($oldfiles) { - $fs->delete_area_files($numericaloptions->contextid, - 'qtype_numerical', 'instruction', $numericaloptions->questionid); - } - } - - $updaterecord = new stdClass(); - $updaterecord->id = $numericaloptions->questionid; - $updaterecord->questiontext = $numericaloptions->questiontext; - $updaterecord->questiontextformat = $numericaloptions->questiontextformat; - $DB->update_record('question', $updaterecord); - } - $rs->close(); - - // numerical savepoint reached - upgrade_plugin_savepoint(true, 2011042600, 'qtype', 'numerical'); - } - - if ($oldversion < 2011042601) { - // Define field instructions to be dropped from question_numerical_options - $table = new xmldb_table('question_numerical_options'); - $field = new xmldb_field('instructions'); - - // Conditionally launch drop field instructions - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // numerical savepoint reached - upgrade_plugin_savepoint(true, 2011042601, 'qtype', 'numerical'); - } - - if ($oldversion < 2011042602) { - // Define field instructionsformat to be dropped from question_numerical_options - $table = new xmldb_table('question_numerical_options'); - $field = new xmldb_field('instructionsformat'); - - // Conditionally launch drop field instructionsformat - if ($dbman->field_exists($table, $field)) { - $dbman->drop_field($table, $field); - } - - // numerical savepoint reached - upgrade_plugin_savepoint(true, 2011042602, 'qtype', 'numerical'); - } - - // Moodle v2.1.0 release upgrade line - // Put any upgrade step following this - - // Moodle v2.2.0 release upgrade line - // Put any upgrade step following this return true; } - -/** - * Convert the ->questiontext and ->instructions fields to have the same text format. - * If they are already the same, do nothing. Otherwise, this method works by - * converting both to HTML. - * @param $numericaloptions the data to convert. - * @return bool true if the resulting fields are in HTML, as opposed to one of - * the text-based formats. - */ -function qtype_numerical_convert_text_format($numericaloptions) { - if ($numericaloptions->questiontextformat == $numericaloptions->instructionsformat) { - // Nothing to do: - return $numericaloptions->questiontextformat == FORMAT_HTML; - } - - if ($numericaloptions->questiontextformat != FORMAT_HTML) { - $numericaloptions->questiontext = qtype_numerical_convert_to_html( - $numericaloptions->questiontext, $numericaloptions->questiontextformat); - $numericaloptions->questiontextformat = FORMAT_HTML; - } - - if ($numericaloptions->instructionsformat != FORMAT_HTML) { - $numericaloptions->instructions = qtype_numerical_convert_to_html( - $numericaloptions->instructions, $numericaloptions->instructionsformat); - $numericaloptions->instructionsformat = FORMAT_HTML; - } - - return true; -} - -// Add some helper functions that should be in upgradelib.php, but having there already -// the question attempts updater classes prevents us to do so :-( - -/** - * Convert some content to HTML. - * @param string $text the content to convert to HTML - * @param int $oldformat One of the FORMAT_... constants. - */ -function qtype_numerical_convert_to_html($text, $oldformat) { - switch ($oldformat) { - // Similar to format_text. - - case FORMAT_PLAIN: - $text = s($text); - $text = str_replace(' ', '  ', $text); - $text = nl2br($text); - return $text; - - case FORMAT_MARKDOWN: - return markdown_to_html($text); - - case FORMAT_MOODLE: - return text_to_html($text, null, $options['para'], $options['newlines']); - - default: - throw new coding_exception( - 'Unexpected text format when upgrading numerical questions.'); - } -}