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 < 2004022200) {
15 if (!empty($CFG->textfilters
)) {
16 $CFG->textfilters
= str_replace("dynalink.php", "filter.php", $CFG->textfilters
);
17 set_config("textfilters", $CFG->textfilters
);
21 if ($oldversion < 2004050900) {
22 table_column("glossary","","rsstype","integer","2", "unsigned", "0", "", "entbypage");
23 table_column("glossary","","rssarticles","integer","2", "unsigned", "0", "", "rsstype");
24 set_config("glossary_enablerssfeeds",0);
27 if ( $oldversion < 2004051400 ) {
28 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");
29 if ( $entries = get_records("glossary_entries", '', '', '', 'id,concept')) {
30 foreach($entries as $entry) {
31 set_field("glossary_entries","concept",addslashes(trim($entry->concept
)),"id",$entry->id
);
34 if ( $aliases = get_records("glossary_alias")) {
35 foreach($aliases as $alias) {
36 set_field("glossary_alias","alias",addslashes(trim($alias->alias
)),"id",$alias->id
);
41 if ( $oldversion < 2004072300) {
42 table_column("glossary_alias", "alias", "alias", "VARCHAR", "255", "", "", "NOT NULL");
45 if ( $oldversion < 2004072400) {
47 //Create new table glossary_formats to store format info
48 execute_sql("CREATE TABLE {$CFG->prefix}glossary_formats (
49 id SERIAL8 PRIMARY KEY,
50 name VARCHAR(50) NOT NULL,
51 popupformatname VARCHAR(50) NOT NULL,
52 visible int2 NOT NULL default '1',
53 showgroup int2 NOT NULL default '1',
54 defaultmode VARCHAR(50) NOT NULL default '',
55 defaulthook VARCHAR(50) NOT NULL default '',
56 sortkey VARCHAR(50) NOT NULL default '',
57 sortorder VARCHAR(50) NOT NULL default ''
60 //Define current 0-6 format names
61 $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
62 'faq','fullwithoutauthor','entrylist');
64 //Fill the new table from the old one (only 'valid', 0-6, formats)
65 if ($formats = get_records('glossary_displayformats')) {
66 foreach ($formats as $format) {
68 if ($format->fid
>= 0 && $format->fid
<= 6) {
69 $format->name
= $formatnames[$format->fid
];
72 //Format popupformatname
73 $format->popupformatname
= 'dictionary'; //Default format
74 if ($format->relatedview
>= 0 && $format->relatedview
<= 6) {
75 $format->popupformatname
= $formatnames[$format->relatedview
];
78 //Insert the new record
79 //Only if $format->name is set (ie. formats 0-6)
81 insert_record('glossary_formats',$format);
87 //Drop the old formats table
88 execute_sql("DROP TABLE {$CFG->prefix}glossary_displayformats");
90 //Modify the glossary->displayformat field
91 table_column('glossary', 'displayformat', 'displayformat', 'VARCHAR', '50', '', 'dictionary', 'NOT NULL');
93 //Update glossary->displayformat field
94 if ($glossaries = get_records('glossary')) {
95 foreach($glossaries as $glossary) {
96 $displayformat = 'dictionary'; //Default format
97 if ($glossary->displayformat
>= 0 && $glossary->displayformat
<= 6) {
98 $displayformat = $formatnames[$glossary->displayformat
];
100 set_field('glossary','displayformat',$displayformat,'id',$glossary->id
);
105 if ( $oldversion < 2004080800) {
106 table_column("glossary","","editalways","integer","2", "unsigned", "0", "", "entbypage");
109 //Activate editalways in old secondary glossaries (old behaviour)
110 if ( $oldversion < 2004080900) {
111 set_field('glossary','editalways','1','mainglossary','0');
114 if ($oldversion < 2004111200) {
115 execute_sql("DROP INDEX {$CFG->prefix}glossary_course_idx;",false);
116 execute_sql("DROP INDEX {$CFG->prefix}glossary_alias_entryid_idx;",false);
117 execute_sql("DROP INDEX {$CFG->prefix}glossary_categories_glossaryid_idx;",false);
118 execute_sql("DROP INDEX {$CFG->prefix}glossary_comments_entryid_idx;",false);
119 execute_sql("DROP INDEX {$CFG->prefix}glossary_comments_userid_idx;",false);
120 execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_glossaryid_idx;",false);
121 execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_userid_idx;",false);
122 execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_concept_idx;",false);
123 execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_categories_category_idx;",false);
124 execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_categories_entryid_idx;",false);
125 execute_sql("DROP INDEX {$CFG->prefix}glossary_ratings_userid_idx;",false);
126 execute_sql("DROP INDEX {$CFG->prefix}glossary_ratings_entryid_idx;",false);
128 modify_database('','CREATE INDEX prefix_glossary_course_idx ON prefix_glossary (course);');
129 modify_database('','CREATE INDEX prefix_glossary_alias_entryid_idx ON prefix_glossary_alias (entryid);');
130 modify_database('','CREATE INDEX prefix_glossary_categories_glossaryid_idx ON prefix_glossary_categories (glossaryid);');
131 modify_database('','CREATE INDEX prefix_glossary_comments_entryid_idx ON prefix_glossary_comments (entryid);');
132 modify_database('','CREATE INDEX prefix_glossary_comments_userid_idx ON prefix_glossary_comments (userid);');
133 modify_database('','CREATE INDEX prefix_glossary_entries_glossaryid_idx ON prefix_glossary_entries (glossaryid);');
134 modify_database('','CREATE INDEX prefix_glossary_entries_userid_idx ON prefix_glossary_entries (userid);');
135 modify_database('','CREATE INDEX prefix_glossary_entries_concept_idx ON prefix_glossary_entries (concept);');
136 modify_database('','CREATE INDEX prefix_glossary_entries_categories_category_idx ON prefix_glossary_entries_categories (categoryid);');
137 modify_database('','CREATE INDEX prefix_glossary_entries_categories_entryid_idx ON prefix_glossary_entries_categories (entryid);');
138 modify_database('','CREATE INDEX prefix_glossary_ratings_userid_idx ON prefix_glossary_ratings (userid);');
139 modify_database('','CREATE INDEX prefix_glossary_ratings_entryid_idx ON prefix_glossary_ratings (entryid);');
142 //Delete orphaned categories (bug 2140)
143 if ($oldversion < 2005011100) {
144 $categories = get_records('glossary_categories', '', '', '', 'id, glossaryid');
146 foreach ($categories as $category) {
147 $glossary = get_record('glossary', 'id', "$category->glossaryid");
149 delete_records('glossary_categories', 'id', "$category->id");
155 //Allowprintview flag
156 if ($oldversion < 2005011200) {
157 table_column('glossary','','allowprintview','integer','2', 'unsigned', '1', '', 'allowcomments');
158 $glossaries = get_records('glossary', '', '', '', 'id, name');
160 foreach ($glossaries as $glossary) {
161 set_field('glossary', 'allowprintview', '1', 'id', "$glossary->id");
166 if ($oldversion < 2005031001) {
167 modify_database('',"INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('glossary', 'view entry', 'glossary_entries', 'concept');");
170 if ($oldversion < 2005041100) { // replace wiki-like with markdown
171 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
172 $wtm = new WikiToMarkdown();
173 // update glossary_entries->definition
174 $sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries ";
175 $sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
176 $sql .= "and {$CFG->prefix}glossary_entries.id = ";
177 $wtm->update( 'glossary_entries','definition','format' );
178 // update glossary_comments->text
179 $sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries,{$CFG->prefix}glossary_comments ";
180 $sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
181 $sql .= "and {$CFG->prefix}glossary_entries.id = {$CFG->prefix}glossary_comments.entryid ";
182 $sql .= "and {$CFG->prefix}glossary_comments.id = ";
183 $wtm->update( 'glossary_comments','text','format',$sql );
186 if ($oldversion < 2005041901) { // Mass cleanup of bad postgres upgrade scripts
187 table_column('glossary','allowprintview','allowprintview','smallint','4','unsigned','1');
190 if ($oldversion < 2006082600) {
191 $sql1 = "UPDATE {$CFG->prefix}glossary_entries SET definition = REPLACE(definition, '".TRUSTTEXT
."', '');";
192 $sql2 = "UPDATE {$CFG->prefix}glossary_comments SET comment = REPLACE(comment, '".TRUSTTEXT
."', '');";
193 $likecond = sql_ilike()." '%".TRUSTTEXT
."%'";
195 if (!count_records_select('glossary_entries', "definition $likecond")) {
201 if (!count_records_select('glossary_comments', "comment $likecond")) {
208 if ($oldversion < 2006090400) {
209 table_column('glossary_comments', 'comment', 'entrycomment', 'text', '', '', '');
212 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.