| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?PHP 2 3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT! 4 // 5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL 6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY. 7 8 function lesson_upgrade($oldversion) { 9 /// This function does anything necessary to upgrade 10 /// older versions to match current functionality 11 12 global $CFG; 13 14 if ($oldversion < 2004021600) { 15 16 delete_records("log_display", "module", "lesson"); 17 18 modify_database ("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('lesson', 'start', 'lesson', 'name');"); 19 modify_database ("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('lesson', 'end', 'lesson', 'name');"); 20 modify_database ("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('lesson', 'view', 'lesson_pages', 'title');"); 21 22 } 23 24 if ($oldversion < 2004022200) { 25 26 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxattempts` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxanswers"); 27 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `nextpagedefault` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); 28 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxpages` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); 29 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qtype` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER lessonid"); 30 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qoption` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER qtype"); 31 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `grade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER jumpto"); 32 33 } 34 35 if ($oldversion < 2004032000) { // Upgrade some old beta lessons 36 execute_sql(" UPDATE `{$CFG->prefix}lesson_pages` SET qtype = 3 WHERE qtype = 0"); 37 } 38 39 if ($oldversion < 2004032400) { 40 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usemaxgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); 41 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `minquestions` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); 42 } 43 44 if ($oldversion < 2004032700) { 45 table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); 46 } 47 48 if ($oldversion < 2004060501) { 49 // matching questions need 2 records for responses and the 50 // 2 records must appear before the old ones. So, delete the old ones, 51 // create the 2 needed, then re-insert the old ones for each matching question. 52 if ($matchingquestions = get_records('lesson_pages', 'qtype', 5)) { // get our matching questions 53 foreach ($matchingquestions as $matchingquestion) { 54 if ($answers = get_records('lesson_answers', 'pageid', $matchingquestion->id)) { // get answers 55 if (delete_records('lesson_answers', 'pageid', $matchingquestion->id)) { // delete them 56 $time = time(); 57 // make our 2 response answers 58 $newanswer->lessonid = $matchingquestion->lessonid; 59 $newanswer->pageid = $matchingquestion->id; 60 $newanswer->timecreated = $time; 61 $newanswer->timemodified = 0; 62 insert_record('lesson_answers', $newanswer); 63 insert_record('lesson_answers', $newanswer); 64 // insert our old answers 65 foreach ($answers as $answer) { 66 $answer->timecreated = $time; 67 $answer->timemodified = 0; 68 insert_record('lesson_answers', (object) array_map('addslashes', (array)$answer)); 69 } 70 } 71 } 72 } 73 } 74 } 75 76 if ($oldversion < 2004072100) { 77 execute_sql(" create table ".$CFG->prefix."lesson_high_scores 78 ( id int(10) unsigned not null auto_increment, 79 lessonid int(10) unsigned not null default '0', 80 userid int(10) unsigned not null default '0', 81 gradeid int(10) unsigned not null default '0', 82 nickname varchar(5) not null default '', 83 PRIMARY KEY (`id`) 84 )"); 85 86 execute_sql(" create table ".$CFG->prefix."lesson_branch 87 ( id int(10) unsigned not null auto_increment, 88 lessonid int(10) unsigned not null default '0', 89 userid int(10) unsigned not null default '0', 90 pageid int(10) unsigned not null default '0', 91 retry int(10) unsigned not null default '0', 92 flag tinyint(3) unsigned not null default '0', 93 timeseen int(10) unsigned not null default '0', 94 PRIMARY KEY (`id`) 95 )"); 96 97 98 execute_sql(" create table ".$CFG->prefix."lesson_timer 99 ( id int(10) unsigned not null auto_increment, 100 lessonid int(10) unsigned not null default '0', 101 userid int(10) unsigned not null default '0', 102 starttime int(10) unsigned not null default '0', 103 lessontime int(10) unsigned not null default '0', 104 PRIMARY KEY (`id`) 105 )"); 106 107 108 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `layout` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption"); 109 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `display` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout"); 110 111 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `score` INT(10) NOT NULL DEFAULT '0' AFTER grade"); 112 113 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usepassword` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); 114 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `password` VARCHAR(32) NOT NULL DEFAULT '' AFTER usepassword"); 115 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `custom` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); 116 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `ongoing` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER custom"); 117 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `timed` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxpages"); 118 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxtime` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER timed"); 119 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `tree` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER retake"); 120 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `slideshow` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER tree"); 121 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `width` INT(10) UNSIGNED NOT NULL DEFAULT '640' AFTER slideshow"); 122 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `height` INT(10) UNSIGNED NOT NULL DEFAULT '480' AFTER width"); 123 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `bgcolor` CHAR(7) NOT NULL DEFAULT '#FFFFFF' AFTER height"); 124 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `displayleft` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER bgcolor"); 125 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `highscores` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER displayleft"); 126 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxhighscores` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER highscores"); 127 128 } 129 130 if ($oldversion < 2004081100) { 131 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `practice` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); 132 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `review` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); 133 } 134 135 if ($oldversion < 2004081700) { 136 execute_sql("CREATE TABLE `{$CFG->prefix}lesson_default` 137 ( `id` int(10) unsigned NOT NULL auto_increment, 138 `course` int(10) unsigned NOT NULL default '0', 139 `practice` tinyint(3) unsigned NOT NULL default '0', 140 `password` varchar(32) NOT NULL default '', 141 `usepassword` int(3) unsigned NOT NULL default '0', 142 `grade` tinyint(3) NOT NULL default '0', 143 `custom` int(3) unsigned NOT NULL default '0', 144 `ongoing` int(3) unsigned NOT NULL default '0', 145 `usemaxgrade` tinyint(3) unsigned NOT NULL default '0', 146 `maxanswers` int(3) unsigned NOT NULL default '4', 147 `maxattempts` int(3) unsigned NOT NULL default '5', 148 `review` tinyint(3) unsigned NOT NULL default '0', 149 `nextpagedefault` int(3) unsigned NOT NULL default '0', 150 `minquestions` tinyint(3) unsigned NOT NULL default '0', 151 `maxpages` int(3) unsigned NOT NULL default '0', 152 `timed` int(3) unsigned NOT NULL default '0', 153 `maxtime` int(10) unsigned NOT NULL default '0', 154 `retake` int(3) unsigned NOT NULL default '1', 155 `tree` int(3) unsigned NOT NULL default '0', 156 `slideshow` int(3) unsigned NOT NULL default '0', 157 `width` int(10) unsigned NOT NULL default '640', 158 `height` int(10) unsigned NOT NULL default '480', 159 `bgcolor` varchar(7) default '#FFFFFF', 160 `displayleft` int(3) unsigned NOT NULL default '0', 161 `highscores` int(3) unsigned NOT NULL default '0', 162 `maxhighscores` int(10) NOT NULL default '0', 163 PRIMARY KEY (`id`) 164 ) COMMENT = 'Defines lesson_default'"); 165 } 166 167 if ($oldversion < 2004100400) { 168 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); 169 } 170 171 if ($oldversion < 2004100700) { 172 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); 173 } 174 175 if ($oldversion < 2004102600) { 176 execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); 177 } 178 179 if ($oldversion < 2004111200) { 180 execute_sql("ALTER TABLE {$CFG->prefix}lesson DROP INDEX course;",false); 181 execute_sql("ALTER TABLE {$CFG->prefix}lesson_answers DROP INDEX lessonid;",false); 182 execute_sql("ALTER TABLE {$CFG->prefix}lesson_attempts DROP INDEX lessonid;",false); 183 execute_sql("ALTER TABLE {$CFG->prefix}lesson_attempts DROP INDEX pageid;",false); 184 execute_sql("ALTER TABLE {$CFG->prefix}lesson_grades DROP INDEX lessonid;",false); 185 execute_sql("ALTER TABLE {$CFG->prefix}lesson_grades DROP INDEX userid;",false); 186 execute_sql("ALTER TABLE {$CFG->prefix}lesson_pages DROP INDEX lessonid;",false); 187 188 modify_database('','ALTER TABLE prefix_lesson ADD INDEX course (course);'); 189 modify_database('','ALTER TABLE prefix_lesson_answers ADD INDEX lessonid (lessonid);'); 190 modify_database('','ALTER TABLE prefix_lesson_attempts ADD INDEX lessonid (lessonid);'); 191 modify_database('','ALTER TABLE prefix_lesson_attempts ADD INDEX pageid (pageid);'); 192 modify_database('','ALTER TABLE prefix_lesson_grades ADD INDEX lessonid (lessonid);'); 193 modify_database('','ALTER TABLE prefix_lesson_grades ADD INDEX userid (userid);'); 194 modify_database('','ALTER TABLE prefix_lesson_pages ADD INDEX lessonid (lessonid);'); 195 } 196 197 if ($oldversion < 2005060900) { 198 table_column('lesson_grades', 'grade', 'grade', 'float', '', 'unsigned', '0', 'not null'); 199 } 200 201 if ($oldversion < 2005061500) { 202 table_column('lesson', '', 'mediafile', 'varchar', '255', '', '', 'not null', 'tree'); 203 } 204 205 if ($oldversion < 2005063000) { 206 table_column('lesson', '', 'dependency', 'int', '10', 'unsigned', '0', 'not null', 'usepassword'); 207 table_column('lesson', '', 'conditions', 'text', '', '', '', 'not null', 'dependency'); 208 } 209 210 if ($oldversion < 2005101900) { 211 table_column('lesson', '', 'progressbar', 'tinyint', '3', 'unsigned', '0', 'not null', 'displayleft'); 212 table_column('lesson', '', 'displayleftif', 'int', '3', 'unsigned', '0', 'not null', 'displayleft'); 213 } 214 215 if ($oldversion < 2005102800) { 216 table_column('lesson', '', 'mediaclose', 'tinyint', '3', 'unsigned', '0', 'not null', 'mediafile'); 217 table_column('lesson', '', 'mediaheight', 'int', '10', 'unsigned', '100', 'not null', 'mediafile'); 218 table_column('lesson', '', 'mediawidth', 'int', '10', 'unsigned', '650', 'not null', 'mediafile'); 219 } 220 221 if ($oldversion < 2005110200) { 222 table_column('lesson', '', 'activitylink', 'int', '10', 'unsigned', '0', 'not null', 'tree'); 223 } 224 225 if ($oldversion < 2006031900) { 226 execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson DROP COLUMN tree'); 227 execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson_default DROP COLUMN tree'); 228 } 229 230 if ($oldversion < 2006050100) { 231 table_column('lesson_default', '', 'conditions', 'text', '', '', '', 'not null', 'password'); 232 table_column('lesson_default', '', 'progressbar', 'tinyint', '3', 'unsigned', '0', 'not null', 'displayleft'); 233 table_column('lesson_default', '', 'displayleftif', 'int', '3', 'unsigned', '0', 'not null', 'displayleft'); 234 table_column('lesson_default', '', 'mediaclose', 'tinyint', '3', 'unsigned', '0', 'not null', 'retake'); 235 table_column('lesson_default', '', 'mediaheight', 'int', '10', 'unsigned', '100', 'not null', 'retake'); 236 table_column('lesson_default', '', 'mediawidth', 'int', '10', 'unsigned', '650', 'not null', 'retake'); 237 } 238 239 if ($oldversion < 2006091202) { 240 table_column('lesson', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); 241 table_column('lesson_default', '', 'feedback', 'int', '3', 'unsigned', '1', 'not null', 'nextpagedefault'); 242 } 243 244 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions. 245 246 return true; 247 } 248 249 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |