📄 postgres7.php
字号:
$skip = true; foreach ($ids as $id) { if ($skip) { $skip = false; } else { $success = $success && delete_records('quiz_numerical','id', $id->id); } } } } // Remove duplicate entries from quiz_shortanswer if ($dups = get_records_sql(" SELECT question, answers, count(*) as num FROM {$CFG->prefix}quiz_shortanswer GROUP BY question, answers HAVING count(*) > 1" )) { foreach ($dups as $dup) { $ids = get_records_sql(" SELECT id, id FROM {$CFG->prefix}quiz_shortanswer WHERE question = '$dup->question' AND answers = '$dup->answers'" ); $skip = true; foreach ($ids as $id) { if ($skip) { $skip = false; } else { $success = $success && delete_records('quiz_shortanswer','id', $id->id); } } } } // Remove duplicate entries from quiz_multichoice if ($dups = get_records_sql(" SELECT question, answers, count(*) as num FROM {$CFG->prefix}quiz_multichoice GROUP BY question, answers HAVING count(*) > 1" )) { foreach ($dups as $dup) { $ids = get_records_sql(" SELECT id, id FROM {$CFG->prefix}quiz_multichoice WHERE question = '$dup->question' AND answers = '$dup->answers'" ); $skip = true; foreach ($ids as $id) { if ($skip) { $skip = false; } else { $success = $success && delete_records('quiz_multichoice','id', $id->id); } } } } //Search all the orphan categories (those whose course doesn't exist) //and process them, deleting or moving them to site course - Bug 2459 //Set debug to false $olddebug = $db->debug; $db->debug = false; //Iterate over all the quiz_categories records to get their course id if ($courses = get_records_sql ("SELECT DISTINCT course as id, course FROM {$CFG->prefix}quiz_categories")) { //Iterate over courses foreach ($courses as $course) { //If the course doesn't exist, orphan category found! //Process it with question_delete_course(). It will do all the hard work. if (!record_exists('course', 'id', $course->id)) { require_once("$CFG->libdir/questionlib.php"); $success = $success && question_delete_course($course); } } } //Reset rebug to its original state $db->debug = $olddebug; } if ($success && $oldversion < 2005060301) { $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_rqp_type RENAME TO '.$CFG->prefix.'quiz_rqp_types'); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_rqp_type_id_seq RENAME TO '.$CFG->prefix.'rqp_types_id_seq'); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_rqp_types ALTER COLUMN id SET DEFAULT nextval(\''.$CFG->prefix.'quiz_rqp_types_id_seq\')'); $success = $success && execute_sql('DROP INDEX '.$CFG->prefix.'quiz_rqp_type_name_uk'); $success = $success && execute_sql('CREATE UNIQUE INDEX '.$CFG->prefix.'quiz_rqp_types_name_uk ON '.$CFG->prefix.'quiz_rqp_types (name);'); } if ($success && $oldversion < 2005060302) { // Mass cleanup of bad postgres upgrade scripts $success = $success && execute_sql('CREATE UNIQUE INDEX '.$CFG->prefix.'quiz_newest_states_attempt_idx ON '.$CFG->prefix.'quiz_newest_states (attemptid, questionid)',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_attemptonlast_datasets DROP CONSTRAINT '.$CFG->prefix.'quiz_category_userid_unique',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_attemptonlast_datasets ADD CONSTRAINT '.$CFG->prefix.'quiz_attemptonlast_datasets_category_userid UNIQUE (category, userid)',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_question_instances DROP CONSTRAINT '.$CFG->prefix.'quiz_question_grades_pkey',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_question_instances ADD CONSTRAINT '.$CFG->prefix.'quiz_question_instances_pkey PRIMARY KEY (id)',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_question_versions DROP CONSTRAINT '.$CFG->prefix.'quiz_question_version_pkey',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_question_versions ADD CONSTRAINT '.$CFG->prefix.'quiz_question_versions_pkey PRIMARY KEY (id)',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_states DROP CONSTRAINT '.$CFG->prefix.'quiz_responses_pkey',false); $success = $success && execute_sql('ALTER TABLE ONLY '.$CFG->prefix.'quiz_states ADD CONSTRAINT '.$CFG->prefix.'quiz_states_pkey PRIMARY KEY (id)',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER decimalpoints SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER optionflags SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER penaltyscheme SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER popup SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER questionsperpage SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz ALTER review SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_answers ALTER answer SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_attempts ALTER layout SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_attempts ALTER preview SET NOT NULL',false); $success = $success && table_column('quiz_calculated','correctanswerformat','correctanswerformat','integer','16','unsigned','2'); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_categories ALTER parent SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_categories ALTER sortorder SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_grades ALTER grade SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_multianswers ALTER sequence SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_numerical ALTER tolerance SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_questions ALTER hidden SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_questions ALTER length SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_questions ALTER parent SET NOT NULL',false); $success = $success && table_column('quiz_questions','penalty','penalty','real','','UNSIGNED','0.1'); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER answer SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER event SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER originalquestion SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER penalty SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER raw_grade SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER seq_number SET NOT NULL',false); $success = $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_states ALTER timestamp SET NOT NULL',false); } if ($success && $oldversion < 2005100500) { // clean up an old mistake. This mistake may not have been made, so don't worry about failures. $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_question_version_id_seq RENAME TO '.$CFG->prefix.'quiz_question_versions_id_seq',false); $success && execute_sql('ALTER TABLE '.$CFG->prefix.'quiz_question_versions ALTER COLUMN id SET DEFAULT nextval(\''.$CFG->prefix.'quiz_question_versions_id_seq\')',false); } if ($success && $oldversion < 2006020801) { $success = $success && table_column("quiz", "", "delay1", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "popup"); $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 && execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false); $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 < 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 < 2006021400) { // modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);'); // this index will not be created since uniqueid was not added, proper upgrade will be on 2006042801 } if ($success && $oldversion < 2006021501) { $success = $success && execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME TO {$CFG->prefix}question_sessions", false); } if ($success && $oldversion < 2006021900) { $success = $success && modify_database ('', " CREATE TABLE prefix_quiz_essay ( id SERIAL PRIMARY KEY, question integer NOT NULL default '0', answer varchar(255) NOT NULL default '' ) "); $success = $success && modify_database ('', " CREATE TABLE prefix_quiz_essay_states ( id SERIAL PRIMARY KEY, stateid integer NOT NULL default '0', graded integer NOT NULL default '0', fraction varchar(10) NOT NULL default '0.0', response text NOT NULL default '' );"); // convert grade fields to real $success = $success && table_column('quiz_attempts', 'sumgrades', 'sumgrades', 'real', '', '', '0', 'not null'); $success = $success && table_column('quiz_answers', 'fraction', 'fraction', 'real', '', '', '0', 'not null'); $success = $success && table_column('quiz_essay_states', 'fraction', 'fraction', 'real', '', '', '0', 'not null'); $success = $success && set_field('quiz_states', 'grade', 0, 'grade', ''); // Some values may be wrong, which caused errors in the following table_column calls. $success = $success && set_field('quiz_states', 'raw_grade', 0, 'raw_grade', ''); $success = $success && set_field('quiz_states', 'penalty', 0, 'penalty', ''); $success = $success && table_column('quiz_states', 'grade', 'grade', 'real', '', '', '0', 'not null'); $success = $success && table_column('quiz_states', 'raw_grade', 'raw_grade', 'real', '', '', '0',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -