From bb28e3bc5e5cb904cf2d39713723c16d4eedd403 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 12 May 2011 18:58:50 +0100 Subject: [PATCH] MDL-27408 Moved the question engine install/upgrade code into the proper place. I have tested upgrade from the previous development version, and a clean install. Upgrade from 2.0 still needs more work. --- lib/adminlib.php | 29 ++ lib/db/install.xml | 93 +++- lib/db/upgrade.php | 352 +++++++++++++ local/qedatabase/db/install.php | 696 ------------------------- local/qedatabase/db/upgrade.php | 110 ---- local/qedatabase/readme.txt | 2 - local/qedatabase/version.php | 30 -- mod/quiz/attemptlib.php | 6 - mod/quiz/db/install.php | 6 +- mod/quiz/db/install.xml | 117 +++-- mod/quiz/db/upgrade.php | 604 +++++++++++++++++++++ mod/quiz/db/upgradelib.php | 76 +++ mod/quiz/lang/en/quiz.php | 3 + mod/quiz/locallib.php | 41 -- mod/quiz/mod_form.php | 3 +- mod/quiz/settings.php | 13 +- mod/quiz/version.php | 4 +- question/engine/upgrade/upgradelib.php | 16 +- version.php | 2 +- 19 files changed, 1233 insertions(+), 970 deletions(-) delete mode 100755 local/qedatabase/db/install.php delete mode 100755 local/qedatabase/db/upgrade.php delete mode 100755 local/qedatabase/readme.txt delete mode 100755 local/qedatabase/version.php create mode 100644 mod/quiz/db/upgradelib.php diff --git a/lib/adminlib.php b/lib/adminlib.php index 6e4040b57bd7a..76088f6a54e77 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3762,6 +3762,35 @@ public function output_html($data, $query='') { } +/** + * Admin setting that allows a user to pick a behaviour. + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_setting_question_behaviour extends admin_setting_configselect { + /** + * @param string $name name of config variable + * @param string $visiblename display name + * @param string $description description + * @param string $default default. + */ + public function __construct($name, $visiblename, $description, $default) { + parent::__construct($name, $visiblename, $description, $default, NULL); + } + + /** + * Load list of behaviours as choices + * @return bool true => success, false => error. + */ + public function load_choices() { + global $CFG; + require_once($CFG->dirroot . '/question/engine/lib.php'); + $this->choices = question_engine::get_archetypal_behaviours(); + return true; + } +} + + /** * Admin setting that allows a user to pick appropriate roles for something. * diff --git a/lib/db/install.xml b/lib/db/install.xml index 27b3c1e5b19b2..ec6d941505667 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1279,9 +1279,9 @@ - - - + + + @@ -1300,7 +1300,7 @@ - +
@@ -1315,16 +1315,91 @@
- +
- - + + + + + + - + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
- +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index b47810c0c2cda..5317e705d8ed0 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6062,6 +6062,358 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2011022100.01); } + if ($oldversion < 2011051200) { + + // Changing the default of field penalty on table question to 0.3333333 + $table = new xmldb_table('question'); + $field = new xmldb_field('penalty'); + $field->set_attributes(XMLDB_TYPE_FLOAT, null, null, + XMLDB_NOTNULL, null, '0.3333333', 'defaultgrade'); + + // Launch change of default for field penalty + $dbman->change_field_default($table, $field); + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051200); + } + + if ($oldversion < 2011051201) { + + // Rename field defaultgrade on table question to defaultmark + $table = new xmldb_table('question'); + $field = new xmldb_field('defaultgrade'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '1', 'generalfeedback'); + + // Launch rename field defaultmark + if ($dbman->field_exists($table, $field)) { + $dbman->rename_field($table, $field, 'defaultmark'); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051201); + } + + if ($oldversion < 2011051202) { + + // Rename the question_attempts table to question_usages. + $table = new xmldb_table('question_attempts'); + if (!$dbman->table_exists('question_usages')) { + $dbman->rename_table($table, 'question_usages'); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051202); + } + + if ($oldversion < 2011051203) { + + // Rename the modulename field to component ... + $table = new xmldb_table('question_usages'); + $field = new xmldb_field('modulename'); + $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, + XMLDB_NOTNULL, null, null, 'contextid'); + + if ($dbman->field_exists($table, $field)) { + $dbman->rename_field($table, $field, 'component'); + } + + // ... and update its contents. + $DB->set_field('question_usages', 'component', 'mod_quiz', array('component' => 'quiz')); + + // Add the contextid field. + $field = new xmldb_field('contextid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null, 'id'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + + // And populate it. + $quizmoduleid = $DB->get_field('modules', 'id', array('name' => 'quiz')); + $DB->execute(" + UPDATE {question_usages} SET contextid = ( + SELECT ctx.id + FROM {context} ctx + JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = $quizmoduleid + JOIN {quiz_attempts} quiza ON quiza.quiz = cm.instance + WHERE ctx.contextlevel = " . CONTEXT_MODULE . " + AND quiza.uniqueid = {question_usages}.id + ) + "); + + // Then make it NOT NULL. + $field = new xmldb_field('contextid'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null, 'id'); + $dbman->change_field_notnull($table, $field); + } + + // Add the preferredbehaviour column. Populate it with a dummy value + // for now. We will fill in the appropriate behaviour name when + // updating all the rest of the attempt data. + $field = new xmldb_field('preferredbehaviour'); + if (!$dbman->field_exists($table, $field)) { + $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, + XMLDB_NOTNULL, null, 'to_be_set_later', 'component'); + $dbman->add_field($table, $field); + + // Then remove the default value, now the column is populated. + $field = new xmldb_field('preferredbehaviour'); + $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, + XMLDB_NOTNULL, null, null, 'component'); + $dbman->change_field_default($table, $field); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051203); + } + + if ($oldversion < 2011051204) { + + // Define key contextid (foreign) to be added to question_usages + $table = new xmldb_table('question_usages'); + $key = new XMLDBKey('contextid'); + $key->set_attributes(XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); + + // Launch add key contextid + $dbman->add_key($table, $key); + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051204); + } + + if ($oldversion < 2011051205) { + + // Changing precision of field component on table question_usages to (255) + // This was missed during the upgrade from old versions. + $table = new xmldb_table('question_usages'); + $field = new xmldb_field('component'); + $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, + XMLDB_NOTNULL, null, null, 'contextid'); + + // Launch change of precision for field component + $dbman->change_field_precision($table, $field); + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051205); + } + + if ($oldversion < 2011051206) { + + // Define table question_attempts to be created + $table = new xmldb_table('question_attempts'); + if (!$dbman->table_exists($table)) { + + // Adding fields to table question_attempts + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('questionusageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('behaviour', XMLDB_TYPE_CHAR, '32', null, + XMLDB_NOTNULL, null, null); + $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, + XMLDB_NOTNULL, null, null); + $table->add_field('minfraction', XMLDB_TYPE_NUMBER, '12, 7', null, + XMLDB_NOTNULL, null, null); + $table->add_field('flagged', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0'); + $table->add_field('questionsummary', XMLDB_TYPE_TEXT, 'small', null, + null, null, null); + $table->add_field('rightanswer', XMLDB_TYPE_TEXT, 'small', null, + null, null, null); + $table->add_field('responsesummary', XMLDB_TYPE_TEXT, 'small', null, + null, null, null); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + + // Adding keys to table question_attempts + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), + 'question', array('id')); + $table->add_key('questionusageid', XMLDB_KEY_FOREIGN, array('questionusageid'), + 'question_usages', array('id')); + + // Adding indexes to table question_attempts + $table->add_index('questionusageid-slot', XMLDB_INDEX_UNIQUE, + array('questionusageid', 'slot')); + + // Launch create table for question_attempts + $dbman->create_table($table); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051206); + } + + if ($oldversion < 2011051207) { + + // Define table question_attempt_steps to be created + $table = new xmldb_table('question_attempt_steps'); + if (!$dbman->table_exists($table)) { + + // Adding fields to table question_attempt_steps + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('questionattemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('sequencenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('state', XMLDB_TYPE_CHAR, '13', null, + XMLDB_NOTNULL, null, null); + $table->add_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, + null, null, null); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + null, null, null); + + // Adding keys to table question_attempt_steps + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('questionattemptid', XMLDB_KEY_FOREIGN, + array('questionattemptid'), 'question_attempts_new', array('id')); + $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), + 'user', array('id')); + + // Adding indexes to table question_attempt_steps + $table->add_index('questionattemptid-sequencenumber', XMLDB_INDEX_UNIQUE, + array('questionattemptid', 'sequencenumber')); + + // Launch create table for question_attempt_steps + $dbman->create_table($table); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051207); + } + + if ($oldversion < 2011051208) { + + // Define table question_attempt_step_data to be created + $table = new xmldb_table('question_attempt_step_data'); + if (!$dbman->table_exists($table)) { + + // Adding fields to table question_attempt_step_data + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('attemptstepid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, + XMLDB_NOTNULL, null, null); + $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, + null, null, null); + + // Adding keys to table question_attempt_step_data + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('attemptstepid', XMLDB_KEY_FOREIGN, array('attemptstepid'), + 'question_attempt_steps', array('id')); + + // Adding indexes to table question_attempt_step_data + $table->add_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, + array('attemptstepid', 'name')); + + // Launch create table for question_attempt_step_data + $dbman->create_table($table); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051208); + } + + if ($oldversion < 2011051209) { + + // Define table question_hints to be created + $table = new xmldb_table('question_hints'); + + // Adding fields to table question_hints + $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('hint', XMLDB_TYPE_TEXT, 'small', null, + XMLDB_NOTNULL, null, null); + $table->add_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0'); + $table->add_field('shownumcorrect', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('clearwrong', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, + null, null, null); + $table->add_field('options', XMLDB_TYPE_CHAR, '255', null, + null, null, null); + + // Adding keys to table question_hints + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), + 'question', array('id')); + + // Conditionally launch create table for question_hints + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051209); + } + + if ($oldversion < 2011051210) { + + // In the past, question_answer fractions were stored with rather + // sloppy rounding. Now update them to the new standard of 7 d.p. + $changes = array( + '-0.66666' => '-0.6666667', + '-0.33333' => '-0.3333333', + '-0.16666' => '-0.1666667', + '-0.142857' => '-0.1428571', + '0.11111' => '0.1111111', + '0.142857' => '0.1428571', + '0.16666' => '0.1666667', + '0.33333' => '0.3333333', + '0.333333' => '0.3333333', + '0.66666' => '0.6666667', + ); + foreach ($changes as $from => $to) { + $DB->set_field('question_answers', + 'fraction', $to, array('fraction' => $from)); + } + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051210); + } + + if ($oldversion < 2011051211) { + + // In the past, question penalties were stored with rather + // sloppy rounding. Now update them to the new standard of 7 d.p. + $DB->set_field('question', + 'penalty', 0.3333333, array('penalty' => 33.3)); + $DB->set_field_select('question', + 'penalty', 0.3333333, 'penalty >= 0.33 AND penalty <= 0.34'); + $DB->set_field_select('question', + 'penalty', 0.6666667, 'penalty >= 0.66 AND penalty <= 0.67'); + $DB->set_field_select('question', + 'penalty', 1, 'penalty > 1'); + + // quiz savepoint reached + upgrade_main_savepoint(true, 2011051211); + } + + if ($oldversion < 2011051212) { + + // Define field hintformat to be added to question_hints table. + $table = new xmldb_table('question_hints'); + $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0'); + + // Conditionally launch add field partiallycorrectfeedbackformat + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_main_savepoint(true, 2011051212); + } return true; } diff --git a/local/qedatabase/db/install.php b/local/qedatabase/db/install.php deleted file mode 100755 index 56401da87034d..0000000000000 --- a/local/qedatabase/db/install.php +++ /dev/null @@ -1,696 +0,0 @@ -get_manager(); - - // Bit of a hack to prevent errors like "Cannot downgrade local_qedatabase from ... to ...". - $oldversion = 2008000000; - $DB->set_field('config_plugins', 'value', $oldversion, - array('plugin' => 'local_qedatabase', 'name' => 'version')); - - // Add new preferredbehaviour column to the quiz table. - if ($oldversion < 2008000100) { - $table = new xmldb_table('quiz'); - $field = new xmldb_field('preferredbehaviour'); - $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, null, null, null, 'timeclose'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000100, 'local', 'qedatabase'); - } - - // Populate preferredbehaviour column based on old optionflags column. - if ($oldversion < 2008000101) { - $DB->set_field_select('quiz', 'preferredbehaviour', 'deferredfeedback', - 'optionflags = 0'); - $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptive', - 'optionflags <> 0 AND penaltyscheme <> 0'); - $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty', - 'optionflags <> 0 AND penaltyscheme = 0'); - - set_config('preferredbehaviour', 'deferredfeedback', 'quiz'); - set_config('fix_preferredbehaviour', 0, 'quiz'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000101, 'local', 'qedatabase'); - } - - // Add a not-NULL constraint to the preferredmodel field now that it is populated. - if ($oldversion < 2008000102) { - $table = new xmldb_table('quiz'); - $field = new xmldb_field('preferredbehaviour'); - $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'timeclose'); - - $dbman->change_field_notnull($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000102, 'local', 'qedatabase'); - } - - // Drop the old optionflags field. - if ($oldversion < 2008000103) { - $table = new xmldb_table('quiz'); - $field = new xmldb_field('optionflags'); - $dbman->drop_field($table, $field); - - unset_config('optionflags', 'quiz'); - unset_config('fix_optionflags', 'quiz'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000103, 'local', 'qedatabase'); - } - - // Drop the old penaltyscheme field. - if ($oldversion < 2008000104) { - $table = new xmldb_table('quiz'); - $field = new xmldb_field('penaltyscheme'); - $dbman->drop_field($table, $field); - - unset_config('penaltyscheme', 'quiz'); - unset_config('fix_penaltyscheme', 'quiz'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000104, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000110) { - - // Changing nullability of field sumgrades on table quiz_attempts to null - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('sumgrades'); - $field->set_attributes(XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'attempt'); - - // Launch change of nullability for field sumgrades - $dbman->change_field_notnull($table, $field); - - // Launch change of default for field sumgrades - $dbman->change_field_default($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000110, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000111) { - - // Changing the default of field penalty on table question to 0.3333333 - $table = new xmldb_table('question'); - $field = new xmldb_field('penalty'); - $field->set_attributes(XMLDB_TYPE_FLOAT, null, null, XMLDB_NOTNULL, null, '0.3333333', 'defaultgrade'); - - // Launch change of default for field penalty - $dbman->change_field_default($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000111, 'local', 'qedatabase'); - } - -// Update the quiz from the old single review column to seven new columns. - - if ($oldversion < 2008000200) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewattempt'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'review'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000200, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000201) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewcorrectness'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewattempt'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000201, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000202) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewmarks'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewcorrectness'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000202, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000203) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewspecificfeedback'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewmarks'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000203, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000204) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewgeneralfeedback'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewspecificfeedback'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000204, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000205) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewrightanswer'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewgeneralfeedback'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000205, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000206) { - - // Define field reviewattempt to be added to quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('reviewoverallfeedback'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'reviewrightanswer'); - - // Launch add field reviewattempt - $dbman->add_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000206, 'local', 'qedatabase'); - } - - define('QUIZ_NEW_DURING', 0x10000); - define('QUIZ_NEW_IMMEDIATELY_AFTER', 0x01000); - define('QUIZ_NEW_LATER_WHILE_OPEN', 0x00100); - define('QUIZ_NEW_AFTER_CLOSE', 0x00010); - - define('QUIZ_OLD_IMMEDIATELY', 0x3c003f); - define('QUIZ_OLD_OPEN', 0x3c00fc0); - define('QUIZ_OLD_CLOSED', 0x3c03f000); - - define('QUIZ_OLD_RESPONSES', 1*0x1041); // Show responses - define('QUIZ_OLD_SCORES', 2*0x1041); // Show scores - define('QUIZ_OLD_FEEDBACK', 4*0x1041); // Show question feedback - define('QUIZ_OLD_ANSWERS', 8*0x1041); // Show correct answers - define('QUIZ_OLD_SOLUTIONS', 16*0x1041); // Show solutions - define('QUIZ_OLD_GENERALFEEDBACK',32*0x1041); // Show question general feedback - define('QUIZ_OLD_OVERALLFEEDBACK', 1*0x4440000); // Show quiz overall feedback - - // Copy the old review settings - if ($oldversion < 2008000210) { - $DB->execute(" - UPDATE {quiz} - SET reviewattempt = " . $DB->sql_bitor($DB->sql_bitor( - QUIZ_NEW_DURING, - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000210, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000211) { - $DB->execute(" - UPDATE {quiz} - SET reviewcorrectness = " . $DB->sql_bitor($DB->sql_bitor( - QUIZ_NEW_DURING, - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000211, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000212) { - $DB->execute(" - UPDATE {quiz} - SET reviewmarks = " . $DB->sql_bitor($DB->sql_bitor( - QUIZ_NEW_DURING, - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000212, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000213) { - $DB->execute(" - UPDATE {quiz} - SET reviewspecificfeedback = " . $DB->sql_bitor($DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000213, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000214) { - $DB->execute(" - UPDATE {quiz} - SET reviewgeneralfeedback = " . $DB->sql_bitor($DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000214, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000215) { - $DB->execute(" - UPDATE {quiz} - SET reviewrightanswer = " . $DB->sql_bitor($DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . - ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000215, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000216) { - $DB->execute(" - UPDATE {quiz} - SET reviewoverallfeedback = " . $DB->sql_bitor($DB->sql_bitor( - 0, - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', - 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK) . - ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " - "); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000216, 'local', 'qedatabase'); - } - - // And, do the same for the defaults - if ($oldversion < 2008000217) { - if (empty($CFG->quiz_review)) { - $CFG->quiz_review = 0; - } - - set_config('reviewattempt', - QUIZ_NEW_DURING | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewcorrectness', - QUIZ_NEW_DURING | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewmarks', - QUIZ_NEW_DURING | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewspecificfeedback', - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewgeneralfeedback', - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewrightanswer', - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - set_config('reviewoverallfeedback', - 0 | - ($CFG->quiz_review & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | - ($CFG->quiz_review & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | - ($CFG->quiz_review & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), - 'quiz'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000217, 'local', 'qedatabase'); - } - - // Finally drop the old column - if ($oldversion < 2008000220) { - // Define field review to be dropped from quiz - $table = new xmldb_table('quiz'); - $field = new xmldb_field('review'); - - // Launch drop field review - $dbman->drop_field($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000220, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000221) { - unset_config('review', 'quiz'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000221, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000501) { - - // Rename field defaultgrade on table question to defaultmark - $table = new xmldb_table('question'); - $field = new xmldb_field('defaultgrade'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'generalfeedback'); - - // Launch rename field defaultmark - $dbman->rename_field($table, $field, 'defaultmark'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000501, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000505) { - - // Rename the question_attempts table to question_usages. - $table = new xmldb_table('question_attempts'); - if ($dbman->table_exists($table)) { - $dbman->rename_table($table, 'question_usages'); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000505, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000507) { - - // Rename the modulename field to component ... - $table = new xmldb_table('question_usages'); - $field = new xmldb_field('modulename'); - $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'contextid'); - $dbman->rename_field($table, $field, 'component'); - - // ... and update its contents. - $DB->set_field('question_usages', 'component', 'mod_quiz', array('component' => 'quiz')); - - // Add the contextid field. - $field = new xmldb_field('contextid'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'id'); - $dbman->add_field($table, $field); - - // And populate it. - $quizmoduleid = $DB->get_field('modules', 'id', array('name' => 'quiz')); - $DB->execute(" - UPDATE {question_usages} SET contextid = ( - SELECT ctx.id - FROM {context} ctx - JOIN {course_modules} cm ON cm.id = ctx.instanceid AND cm.module = $quizmoduleid - JOIN {quiz_attempts} quiza ON quiza.quiz = cm.instance - WHERE ctx.contextlevel = " . CONTEXT_MODULE . " - AND quiza.uniqueid = {question_usages}.id - ) - "); - - // Then make it NOT NULL. - $field = new xmldb_field('contextid'); - $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'id'); - $dbman->change_field_notnull($table, $field); - - // Add the preferredbehaviour column. Populate it with a dummy value - // for now. We will fill in the appropriate behaviour name when - // updating all the rest of the attempt data. - $field = new xmldb_field('preferredbehaviour'); - $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, 'to_be_set_later', 'component'); - $dbman->add_field($table, $field); - - // Then remove the default value, now the column is populated. - $field = new xmldb_field('preferredbehaviour'); - $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, 'component'); - $dbman->change_field_default($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000507, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000513) { - - // Define key contextid (foreign) to be added to question_usages - $table = new xmldb_table('question_usages'); - $key = new XMLDBKey('contextid'); - $key->set_attributes(XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); - - // Launch add key contextid - $dbman->add_key($table, $key); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000513, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000514) { - - // Changing precision of field component on table question_usages to (255) - // This was missed during the upgrade from old versions. - $table = new xmldb_table('question_usages'); - $field = new xmldb_field('component'); - $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'contextid'); - - // Launch change of precision for field component - $dbman->change_field_precision($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000514, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000520) { - - // Define table question_attempts to be created - $table = new xmldb_table('question_attempts'); - if (!$dbman->table_exists($table)) { - - // Adding fields to table question_attempts - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('questionusageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('behaviour', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); - $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null); - $table->add_field('minfraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, null); - $table->add_field('flagged', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); - $table->add_field('questionsummary', XMLDB_TYPE_TEXT, 'small', null, null, null, null); - $table->add_field('rightanswer', XMLDB_TYPE_TEXT, 'small', null, null, null, null); - $table->add_field('responsesummary', XMLDB_TYPE_TEXT, 'small', null, null, null, null); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - - // Adding keys to table question_attempts - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); - $table->add_key('questionusageid', XMLDB_KEY_FOREIGN, array('questionusageid'), 'question_usages', array('id')); - - // Adding indexes to table question_attempts - $table->add_index('questionusageid-slot', XMLDB_INDEX_UNIQUE, array('questionusageid', 'slot')); - - // Launch create table for question_attempts - $dbman->create_table($table); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000520, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000521) { - - // Define table question_attempt_steps to be created - $table = new xmldb_table('question_attempt_steps'); - if (!$dbman->table_exists($table)) { - - // Adding fields to table question_attempt_steps - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('questionattemptid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('sequencenumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('state', XMLDB_TYPE_CHAR, '13', null, XMLDB_NOTNULL, null, null); - $table->add_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); - $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); - - // Adding keys to table question_attempt_steps - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('questionattemptid', XMLDB_KEY_FOREIGN, array('questionattemptid'), 'question_attempts_new', array('id')); - $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - - // Adding indexes to table question_attempt_steps - $table->add_index('questionattemptid-sequencenumber', XMLDB_INDEX_UNIQUE, array('questionattemptid', 'sequencenumber')); - - // Launch create table for question_attempt_steps - $dbman->create_table($table); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000521, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000522) { - - // Define table question_attempt_step_data to be created - $table = new xmldb_table('question_attempt_step_data'); - if (!$dbman->table_exists($table)) { - - // Adding fields to table question_attempt_step_data - $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); - $table->add_field('attemptstepid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); - $table->add_field('name', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); - $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); - - // Adding keys to table question_attempt_step_data - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('attemptstepid', XMLDB_KEY_FOREIGN, array('attemptstepid'), 'question_attempt_steps', array('id')); - - // Adding indexes to table question_attempt_step_data - $table->add_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name')); - - // Launch create table for question_attempt_step_data - $dbman->create_table($table); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000522, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000600) { - - // Define table question_hints to be created - $table = new xmldb_table('question_hints'); - - // Adding fields to table question_hints - $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('hint', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); - $table->add_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); - $table->add_field('shownumcorrect', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); - $table->add_field('clearwrong', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); - $table->add_field('options', XMLDB_TYPE_CHAR, '255', null, null, null, null); - - // Adding keys to table question_hints - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id')); - - // Conditionally launch create table for question_hints - if (!$dbman->table_exists($table)) { - $dbman->create_table($table); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000600, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000601) { - - // In the past, question_answer fractions were stored with rather - // sloppy rounding. Now update them to the new standard of 7 d.p. - $changes = array( - '-0.66666' => '-0.6666667', - '-0.33333' => '-0.3333333', - '-0.16666' => '-0.1666667', - '-0.142857' => '-0.1428571', - '0.11111' => '0.1111111', - '0.142857' => '0.1428571', - '0.16666' => '0.1666667', - '0.33333' => '0.3333333', - '0.333333' => '0.3333333', - '0.66666' => '0.6666667', - ); - foreach ($changes as $from => $to) { - $DB->set_field('question_answers', - 'fraction', $to, array('fraction' => $from)); - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000601, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000602) { - - // In the past, question penalties were stored with rather - // sloppy rounding. Now update them to the new standard of 7 d.p. - $DB->set_field('question', - 'penalty', 0.3333333, array('penalty' => 33.3)); - $DB->set_field_select('question', - 'penalty', 0.3333333, 'penalty >= 0.33 AND penalty <= 0.34'); - $DB->set_field_select('question', - 'penalty', 0.6666667, 'penalty >= 0.66 AND penalty <= 0.67'); - $DB->set_field_select('question', - 'penalty', 1, 'penalty > 1'); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000602, 'local', 'qedatabase'); - } -} diff --git a/local/qedatabase/db/upgrade.php b/local/qedatabase/db/upgrade.php deleted file mode 100755 index d4564e63d2d74..0000000000000 --- a/local/qedatabase/db/upgrade.php +++ /dev/null @@ -1,110 +0,0 @@ -get_manager(); - - if ($oldversion < 2008000700) { - - // Define field hintformat to be added to question_hints table. - $table = new xmldb_table('question_hints'); - $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); - - // Conditionally launch add field partiallycorrectfeedbackformat - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_plugin_savepoint(true, 2008000700, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000701) { - // Define table quiz_report to be renamed to quiz_reports - $table = new xmldb_table('quiz_report'); - - // Launch rename table for quiz_reports - if ($dbman->table_exists($table)) { - $dbman->rename_table($table, 'quiz_reports'); - } - - upgrade_plugin_savepoint(true, 2008000701, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000702) { - // Define index name (unique) to be added to quiz_reports - $table = new xmldb_table('quiz_reports'); - $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); - - // Conditionally launch add index name - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - upgrade_plugin_savepoint(true, 2008000702, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000703) { - // Rename the quiz_report table to quiz_reports. - $table = new xmldb_table('quiz_report'); - if ($dbman->table_exists($table)) { - $dbman->rename_table($table, 'quiz_reports'); - } - - upgrade_plugin_savepoint(true, 2008000703, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000704) { - - // Changing nullability of field sumgrades on table quiz_attempts to null - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'attempt'); - - // Launch change of nullability for field sumgrades - $dbman->change_field_notnull($table, $field); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000704, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000799) { - // Define field needsupgradetonewqe to be added to quiz_attempts - $table = new xmldb_table('quiz_attempts'); - $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'preview'); - - // Launch add field needsupgradetonewqe - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1); - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000800, 'local', 'qedatabase'); - } - - if ($oldversion < 2008000800) { - $table = new xmldb_table('question_states'); - if ($dbman->table_exists($table)) { - // First delete all data from preview attempts. - $DB->delete_records_select('question_states', - "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); - $DB->delete_records_select('question_sessions', - "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); - $DB->delete_records('quiz_attempts', array('preview' => 1)); - - // Now update all the old attempt data. - $oldrcachesetting = $CFG->rcache; - $CFG->rcache = false; - - require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php'); - $upgrader = new question_engine_attempt_upgrader(); - $upgrader->convert_all_quiz_attempts(); - - $CFG->rcache = $oldrcachesetting; - } - - // quiz savepoint reached - upgrade_plugin_savepoint(true, 2008000800, 'local', 'qedatabase'); - } -} diff --git a/local/qedatabase/readme.txt b/local/qedatabase/readme.txt deleted file mode 100755 index d77cb903500dd..0000000000000 --- a/local/qedatabase/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -This local plugin exists simply to create and update the database as required -by the new Question Engine. diff --git a/local/qedatabase/version.php b/local/qedatabase/version.php deleted file mode 100755 index a953b788efd10..0000000000000 --- a/local/qedatabase/version.php +++ /dev/null @@ -1,30 +0,0 @@ -. - -/** - * Question engine database upgrade version information - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -$plugin->version = 2008000800; -$plugin->requires = 2010080300; diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 563bc2bbfb8d6..749f397e62427 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -374,12 +374,6 @@ public function __construct($attempt, $quiz, $cm, $course) { protected static function create_helper($conditions) { global $DB; - // TODO deal with the issue that makes this necessary. - // if (!$DB->record_exists('question_sessions', array('attemptid' => $attempt->uniqueid))) { - // // this attempt has not yet been upgraded to the new model - // quiz_upgrade_states($attempt); - // } - $attempt = $DB->get_record('quiz_attempts', $conditions, '*', MUST_EXIST); $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); diff --git a/mod/quiz/db/install.php b/mod/quiz/db/install.php index 60fbb487136ef..68be5cb4611f1 100644 --- a/mod/quiz/db/install.php +++ b/mod/quiz/db/install.php @@ -36,15 +36,15 @@ function xmldb_quiz_install() { $record = new stdClass(); $record->name = 'overview'; $record->displayorder = '10000'; - $DB->insert_record('quiz_report', $record); + $DB->insert_record('quiz_reports', $record); $record = new stdClass(); $record->name = 'responses'; $record->displayorder = '9000'; - $DB->insert_record('quiz_report', $record); + $DB->insert_record('quiz_reports', $record); $record = new stdClass(); $record->name = 'grading'; $record->displayorder = '6000'; - $DB->insert_record('quiz_report', $record); + $DB->insert_record('quiz_reports', $record); } diff --git a/mod/quiz/db/install.xml b/mod/quiz/db/install.xml index a8b41442595f5..1e8ac64956fae 100644 --- a/mod/quiz/db/install.xml +++ b/mod/quiz/db/install.xml @@ -1,5 +1,5 @@ - @@ -7,36 +7,40 @@
- - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -48,16 +52,17 @@
- - - - - - - - - - + + + + + + + + + + + @@ -97,7 +102,7 @@
- +
@@ -111,20 +116,7 @@
- - - - - - - - - - - - -
- +
@@ -143,5 +135,18 @@
+ + + + + + + + + + + + +
- \ No newline at end of file + diff --git a/mod/quiz/db/upgrade.php b/mod/quiz/db/upgrade.php index 41ea3084b84c2..258d14b74d505 100644 --- a/mod/quiz/db/upgrade.php +++ b/mod/quiz/db/upgrade.php @@ -541,6 +541,610 @@ function xmldb_quiz_upgrade($oldversion) { upgrade_mod_savepoint(true, 2010122304, 'quiz'); } + // Complete any old upgrade from 1.5 that was never finished. + if ($oldversion < 2011051199) { + $table = new xmldb_table('question_states'); + if ($dbman->table_exists($table)) { + $transaction = $DB->start_delegated_transaction(); + + $oldattempts = $DB->get_records_sql(' + SELECT quiza + FROM {quiz_attempts} quiza + WHERE uniqueid IN ( + SELECT DISTINCT qst.attempt + FROM {question_states} qst + LEFT JOIN {question_sessions} qsess ON + qst.question = qsess.questionid AND qst.attempt = qsess.attemptid + WHERE qsess.id IS NULL + ) + '); + + if ($oldattempts) { + $pbar = new progress_bar('q15upgrade'); + $a = new stdClass(); + $a->todo = count($oldattempts); + $a->done = 0; + $pbar->update($a->done, $a->todo, + get_string('upgradingveryoldquizattempts', 'quiz', $a)); + + foreach ($oldattempts as $oldattempt) { + quiz_upgrade_very_old_question_sessions($oldattempt); + + $a->done += 1; + $pbar->update($a->done, $a->todo, + get_string('upgradingveryoldquizattempts', 'quiz', $a)); + } + } + + $transaction->allow_commit(); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051199, 'quiz'); + } + + // Add new preferredbehaviour column to the quiz table. + if ($oldversion < 2011051200) { + $table = new xmldb_table('quiz'); + $field = new xmldb_field('preferredbehaviour'); + $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, + null, null, null, 'timeclose'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051200, 'quiz'); + } + + // Populate preferredbehaviour column based on old optionflags column. + if ($oldversion < 2011051201) { + if ($dbman->field_exists('quiz', 'optionflags')) { + $DB->set_field_select('quiz', 'preferredbehaviour', 'deferredfeedback', + 'optionflags = 0'); + $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptive', + 'optionflags <> 0 AND penaltyscheme <> 0'); + $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty', + 'optionflags <> 0 AND penaltyscheme = 0'); + + set_config('preferredbehaviour', 'deferredfeedback', 'quiz'); + set_config('fix_preferredbehaviour', 0, 'quiz'); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051201, 'quiz'); + } + + // Add a not-NULL constraint to the preferredmodel field now that it is populated. + if ($oldversion < 2011051202) { + $table = new xmldb_table('quiz'); + $field = new xmldb_field('preferredbehaviour'); + $field->set_attributes(XMLDB_TYPE_CHAR, '32', null, + XMLDB_NOTNULL, null, null, 'timeclose'); + + $dbman->change_field_notnull($table, $field); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051202, 'quiz'); + } + + // Drop the old optionflags field. + if ($oldversion < 2011051203) { + $table = new xmldb_table('quiz'); + $field = new xmldb_field('optionflags'); + + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + unset_config('optionflags', 'quiz'); + unset_config('fix_optionflags', 'quiz'); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051203, 'quiz'); + } + + // Drop the old penaltyscheme field. + if ($oldversion < 2011051204) { + $table = new xmldb_table('quiz'); + $field = new xmldb_field('penaltyscheme'); + + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + unset_config('penaltyscheme', 'quiz'); + unset_config('fix_penaltyscheme', 'quiz'); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051204, 'quiz'); + } + + if ($oldversion < 2011051205) { + + // Changing nullability of field sumgrades on table quiz_attempts to null + $table = new xmldb_table('quiz_attempts'); + $field = new xmldb_field('sumgrades'); + $field->set_attributes(XMLDB_TYPE_NUMBER, '10, 5', null, + null, null, null, 'attempt'); + + // Launch change of nullability for field sumgrades + $dbman->change_field_notnull($table, $field); + + // Launch change of default for field sumgrades + $dbman->change_field_default($table, $field); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051205, 'quiz'); + } + + if ($oldversion < 2011051206) { + + // Changing the default of field penalty on table question to 0.3333333 + $table = new xmldb_table('question'); + $field = new xmldb_field('penalty'); + $field->set_attributes(XMLDB_TYPE_FLOAT, null, null, + XMLDB_NOTNULL, null, '0.3333333', 'defaultgrade'); + + // Launch change of default for field penalty + $dbman->change_field_default($table, $field); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051206, 'quiz'); + } + +// Update the quiz from the old single review column to seven new columns. + + if ($oldversion < 2011051207) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewattempt'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'review'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051207, 'quiz'); + } + + if ($oldversion < 2011051208) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewcorrectness'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewattempt'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051208, 'quiz'); + } + + if ($oldversion < 2011051209) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewmarks'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewcorrectness'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051209, 'quiz'); + } + + if ($oldversion < 2011051210) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewspecificfeedback'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewmarks'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051210, 'quiz'); + } + + if ($oldversion < 2011051211) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewgeneralfeedback'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewspecificfeedback'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051211, 'quiz'); + } + + if ($oldversion < 2011051212) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewrightanswer'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewgeneralfeedback'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051212, 'quiz'); + } + + if ($oldversion < 2011051213) { + + // Define field reviewattempt to be added to quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('reviewoverallfeedback'); + $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'reviewrightanswer'); + + // Launch add field reviewattempt + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051213, 'quiz'); + } + + define('QUIZ_NEW_DURING', 0x10000); + define('QUIZ_NEW_IMMEDIATELY_AFTER', 0x01000); + define('QUIZ_NEW_LATER_WHILE_OPEN', 0x00100); + define('QUIZ_NEW_AFTER_CLOSE', 0x00010); + + define('QUIZ_OLD_IMMEDIATELY', 0x3c003f); + define('QUIZ_OLD_OPEN', 0x3c00fc0); + define('QUIZ_OLD_CLOSED', 0x3c03f000); + + define('QUIZ_OLD_RESPONSES', 1*0x1041); // Show responses + define('QUIZ_OLD_SCORES', 2*0x1041); // Show scores + define('QUIZ_OLD_FEEDBACK', 4*0x1041); // Show question feedback + define('QUIZ_OLD_ANSWERS', 8*0x1041); // Show correct answers + define('QUIZ_OLD_SOLUTIONS', 16*0x1041); // Show solutions + define('QUIZ_OLD_GENERALFEEDBACK',32*0x1041); // Show question general feedback + define('QUIZ_OLD_OVERALLFEEDBACK', 1*0x4440000); // Show quiz overall feedback + + // Copy the old review settings + if ($oldversion < 2011051214) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewattempt = " . $DB->sql_bitor($DB->sql_bitor( + QUIZ_NEW_DURING, + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051214, 'quiz'); + } + + if ($oldversion < 2011051215) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewcorrectness = " . $DB->sql_bitor($DB->sql_bitor( + QUIZ_NEW_DURING, + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051215, 'quiz'); + } + + if ($oldversion < 2011051216) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewmarks = " . $DB->sql_bitor($DB->sql_bitor( + QUIZ_NEW_DURING, + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051216, 'quiz'); + } + + if ($oldversion < 2011051217) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewspecificfeedback = " . $DB->sql_bitor($DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051217, 'quiz'); + } + + if ($oldversion < 2011051218) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewgeneralfeedback = " . $DB->sql_bitor($DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051218, 'quiz'); + } + + if ($oldversion < 2011051219) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewrightanswer = " . $DB->sql_bitor($DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . + ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051219, 'quiz'); + } + + if ($oldversion < 2011051220) { + if ($dbman->field_exists('quiz', 'review')) { + $DB->execute(" + UPDATE {quiz} + SET reviewoverallfeedback = " . $DB->sql_bitor($DB->sql_bitor( + 0, + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor( + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END', + 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK) . + ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . " + "); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051220, 'quiz'); + } + + // And, do the same for the defaults + if ($oldversion < 2011051221) { + $quizrevew = get_config('quiz', 'review'); + if (!empty($quizrevew)) { + + set_config('reviewattempt', + QUIZ_NEW_DURING | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewcorrectness', + QUIZ_NEW_DURING | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewmarks', + QUIZ_NEW_DURING | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewspecificfeedback', + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewgeneralfeedback', + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewrightanswer', + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + + set_config('reviewoverallfeedback', + 0 | + ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) | + ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) | + ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0), + 'quiz'); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051221, 'quiz'); + } + + // Finally drop the old column + if ($oldversion < 2011051222) { + // Define field review to be dropped from quiz + $table = new xmldb_table('quiz'); + $field = new xmldb_field('review'); + + // Launch drop field review + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051222, 'quiz'); + } + + if ($oldversion < 2011051223) { + unset_config('review', 'quiz'); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051223, 'quiz'); + } + + if ($oldversion < 2011051224) { + + // Define field hintformat to be added to question_hints table. + $table = new xmldb_table('question_hints'); + $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0'); + + // Conditionally launch add field partiallycorrectfeedbackformat + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_mod_savepoint(true, 2011051224, 'quiz'); + } + + if ($oldversion < 2011051225) { + // Define table quiz_report to be renamed to quiz_reports + $table = new xmldb_table('quiz_report'); + + // Launch rename table for quiz_reports + if ($dbman->table_exists($table)) { + $dbman->rename_table($table, 'quiz_reports'); + } + + upgrade_mod_savepoint(true, 2011051225, 'quiz'); + } + + if ($oldversion < 2011051226) { + // Define index name (unique) to be added to quiz_reports + $table = new xmldb_table('quiz_reports'); + $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); + + // Conditionally launch add index name + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_mod_savepoint(true, 2011051226, 'quiz'); + } + + if ($oldversion < 2011051227) { + + // Changing nullability of field sumgrades on table quiz_attempts to null + $table = new xmldb_table('quiz_attempts'); + $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, + null, null, null, 'attempt'); + + // Launch change of nullability for field sumgrades + $dbman->change_field_notnull($table, $field); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051227, 'quiz'); + } + + if ($oldversion < 2011051228) { + // Define field needsupgradetonewqe to be added to quiz_attempts + $table = new xmldb_table('quiz_attempts'); + $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, + XMLDB_NOTNULL, null, '0', 'preview'); + + // Launch add field needsupgradetonewqe + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1); + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051228, 'quiz'); + } + + if ($oldversion < 2011051229) { + $table = new xmldb_table('question_states'); + if ($dbman->table_exists($table)) { + // First delete all data from preview attempts. + $DB->delete_records_select('question_states', + "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); + $DB->delete_records_select('question_sessions', + "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)"); + $DB->delete_records('quiz_attempts', array('preview' => 1)); + + // Now update all the old attempt data. + $oldrcachesetting = $CFG->rcache; + $CFG->rcache = false; + + require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php'); + $upgrader = new question_engine_attempt_upgrader(); + $upgrader->convert_all_quiz_attempts(); + + $CFG->rcache = $oldrcachesetting; + } + + // quiz savepoint reached + upgrade_mod_savepoint(true, 2011051229, 'quiz'); + } + return true; } diff --git a/mod/quiz/db/upgradelib.php b/mod/quiz/db/upgradelib.php new file mode 100644 index 0000000000000..bc2874dda0ada --- /dev/null +++ b/mod/quiz/db/upgradelib.php @@ -0,0 +1,76 @@ +. + +/** + * Upgrade helper code for the quiz module. + * + * @package mod + * @subpackage quiz + * @copyright 2006 Eloy Lafuente (stronk7) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + + +/** + * Upgrade states for an attempt to Moodle 1.5 model + * + * Any state that does not yet have its timestamp set to nonzero has not yet been + * upgraded from Moodle 1.4. The reason these are still around is that for large + * sites it would have taken too long to upgrade all states at once. This function + * sets the timestamp field and creates an entry in the question_sessions table. + * @param object $attempt The attempt whose states need upgrading + */ +function quiz_upgrade_very_old_question_sessions($attempt) { + global $DB; + // The old quiz model only allowed a single response per quiz attempt so that there will be + // only one state record per question for this attempt. + + // We set the timestamp of all states to the timemodified field of the attempt. + $DB->execute("UPDATE {question_states} SET timestamp = ? WHERE attempt = ?", + array($attempt->timemodified, $attempt->uniqueid)); + + // For each state we create an entry in the question_sessions table, with both newest and + // newgraded pointing to this state. + // Actually we only do this for states whose question is actually listed in $attempt->layout. + // We do not do it for states associated to wrapped questions like for example the questions + // used by a RANDOM question + $session = new stdClass(); + $session->attemptid = $attempt->uniqueid; + $session->sumpenalty = 0; + $session->manualcomment = ''; + $session->manualcommentformat = FORMAT_HTML; + $session->flagged = 0; + + $questionlist = str_replace(',0', '', quiz_clean_layout($layout, true)); + if (!$questionlist) { + return; + } + list($usql, $question_params) = $DB->get_in_or_equal(explode(',', $questionlist)); + $params = array_merge(array($attempt->uniqueid), $question_params); + + if ($states = $DB->get_records_select('question_states', + "attempt = ? AND question $usql", $params)) { + foreach ($states as $state) { + $session->newgraded = $state->id; + $session->newest = $state->id; + $session->questionid = $state->question; + $DB->insert_record('question_sessions', $session, false); + } + } +} diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 9bd1bc849ed80..f260a85b16112 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -347,6 +347,7 @@ $string['hidebreaks'] = 'Hide page breaks'; $string['hidereordertool'] = 'Hide the reordering tool'; $string['history'] = 'History of responses:'; +$string['howquestionsbehave_desc'] = 'Default setting for how questions behave in a quiz.'; $string['imagedisplay'] = 'Image to display'; $string['import'] = 'Import'; $string['import_help'] = 'This function allows you to import questions from external text files. @@ -768,6 +769,8 @@ $string['updatingfinalgrades'] = 'Updating final grades.'; $string['updatingthegradebook'] = 'Updating the gradebook.'; $string['upgradesure'] = '
In particular the quiz module will perform an extensive change of the quiz tables and this upgrade has not yet been sufficiently tested. You are very strongly urged to backup your database tables before proceeding.
'; +$string['upgradingquizattempts'] = 'Upgrading quiz attempts: quiz {$a->done}/{$a->outof} (Quiz id {$a->info})'; +$string['upgradingveryoldquizattempts'] = 'Upgrading very old quiz attempts: {$a->done}/{$a->outof}'; $string['url'] = 'URL'; $string['usedcategorymoved'] = 'This category has been preserved and moved to the site level because it is a published category still in use by other courses.'; $string['useroverrides'] = 'User overrides'; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 620abc52ca924..45b171318ec7e 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -820,47 +820,6 @@ function quiz_get_grading_option_name($option) { /// Other quiz functions //////////////////////////////////////////////////// -/** - * Upgrade states for an attempt to Moodle 1.5 model - * - * Any state that does not yet have its timestamp set to nonzero has not yet been - * upgraded from Moodle 1.4. The reason these are still around is that for large - * sites it would have taken too long to upgrade all states at once. This function - * sets the timestamp field and creates an entry in the question_sessions table. - * @param object $attempt The attempt whose states need upgrading - */ -function quiz_upgrade_states($attempt) { - global $DB; - // The old quiz model only allowed a single response per quiz attempt so that there will be - // only one state record per question for this attempt. - - // We set the timestamp of all states to the timemodified field of the attempt. - $DB->execute("UPDATE {question_states} SET timestamp = ? WHERE attempt = ?", - array($attempt->timemodified, $attempt->uniqueid)); - - // For each state we create an entry in the question_sessions table, with both newest and - // newgraded pointing to this state. - // Actually we only do this for states whose question is actually listed in $attempt->layout. - // We do not do it for states associated to wrapped questions like for example the questions - // used by a RANDOM question - $session = new stdClass(); - $session->attemptid = $attempt->uniqueid; - $questionlist = quiz_questions_in_quiz($attempt->layout); - $params = array($attempt->uniqueid); - list($usql, $question_params) = $DB->get_in_or_equal(explode(',', $questionlist)); - $params = array_merge($params, $question_params); - - if ($questionlist and $states = $DB->get_records_select('question_states', - "attempt = ? AND question $usql", $params)) { - foreach ($states as $state) { - $session->newgraded = $state->id; - $session->newest = $state->id; - $session->questionid = $state->question; - $DB->insert_record('question_sessions', $session, false); - } - } -} - /** * @param object $quiz the quiz. * @param int $cmid the course_module object for this quiz. diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 95e2bc894ac9c..4b84862a4138c 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -154,8 +154,7 @@ protected function definition() { $behaviours = question_engine::get_behaviour_options($currentbehaviour); $mform->addElement('select', 'preferredbehaviour', get_string('howquestionsbehave', 'question'), $behaviours); $mform->addHelpButton('preferredbehaviour', 'howquestionsbehave', 'question'); - $mform->setAdvanced('preferredbehaviour', $CFG->quiz_fix_preferredbehaviour); - $mform->setDefault('preferredbehaviour', $CFG->quiz_preferredbehaviour); + $mform->setDefault('preferredbehaviour', $quizconfig->preferredbehaviour); /// Each attempt builds on last. $mform->addElement('selectyesno', 'attemptonlast', get_string('eachattemptbuildsonthelast', 'quiz')); diff --git a/mod/quiz/settings.php b/mod/quiz/settings.php index 88511ae7480ac..8bbb14b666d68 100644 --- a/mod/quiz/settings.php +++ b/mod/quiz/settings.php @@ -103,15 +103,10 @@ get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'), array('value' => 1, 'adv' => false))); -// Adaptive mode. -$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/optionflags', - get_string('adaptive', 'quiz'), get_string('configadaptive', 'quiz'), - array('value' => 1, 'adv' => false))); - -// Apply penalties. -$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/penaltyscheme', - get_string('penaltyscheme', 'quiz'), get_string('configpenaltyscheme', 'quiz'), - array('value' => 1, 'adv' => true))); +// Preferred behaviour. +$quizsettings->add(new admin_setting_question_behaviour('quiz/preferredbehaviour', + get_string('howquestionsbehave', 'question'), get_string('howquestionsbehave_desc', 'quiz'), + 'deferredfeedback')); // Each attempt builds on last. $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/attemptonlast', diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 042084956946c..b4fc91aec2299 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2010122304; // The (date) version of this module -$module->requires = 2010080300; // Requires this Moodle version +$module->version = 2011051250; // The (date) version of this module +$module->requires = 2011051212; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index 590778c1d3d63..d840339791706 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -46,6 +46,8 @@ class question_engine_attempt_upgrader { protected $logger; /** @var int used by {@link prevent_timeout()}. */ protected $dotcounter = 0; + /** @var progress_bar */ + protected $progressbar = null; /** * Called before starting to upgrade all the attempts at a particular quiz. @@ -54,8 +56,16 @@ class question_engine_attempt_upgrader { * @param int $quizid the id of the quiz that is about to be processed. */ protected function print_progress($done, $outof, $quizid) { + if (is_null($this->progressbar)) { + $this->progressbar = new progress_bar('qe2upgrade'); + } + gc_collect_cycles(); // This was really helpful in PHP 5.2. Perhaps remove. - print_progress($done, $outof); + $a = new stdClass(); + $a->done = $done; + $a->todo = $outof; + $a->info = $quizid; + $this->progressbar->update($done, $outof, get_string('upgradingquizattempts', 'quiz', $a)); } protected function prevent_timeout() { @@ -71,7 +81,7 @@ protected function get_quiz_ids() { global $DB; // TODO, if local/qeupgradehelper/ is installed, and defines the right // function, use that to get the lest of quizzes instead. - return $DB->get_records_menu('quiz', '', '', 'id', 'id,1'); + return $DB->get_records_menu('quiz', array(), '', 'id', 'id, 1'); } public function convert_all_quiz_attempts() { @@ -273,7 +283,7 @@ public function load_question($questionid, $quizid = null) { public function get_next_question_session($attempt, moodle_recordset $questionsessionsrs) { $qsession = $questionsessionsrs->current(); - +print_object($qsession); // DONOTCOMMIT if (!$qsession || $qsession->attemptid != $attempt->uniqueid) { // No more question sessions belonging to this attempt. return false; diff --git a/version.php b/version.php index 41ca75bf2e6ff..967b26dcaf287 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011051100.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2011051212.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes