3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 function glossary_upgrade($oldversion) {
9 /// This function does anything necessary to upgrade
10 /// older versions to match current functionality
14 if ($oldversion < 2003091000) {
15 execute_sql(" ALTER TABLE `{$CFG->prefix}glossary` ".
16 " ADD `allowduplicatedentries` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `studentcanpost` , ".
17 " ADD `displayformat` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `allowduplicatedentries` , ".
18 " ADD `mainglossary` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `displayformat` ");
20 execute_sql(" ALTER TABLE `{$CFG->prefix}glossary_entries` ".
21 " ADD timecreated INT(10) UNSIGNED NOT NULL default '0' AFTER `format` , ".
22 " ADD timemodified INT(10) UNSIGNED NOT NULL default '0' AFTER `timecreated` , ".
23 " ADD teacherentry TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `timemodified` ");
25 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'delete', 'glossary', 'name') ");
26 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'delete entry', 'glossary', 'name') ");
29 if ( $oldversion < 2003091500 ) {
30 execute_sql(" ALTER TABLE `{$CFG->prefix}glossary_entries` ".
31 " ADD attachment VARCHAR(100) NOT NULL default '' AFTER `format`");
34 if ( $oldversion < 2003091600 ) {
35 execute_sql(" ALTER TABLE `{$CFG->prefix}glossary` ".
36 " ADD `showspecial` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `mainglossary` , ".
37 " ADD `showalphabet` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `showspecial` , ".
38 " ADD `showall` TINYINT(2) UNSIGNED DEFAULT '1' NOT NULL AFTER `showalphabet` ");
41 if ( $oldversion < 2003091800 ) {
43 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_categories` (
44 `id` INT(10) unsigned NOT NULL auto_increment,
45 `glossaryid` INT(10) UNSIGNED NOT NULL default '0',
46 `name` VARCHAR(255) NOT NULL default '',
48 ) TYPE=MyISAM COMMENT='all categories for glossary entries'");
50 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_entries_categories` (
51 `categoryid` INT(10) UNSIGNED NOT NULL default '1',
52 `entryid` INT(10) UNSIGNED NOT NULL default '0',
53 PRIMARY KEY (`categoryid`, `entryid`)
54 ) TYPE=MyISAM COMMENT='categories of each glossary entry'");
57 if ( $oldversion < 2003092100 ) {
58 execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` CHANGE `categoryid` `categoryid` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ");
61 if ( $oldversion < 2003092102 ) {
62 execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` DROP PRIMARY KEY ");
63 execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` ADD `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
66 if ( $oldversion < 2003092400 ) {
67 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
68 "ADD `sourceglossaryid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `attachment` " );
72 if ( $oldversion < 2003101500 ) {
73 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` " .
74 "ADD `intro` text NOT NULL DEFAULT '' AFTER `name` " );
78 if ( $oldversion < 2003101501 ) {
79 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` " .
80 "ADD `allowcomments` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `showall` " );
82 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_comments` (
83 `id` INT(10) unsigned NOT NULL auto_increment,
84 `entryid` INT(10) UNSIGNED NOT NULL default '0',
85 `userid` INT(10) UNSIGNED NOT NULL default '0',
86 `comment` TEXT NOT NULL default '',
87 `timemodified` INT(10) UNSIGNED NOT NULL default '0',
88 `format` TINYINT(2) UNSIGNED NOT NULL default '0',
90 ) TYPE=MyISAM COMMENT='comments on glossary entries'");
92 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'add comment', 'glossary', 'name') ");
93 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'update comment', 'glossary', 'name') ");
94 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'delete comment', 'glossary', 'name') ");
97 if ( $oldversion < 2003101600 ) {
98 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` " .
99 "ADD `usedynalink` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `allowcomments` " );
101 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
102 "ADD `usedynalink` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `sourceglossaryid`, ".
103 "ADD `casesensitive` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `usedynalink` ");
106 if ( $oldversion < 2003101601 ) {
107 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
108 "ADD `fullmatch` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `casesensitive` ");
111 if ( $oldversion < 2003101800 ) {
112 execute_sql( "UPDATE `{$CFG->prefix}glossary`" .
113 " SET displayformat = 5 WHERE displayformat = 1");
115 if ( $oldversion < 2003102000 ) {
116 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
117 " ADD `defaultapproval` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `usedynalink`");
119 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries`" .
120 " ADD `approved` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `fullmatch`");
122 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('glossary', 'approve entry', 'glossary', 'name') ");
125 if ( $oldversion < 2003102800 ) {
126 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
127 " ADD `globalglossary` TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `defaultapproval`");
130 if ( $oldversion < 2003103100 ) {
131 print_simple_box('This update might take several seconds.<br />The more glossaries, entries and categories you have created, the more it will take so please be patient.','center', '50%', '', '20', 'noticebox');
132 if ( $glossaries = get_records("glossary")) {
134 foreach ( $glossaries as $glossary ) {
135 $gids .= "$glossary->id,";
137 $gids = substr($gids,0,-1); // ID's of VALID glossaries
139 if ($categories = get_records_select("glossary_categories","glossaryid NOT IN ($gids)") ) {
141 foreach ( $categories as $cat ) {
142 $cids .= "$cat->id,";
144 $cids = substr($cids,0,-1); // ID's of INVALID categories
146 delete_records_select("glossary_entries_categories", "categoryid IN ($cids)");
147 delete_records_select("glossary_categories", "id in ($cids)");
150 if ( $entries = get_records_select("glossary_entries") ) {
152 foreach ( $entries as $entry ) {
153 $eids .= "$entry->id,";
155 $eids = substr($eids,0,-1); // ID's of VALID entries
157 delete_records_select("glossary_comments", "entryid NOT IN ($eids)");
163 if ( $oldversion < 2003110400 ) {
164 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_alias` (
165 `id` INT(10) unsigned NOT NULL auto_increment,
166 `entryid` INT(10) UNSIGNED NOT NULL default '0',
167 `alias` TEXT NOT NULL default '',
169 ) TYPE=MyISAM COMMENT='entries alias'");
172 if ( $oldversion < 2003111500 ) {
173 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_categories`
174 ADD `usedynalink` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `name`" );
176 execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`
177 ADD `entbypage` TINYINT(3) UNSIGNED NOT NULL DEFAULT '10' AFTER `globalglossary`" );
181 if ( $oldversion < 2003111800 ) {
182 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_displayformats` (
183 `id` INT(10) unsigned NOT NULL auto_increment,
184 `fid` INT(10) UNSIGNED NOT NULL default '0',
185 `visible` TINYINT(2) UNSIGNED NOT NULL default '1',
186 `relatedview` TINYINT(3) NOT NULL default '-1',
187 `showgroup` TINYINT(2) UNSIGNED NOT NULL default '1',
188 `defaultmode` VARCHAR(50) NOT NULL default '',
189 `defaulthook` VARCHAR(50) NOT NULL default '',
190 `sortkey` VARCHAR(50) NOT NULL default '',
191 `sortorder` VARCHAR(50) NOT NULL default '',
193 ) TYPE=MyISAM COMMENT='Setting of the display formats'");
196 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
197 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
198 VALUES (0,0,'letter','ALL','CREATION','asc',1,1)");
200 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
201 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
202 VALUES (1,1,'date','ALL','CREATION','asc',0,1)");
203 // Full w/author View
204 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
205 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
206 VALUES (2,2,'letter','ALL','CREATION','asc',1,1)");
208 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
209 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
210 VALUES (3,3,'letter','ALL','CREATION','asc',1,1)");
212 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
213 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
214 VALUES (4,4,'date','ALL','CREATION','asc',0,1)");
215 // Full w/o author View
216 execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats
217 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
218 VALUES (5,5,'letter','ALL','CREATION','asc',1,1)");
220 execute_sql("INSERT INTO {$CFG->prefix}glossary_displayformats
221 (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible)
222 VALUES (6,0,'letter','ALL','CREATION','asc',1,1)");
226 if ($oldversion < 2003112100) {
227 table_column("glossary", "", "assessed", "integer", "10", "unsigned", "0");
228 table_column("glossary", "", "assesstimestart", "integer", "10", "unsigned", "0", "", "assessed");
229 table_column("glossary", "", "assesstimefinish", "integer", "10", "unsigned", "0", "", "assesstimestart");
231 execute_sql("CREATE TABLE {$CFG->prefix}glossary_ratings (
232 `id` int(10) unsigned NOT NULL auto_increment,
233 `userid` int(10) unsigned NOT NULL default '0',
234 `entryid` int(10) unsigned NOT NULL default '0',
235 `time` int(10) unsigned NOT NULL default '0',
236 `rating` tinyint(4) NOT NULL default '0',
238 ) COMMENT='Contains user ratings for entries'");
241 if ($oldversion < 2003112101) {
242 table_column("glossary", "", "scale", "integer", "10", "", "0", "", "assesstimefinish");
245 if ($oldversion < 2003112701) {
246 delete_records("glossary_alias","entryid",0);
249 if ($oldversion < 2004022200) {
250 if (!empty($CFG->textfilters
)) {
251 $CFG->textfilters
= str_replace("dynalink.php", "filter.php", $CFG->textfilters
);
252 set_config("textfilters", $CFG->textfilters
);
256 if ($oldversion < 2004050900) {
257 table_column("glossary","","rsstype","tinyint","2", "unsigned", "0", "", "entbypage");
258 table_column("glossary","","rssarticles","tinyint","2", "unsigned", "0", "", "rsstype");
259 set_config("glossary_enablerssfeeds",0);
263 if ( $oldversion < 2004051400 ) {
264 print_simple_box("This update might take several seconds.<p>The more glossaries, entries and aliases you have created, the more it will take so please be patient.","center", "50%", '', "20", "noticebox");
265 if ( $entries = get_records("glossary_entries", '', '', '', 'id,concept')) {
266 foreach($entries as $entry) {
267 set_field("glossary_entries","concept",addslashes(trim($entry->concept
)),"id",$entry->id
);
270 if ( $aliases = get_records("glossary_alias")) {
271 foreach($aliases as $alias) {
272 set_field("glossary_alias","alias",addslashes(trim($alias->alias
)),"id",$alias->id
);
277 if ( $oldversion < 2004072300) {
278 table_column("glossary_alias", "alias", "alias", "VARCHAR", "255", "", "", "NOT NULL");
281 if ( $oldversion < 2004072400) {
283 //Create new table glossary_formats to store format info
284 execute_sql("CREATE TABLE `{$CFG->prefix}glossary_formats` (
285 `id` INT(10) unsigned NOT NULL auto_increment,
286 `name` VARCHAR(50) NOT NULL,
287 `popupformatname` VARCHAR(50) NOT NULL,
288 `visible` TINYINT(2) UNSIGNED NOT NULL default '1',
289 `showgroup` TINYINT(2) UNSIGNED NOT NULL default '1',
290 `defaultmode` VARCHAR(50) NOT NULL default '',
291 `defaulthook` VARCHAR(50) NOT NULL default '',
292 `sortkey` VARCHAR(50) NOT NULL default '',
293 `sortorder` VARCHAR(50) NOT NULL default '',
295 ) TYPE=MyISAM COMMENT='Setting of the display formats'");
297 //Define current 0-6 format names
298 $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
299 'faq','fullwithoutauthor','entrylist');
301 //Fill the new table from the old one (only 'valid', 0-6, formats)
302 if ($formats = get_records('glossary_displayformats')) {
303 foreach ($formats as $format) {
305 if ($format->fid
>= 0 && $format->fid
<= 6) {
306 $format->name
= $formatnames[$format->fid
];
309 //Format popupformatname
310 $format->popupformatname
= 'dictionary'; //Default format
311 if ($format->relatedview
>= 0 && $format->relatedview
<= 6) {
312 $format->popupformatname
= $formatnames[$format->relatedview
];
315 //Insert the new record
316 //Only if $format->name is set (ie. formats 0-6)
318 insert_record('glossary_formats',$format);
324 //Drop the old formats table
325 execute_sql("DROP TABLE `{$CFG->prefix}glossary_displayformats`");
327 //Modify the glossary->displayformat field
328 table_column('glossary', 'displayformat', 'displayformat', 'VARCHAR', '50', '', 'dictionary', 'NOT NULL');
330 //Update glossary->displayformat field
331 if ($glossaries = get_records('glossary')) {
332 foreach($glossaries as $glossary) {
333 $displayformat = 'dictionary'; //Default format
334 if ($glossary->displayformat
>= 0 && $glossary->displayformat
<= 6) {
335 $displayformat = $formatnames[$glossary->displayformat
];
337 set_field('glossary','displayformat',$displayformat,'id',$glossary->id
);
342 if ( $oldversion < 2004080800) {
343 table_column("glossary","","editalways","tinyint","2", "unsigned", "0", "", "entbypage");
346 //Activate editalways in old secondary glossaries (old behaviour)
347 if ( $oldversion < 2004080900) {
348 set_field('glossary','editalways','1','mainglossary','0');
351 if ($oldversion < 2004111200) {
352 execute_sql("ALTER TABLE {$CFG->prefix}glossary DROP INDEX course;",false);
353 execute_sql("ALTER TABLE {$CFG->prefix}glossary_alias DROP INDEX entryid;",false);
354 execute_sql("ALTER TABLE {$CFG->prefix}glossary_categories DROP INDEX glossaryid;",false);
355 execute_sql("ALTER TABLE {$CFG->prefix}glossary_comments DROP INDEX entryid;",false);
356 execute_sql("ALTER TABLE {$CFG->prefix}glossary_comments DROP INDEX userid;",false);
357 execute_sql("ALTER TABLE {$CFG->prefix}glossary_entries DROP INDEX glossaryid;",false);
358 execute_sql("ALTER TABLE {$CFG->prefix}glossary_entries DROP INDEX userid;",false);
359 execute_sql("ALTER TABLE {$CFG->prefix}glossary_entries DROP INDEX concept;",false);
360 execute_sql("ALTER TABLE {$CFG->prefix}glossary_entries_categories DROP INDEX entryid;",false);
361 execute_sql("ALTER TABLE {$CFG->prefix}glossary_entries_categories DROP INDEX categoryid;",false);
362 execute_sql("ALTER TABLE {$CFG->prefix}glossary_ratings DROP INDEX userid;",false);
363 execute_sql("ALTER TABLE {$CFG->prefix}glossary_ratings DROP INDEX entryid;",false);
365 modify_database('','ALTER TABLE prefix_glossary ADD INDEX course (course);');
366 modify_database('','ALTER TABLE prefix_glossary_alias ADD INDEX entryid (entryid);');
367 modify_database('','ALTER TABLE prefix_glossary_categories ADD INDEX glossaryid (glossaryid);');
368 modify_database('','ALTER TABLE prefix_glossary_comments ADD INDEX entryid (entryid);');
369 modify_database('','ALTER TABLE prefix_glossary_comments ADD INDEX userid (userid);');
370 modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX glossaryid (glossaryid);');
371 modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX userid (userid);');
372 modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX concept (concept);');
373 modify_database('','ALTER TABLE prefix_glossary_entries_categories ADD INDEX entryid (entryid);');
374 modify_database('','ALTER TABLE prefix_glossary_entries_categories ADD INDEX categoryid (categoryid);');
375 modify_database('','ALTER TABLE prefix_glossary_ratings ADD INDEX userid (userid);');
376 modify_database('','ALTER TABLE prefix_glossary_ratings ADD INDEX entryid (entryid);');
380 //Delete orphaned categories (bug 2140)
381 if ($oldversion < 2005011100) {
382 $categories = get_records('glossary_categories', '', '', '', 'id, glossaryid');
384 foreach ($categories as $category) {
385 $glossary = get_record('glossary', 'id', "$category->glossaryid");
387 delete_records('glossary_categories', 'id', "$category->id");
393 //Allowprintview flag
394 if ($oldversion < 2005011200) {
395 table_column('glossary','','allowprintview','tinyint','2', 'unsigned', '1', '', 'allowcomments');
396 $glossaries = get_records('glossary', '', '', '', 'id, name');
398 foreach ($glossaries as $glossary) {
399 set_field('glossary', 'allowprintview', '1', 'id', "$glossary->id");
404 if ($oldversion < 2005031001) {
405 modify_database('',"INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('glossary', 'view entry', 'glossary_entries', 'concept');");
408 if ($oldversion < 2005041100) { // replace wiki-like with markdown
409 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
410 $wtm = new WikiToMarkdown();
411 // update glossary_entries->definition
412 $sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries ";
413 $sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
414 $sql .= "and {$CFG->prefix}glossary_entries.id = ";
415 $wtm->update( 'glossary_entries','definition','format' );
416 // update glossary_comments->text
417 $sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries,{$CFG->prefix}glossary_comments ";
418 $sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
419 $sql .= "and {$CFG->prefix}glossary_entries.id = {$CFG->prefix}glossary_comments.entryid ";
420 $sql .= "and {$CFG->prefix}glossary_comments.id = ";
421 $wtm->update( 'glossary_comments','text','format',$sql );
424 if ($oldversion < 2006082600) {
425 $sql1 = "UPDATE {$CFG->prefix}glossary_entries SET definition = REPLACE(definition, '".TRUSTTEXT
."', '');";
426 $sql2 = "UPDATE {$CFG->prefix}glossary_comments SET comment = REPLACE(comment, '".TRUSTTEXT
."', '');";
427 $likecond = sql_ilike()." '%".TRUSTTEXT
."%'";
429 if (!count_records_select('glossary_entries', "definition $likecond")) {
435 if (!count_records_select('glossary_comments', "comment $likecond")) {
442 if ($oldversion < 2006090400) {
443 table_column('glossary_comments', 'comment', 'entrycomment', 'text', '', '', '');
446 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.