2004-09-12 15:06:29 +00:00
|
|
|
<?php // $Id$
|
2002-10-05 17:20:24 +00:00
|
|
|
|
|
|
|
function choice_upgrade($oldversion) {
|
2005-01-27 02:17:35 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
2002-10-05 17:20:24 +00:00
|
|
|
// This function does anything necessary to upgrade
|
|
|
|
// older versions to match current functionality
|
|
|
|
|
|
|
|
if ($oldversion < 2002090800) {
|
|
|
|
execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )");
|
|
|
|
execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )");
|
|
|
|
}
|
2002-10-24 03:43:37 +00:00
|
|
|
if ($oldversion < 2002102400) {
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `answer3` varchar(255) NOT NULL AFTER `answer2`");
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `answer4` varchar(255) NOT NULL AFTER `answer3`");
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `answer5` varchar(255) NOT NULL AFTER `answer4`");
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `answer6` varchar(255) NOT NULL AFTER `answer5`");
|
|
|
|
}
|
2002-12-23 09:39:26 +00:00
|
|
|
if ($oldversion < 2002122300) {
|
|
|
|
execute_sql("ALTER TABLE `choice_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
|
|
|
}
|
2003-01-01 06:34:13 +00:00
|
|
|
if ($oldversion < 2003010100) {
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `text` ");
|
|
|
|
execute_sql(" ALTER TABLE `choice` ADD `publish` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `answer6` ");
|
|
|
|
}
|
2004-01-01 06:35:22 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004010100) {
|
|
|
|
table_column("choice", "", "showunanswered", "integer", "4", "unsigned", "0", "", "publish");
|
|
|
|
}
|
2004-02-17 14:39:15 +00:00
|
|
|
if ($oldversion < 2004021700) {
|
|
|
|
modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose', 'choice', 'name');");
|
|
|
|
modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose again', 'choice', 'name');");
|
|
|
|
}
|
2004-07-01 07:01:26 +00:00
|
|
|
if ($oldversion < 2004070100) {
|
|
|
|
table_column("choice", "", "timeclose", "integer", "10", "unsigned", "0", "", "showunanswered");
|
|
|
|
table_column("choice", "", "timeopen", "integer", "10", "unsigned", "0", "", "showunanswered");
|
|
|
|
}
|
2004-07-01 07:41:36 +00:00
|
|
|
if ($oldversion < 2004070101) {
|
|
|
|
table_column("choice", "", "release", "integer", "2", "unsigned", "0", "", "publish");
|
|
|
|
table_column("choice", "", "allowupdate", "integer", "2", "unsigned", "0", "", "release");
|
|
|
|
}
|
2004-07-01 09:17:37 +00:00
|
|
|
if ($oldversion < 2004070102) {
|
2004-07-01 13:30:50 +00:00
|
|
|
modify_database("", "UPDATE prefix_choice SET allowupdate = '1' WHERE publish = 0;");
|
2004-07-01 09:17:37 +00:00
|
|
|
modify_database("", "UPDATE prefix_choice SET release = '1' WHERE publish > 0;");
|
|
|
|
modify_database("", "UPDATE prefix_choice SET publish = publish - 1 WHERE publish > 0;");
|
|
|
|
}
|
2004-07-01 07:01:26 +00:00
|
|
|
|
2004-11-17 23:03:56 +00:00
|
|
|
if ($oldversion < 2004111200){ // drop first to avoid conflicts when upgrading from 1.4+
|
2004-11-18 02:39:16 +00:00
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}choice DROP INDEX course;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX choice;",false);
|
2005-03-29 23:46:17 +00:00
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX userid;",false);
|
|
|
|
|
2004-11-17 23:03:56 +00:00
|
|
|
modify_database('','ALTER TABLE prefix_choice ADD INDEX course (course);');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX choice (choice);');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX userid (userid);');
|
|
|
|
}
|
2005-03-29 23:46:17 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2005033000){
|
|
|
|
execute_sql("RENAME TABLE {$CFG->prefix}choice_answers TO {$CFG->prefix}choice_responses;");
|
|
|
|
execute_sql("CREATE TABLE {$CFG->prefix}choice_answers (id int(10) unsigned NOT NULL auto_increment, choice int(10) unsigned NOT NULL default '0', answer TEXT, timemodified int(10) NOT NULL default '0', PRIMARY KEY (id), UNIQUE KEY id (id), KEY choice (choice)) TYPE=MyISAM;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}choice ADD `display` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `release`;");
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}choice_responses CHANGE answer answerid integer(10) NOT NULL default '0';");
|
|
|
|
|
|
|
|
//move old answers into new answers table.
|
|
|
|
$records = get_records('choice');
|
|
|
|
if (!empty($records)) {
|
|
|
|
foreach ($records as $thischoice) {
|
|
|
|
for ($i = 1; $i < 7; $i++) {
|
|
|
|
$instance = new stdClass;
|
|
|
|
$instance->choice = $thischoice->id;
|
|
|
|
$instance->answerid = $thischoice->{'answer'.$i};
|
|
|
|
$instance->timemodified = $thischoice->timemodified;
|
|
|
|
$result = insert_record('choice_answers', $instance);
|
|
|
|
//now fix all responses to the answers.
|
|
|
|
execute_sql("UPDATE {$CFG->prefix}choice_responses SET answerid={$result} WHERE choice={$thischoice->id} AND answerid={$i}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//drop old fields
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer1`;');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer2`;');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer3`;');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer4`;');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer5`;');
|
|
|
|
modify_database('','ALTER TABLE prefix_choice DROP `answer6`;');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-01-01 06:35:22 +00:00
|
|
|
|
2002-10-05 17:20:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|