📄 mysql.php
字号:
$success = $success && table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id'); // initially we can use the id as the unique id because no other modules use attempts yet. $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false); // we set $CFG->attemptuniqueid to the next available id $record = get_record_sql("SELECT max(id)+1 AS nextid FROM {$CFG->prefix}quiz_attempts"); $success = $success && set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid); } if ($success && $oldversion < 2006020801) { // add new field to store time delay between the first and second quiz attempt $success = $success && table_column('quiz', '', 'delay1', 'integer', '10', 'unsigned', '0', 'not null', 'popup'); // add new field to store time delay between the second and any additional quizes $success = $success && table_column('quiz', '', 'delay2', 'integer', '10', 'unsigned', '0', 'not null', 'delay1'); } if ($success && $oldversion < 2006021101) { // set defaultgrade field properly (probably not necessary, but better make sure) $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false); $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '7'", false); } if ($success && $oldversion < 2006021103) { // add new field to store the question-level shuffleanswers option $success = $success && table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions'); $success = $success && table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single'); $success = $success && table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); } if ($success && $oldversion < 2006021104) { // add originalversion field for the new versioning mechanism $success = $success && table_column('quiz_question_versions', '', 'originalquestion', 'int', '10', 'unsigned', '0', 'not null', 'newquestion'); } if ($success && $oldversion < 2006021301) { $success = $success && modify_database('','ALTER TABLE prefix_quiz_attempts ADD UNIQUE INDEX uniqueid (uniqueid);'); } if ($success && $oldversion < 2006021302) { $success = $success && table_column('quiz_match_sub', '', 'code', 'int', '10', 'unsigned', '0', 'not null', 'id'); $success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_match_sub SET code = id", false); } if ($success && $oldversion < 2006021304) { // convert sequence field to text to accomodate very long sequences, see bug 4257 $success = $success && table_column('quiz_multianswers', 'sequence', 'sequence', 'text', '', '', '', 'not null', 'question'); } if ($success && $oldversion < 2006021501) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME {$CFG->prefix}question_sessions", false); } if ($success && $oldversion < 2006022200) { // convert grade fields to float $success = $success && set_field('quiz_attempts', 'sumgrades', 0, 'sumgrades', ''); $success = $success && table_column('quiz_attempts', 'sumgrades', 'sumgrades', 'float', '', '', '0', 'not null'); $success = $success && set_field('quiz_answers', 'fraction', 0, 'fraction', ''); $success = $success && table_column('quiz_answers', 'fraction', 'fraction', 'float', '', '', '0', 'not null'); $success = $success && set_field('quiz_essay_states', 'fraction', 0, 'fraction', ''); $success = $success && table_column('quiz_essay_states', 'fraction', 'fraction', 'float', '', '', '0', 'not null'); $success = $success && set_field('quiz_states', 'grade', 0, 'grade', ''); $success = $success && table_column('quiz_states', 'grade', 'grade', 'float', '', '', '0', 'not null'); $success = $success && set_field('quiz_states', 'raw_grade', 0, 'raw_grade', ''); $success = $success && table_column('quiz_states', 'raw_grade', 'raw_grade', 'float', '', '', '0', 'not null'); $success = $success && set_field('quiz_states', 'penalty', 0, 'penalty', ''); $success = $success && table_column('quiz_states', 'penalty', 'penalty', 'float', '', '', '0', 'not null'); $success = $success && set_field('question_sessions', 'sumpenalty', 0, 'sumpenalty', ''); $success = $success && table_column('question_sessions', 'sumpenalty', 'sumpenalty', 'float', '', '', '0', 'not null'); } if ($success && $oldversion < 2006022400) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions RENAME {$CFG->prefix}question", false); } if ($success && $oldversion < 2006022402) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_states RENAME {$CFG->prefix}question_states", false); } if ($success && $oldversion < 2006022800) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_answers RENAME {$CFG->prefix}question_answers", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_categories RENAME {$CFG->prefix}question_categories", false); } if ($success && $oldversion < 2006031202) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_truefalse RENAME {$CFG->prefix}question_truefalse", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_shortanswer RENAME {$CFG->prefix}question_shortanswer", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_multianswers RENAME {$CFG->prefix}question_multianswer", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_multichoice RENAME {$CFG->prefix}question_multichoice", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical RENAME {$CFG->prefix}question_numerical", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical_units RENAME {$CFG->prefix}question_numerical_units", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_randomsamatch RENAME {$CFG->prefix}question_randomsamatch", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_match RENAME {$CFG->prefix}question_match", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_match_sub RENAME {$CFG->prefix}question_match_sub", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_calculated RENAME {$CFG->prefix}question_calculated", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_definitions RENAME {$CFG->prefix}question_dataset_definitions", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_items RENAME {$CFG->prefix}question_dataset_items", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_question_datasets RENAME {$CFG->prefix}question_datasets", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp RENAME {$CFG->prefix}question_rqp", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_servers RENAME {$CFG->prefix}question_rqp_servers", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_states RENAME {$CFG->prefix}question_rqp_states", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_types RENAME {$CFG->prefix}question_rqp_types", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay RENAME {$CFG->prefix}question_essay", false); $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay_states RENAME {$CFG->prefix}question_essay_states", false); } if ($success && $oldversion < 2006032100) { // change from the old questiontype numbers to using the questiontype names $success = $success && table_column('question', 'qtype', 'qtype', 'varchar', 20, '', '', 'not null'); $success = $success && set_field('question', 'qtype', 'shortanswer', 'qtype', 1); $success = $success && set_field('question', 'qtype', 'truefalse', 'qtype', 2); $success = $success && set_field('question', 'qtype', 'multichoice', 'qtype', 3); $success = $success && set_field('question', 'qtype', 'random', 'qtype', 4); $success = $success && set_field('question', 'qtype', 'match', 'qtype', 5); $success = $success && set_field('question', 'qtype', 'randomsamatch', 'qtype', 6); $success = $success && set_field('question', 'qtype', 'description', 'qtype', 7); $success = $success && set_field('question', 'qtype', 'numerical', 'qtype', 8); $success = $success && set_field('question', 'qtype', 'multianswer', 'qtype', 9); $success = $success && set_field('question', 'qtype', 'calculated', 'qtype', 10); $success = $success && set_field('question', 'qtype', 'rqp', 'qtype', 11); $success = $success && set_field('question', 'qtype', 'essay', 'qtype', 12); } if ($success && $oldversion < 2006032200) { // set version for all questiontypes that already have their tables installed $success = $success && set_config('qtype_calculated_version', 2006032100); $success = $success && set_config('qtype_essay_version', 2006032100); $success = $success && set_config('qtype_match_version', 2006032100); $success = $success && set_config('qtype_multianswer_version', 2006032100); $success = $success && set_config('qtype_multichoice_version', 2006032100); $success = $success && set_config('qtype_numerical_version', 2006032100); $success = $success && set_config('qtype_randomsamatch_version', 2006032100); $success = $success && set_config('qtype_rqp_version', 2006032100); $success = $success && set_config('qtype_shortanswer_version', 2006032100); $success = $success && set_config('qtype_truefalse_version', 2006032100); } if ($success && $oldversion < 2006040600) { $success = $success && table_column('question_sessions', '', 'comment', 'text', '', '', '', 'not null', 'sumpenalty'); } if ($success && $oldversion < 2006040900) { $success = $success && modify_database('', "UPDATE prefix_question SET parent = id WHERE qtype ='random';"); } if ($success && $oldversion < 2006041000) { $success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');"); } if ($success && $oldversion < 2006041001) { $success = $success && table_column('question', 'version', 'version', 'varchar', 255); } if ($success && $oldversion < 2006042800) { // Check we have some un-renamed tables (verified in some servers) if ($tables = $db->MetaTables('TABLES')) { if (in_array($CFG->prefix.'quiz_randommatch', $tables) && !in_array($CFG->prefix.'question_randomsamatch', $tables)) { $success = $success && modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_question_randomsamatch "); } // Check for one possible missing field in one table if ($columns = $db->MetaColumnNames($CFG->prefix.'question_randomsamatch')) { if (!in_array('shuffleanswers', $columns)) { $success = $success && table_column('question_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); } } } } if ($oldversion < 2006051300) { // The newgraded field must always point to a valid state $success = $success && modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'"); // Only perform this if hasn't been performed before (in MOODLE_16_STABLE branch - bug 5717) $tables = $db->MetaTables('TABLES'); if (!in_array($CFG->prefix . 'question_attempts', $tables)) { // The following table is discussed in bug 5468 $success = $success && modify_database ("", "CREATE TABLE prefix_question_attempts ( id int(10) unsigned NOT NULL auto_increment, modulename varchar(20) NOT NULL default 'quiz', PRIMARY KEY (id) ) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';"); // create one entry for all the existing quiz attempts $success = $success && modify_database ("", "INSERT INTO prefix_question_attempts (id) SELECT uniqueid FROM prefix_quiz_attempts;"); } } if ($success && $oldversion < 2006060700) { // fix for 5720 // Copy the teacher comments from the question_essay_states table to the new // question_sessions table. // Get the attempt unique ID, teacher comment, graded flag, state ID, and question ID // based on the quesiont_essay_states if ($results = get_records_sql("SELECT a.uniqueid, es.response AS essaycomment, es.graded AS isgraded, qs.id AS stateid, qs.question AS questionid FROM {$CFG->prefix}question_states as qs, {$CFG->prefix}question_essay_states es, {$CFG->prefix}quiz_attempts a WHERE es.stateid = qs.id AND a.uniqueid = qs.attempt")) { foreach ($results as $result) { // Create a state object to be used for updating $state = new stdClass; $state->id = $result->stateid; if ($result->isgraded) { // Graded - save comment to the sessions and change state event to QUESTION_EVENTMANUALGRADE if (!($success = $success && set_field('question_sessions', 'comment', $result->essaycomment, 'attemptid', $result->uniqueid, 'questionid', $result->questionid))) { notify("Essay Table Migration: Cannot save comment"); break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -