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 wiki_upgrade($oldversion) {
9 /// This function does anything necessary to upgrade
10 /// older versions to match current functionality
14 if ($oldversion < 2004040200) {
15 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` DROP `allowstudentstowiki`');
18 if ($oldversion < 2004040700) {
19 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` CHANGE `ewikiallowsafehtml` `htmlmode` TINYINT( 4 ) DEFAULT \'0\' NOT NULL');
22 if ($oldversion < 2004042100) {
23 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` ADD `pagename` VARCHAR( 255 ) AFTER `summary`');
24 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki_entries` CHANGE `name` `pagename` VARCHAR( 255 ) NOT NULL');
25 if ($wikis = get_records('wiki')) {
26 foreach ($wikis as $wiki) {
27 if (empty($wiki->pagename
)) {
28 set_field('wiki', 'pagename', $wiki->name
, 'id', $wiki->id
);
34 if ($oldversion < 2004053100) {
35 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` CHANGE `initialcontent` `initialcontent` VARCHAR( 255 ) NOT NULL DEFAULT \'\'');
36 // Remove obsolete 'initialcontent' values.
37 if ($wikis = get_records('wiki')) {
38 foreach ($wikis as $wiki) {
39 if (!empty($wiki->initialcontent
)) {
40 set_field('wiki', 'initialcontent', null, 'id', $wiki->id
);
46 if ($oldversion < 2004061300) {
47 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki`'
48 .' ADD `setpageflags` TINYINT DEFAULT \'1\' NOT NULL AFTER `ewikiacceptbinary`,'
49 .' ADD `strippages` TINYINT DEFAULT \'1\' NOT NULL AFTER `setpageflags`,'
50 .' ADD `removepages` TINYINT DEFAULT \'1\' NOT NULL AFTER `strippages`,'
51 .' ADD `revertchanges` TINYINT DEFAULT \'1\' NOT NULL AFTER `removepages`');
54 if ($oldversion < 2004062400) {
55 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki`'
56 .' ADD `disablecamelcase` TINYINT DEFAULT \'0\' NOT NULL AFTER `ewikiacceptbinary`');
59 if ($oldversion < 2004082200) {
60 table_column('wiki_pages', '', 'userid', "integer", "10", "unsigned", "0", "not null", "author");
63 if ($oldversion < 2004082303) { // Try to update userid for old records
64 if ($pages = get_records('wiki_pages', 'userid', 0, 'pagename', 'lastmodified,author,pagename,version')) {
65 foreach ($pages as $page) {
66 $name = explode('(', $page->author
);
67 $name = trim($name[0]);
68 $name = explode(' ', $name);
69 $firstname = $name[0];
71 $lastname = trim(implode(' ', $name));
72 if ($user = get_record('user', 'firstname', $firstname, 'lastname', $lastname)) {
73 set_field('wiki_pages', 'userid', $user->id
, 'pagename', addslashes($page->pagename
), 'version', $page->version
);
79 if ($oldversion < 2004111200) {
80 execute_sql("ALTER TABLE {$CFG->prefix}wiki DROP INDEX course;",false);
81 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX course;",false);
82 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX userid;",false);
83 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX groupid;",false);
84 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX wikiid;",false);
85 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX pagename;",false);
87 modify_database('','ALTER TABLE prefix_wiki ADD INDEX course (course);');
88 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX course (course);');
89 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX userid (userid);');
90 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX groupid (groupid);');
91 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX wikiid (wikiid);');
92 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX pagename (pagename);');
95 if ($oldversion < 2005022000) {
96 // recreating the wiki_pages table completelly (missing id, bug 2608)
97 if ($rows = count_records("wiki_pages")) {
98 // we need to use the temp stuff
99 modify_database("","CREATE TABLE `prefix_wiki_pages_tmp` (
100 `pagename` VARCHAR(160) NOT NULL,
101 `version` INT(10) UNSIGNED NOT NULL DEFAULT 0,
102 `flags` INT(10) UNSIGNED DEFAULT 0,
103 `content` MEDIUMTEXT,
104 `author` VARCHAR(100) DEFAULT 'ewiki',
105 `userid` INT(10) UNSIGNED NOT NULL DEFAULT 0,
106 `created` INT(10) UNSIGNED DEFAULT 0,
107 `lastmodified` INT(10) UNSIGNED DEFAULT 0,
110 `hits` INT(10) UNSIGNED DEFAULT 0,
111 `wiki` INT(10) UNSIGNED NOT NULL);");
113 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages_tmp (pagename, version, flags, content,
114 author, userid, created, lastmodified,
115 refs, meta, hits, wiki)
116 SELECT pagename, version, flags, content,
117 author, userid, created, lastmodified,
118 refs, meta, hits, wiki
119 FROM {$CFG->prefix}wiki_pages");
124 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages");
126 modify_database("","CREATE TABLE `prefix_wiki_pages` (
127 `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
128 `pagename` VARCHAR(160) NOT NULL,
129 `version` INT(10) UNSIGNED NOT NULL DEFAULT 0,
130 `flags` INT(10) UNSIGNED DEFAULT 0,
131 `content` MEDIUMTEXT,
132 `author` VARCHAR(100) DEFAULT 'ewiki',
133 `userid` INT(10) UNSIGNED NOT NULL DEFAULT 0,
134 `created` INT(10) UNSIGNED DEFAULT 0,
135 `lastmodified` INT(10) UNSIGNED DEFAULT 0,
138 `hits` INT(10) UNSIGNED DEFAULT 0,
139 `wiki` INT(10) UNSIGNED NOT NULL,
141 UNIQUE KEY `wiki_pages_uk` (`pagename`,`version`,`wiki`))
142 TYPE=MyISAM COMMENT='Holds the Wiki-Pages';");
144 if (!empty($insertafter)) {
145 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages (pagename, version, flags, content,
146 author, userid, created, lastmodified,
147 refs, meta, hits, wiki)
148 SELECT pagename, version, flags, content,
149 author, userid, created, lastmodified,
150 refs, meta, hits, wiki
151 FROM {$CFG->prefix}wiki_pages_tmp");
153 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages_tmp");
157 if ($oldversion < 2006042800) {
159 execute_sql("UPDATE {$CFG->prefix}wiki SET summary='' WHERE summary IS NULL");
160 table_column('wiki','summary','summary','text','','','','not null');
162 execute_sql("UPDATE {$CFG->prefix}wiki SET pagename='' WHERE pagename IS NULL");
163 table_column('wiki','pagename','pagename','varchar','255','','','not null');
165 execute_sql("UPDATE {$CFG->prefix}wiki SET initialcontent='' WHERE initialcontent IS NULL");
166 table_column('wiki','initialcontent','initialcontent','varchar','255','','','not null');
168 if ($oldversion < 2006092502) {
170 CREATE TABLE prefix_wiki_locks
172 id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
173 wikiid INT(10) UNSIGNED NOT NULL,
174 pagename VARCHAR(160) NOT NULL DEFAULT '',
175 lockedby INT(10) NOT NULL DEFAULT 0,
176 lockedsince INT(10) NOT NULL DEFAULT 0,
177 lockedseen INT(10) NOT NULL DEFAULT 0,
179 UNIQUE INDEX wiki_locks_uk(wikiid,pagename),
180 INDEX wiki_locks_ix(lockedseen)
184 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.