3 function wiki_upgrade($oldversion) {
4 /// This function does anything necessary to upgrade
5 /// older versions to match current functionality
9 if ($oldversion < 2004040200) {
10 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` DROP `allowstudentstowiki`');
13 if ($oldversion < 2004040700) {
14 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` CHANGE `ewikiallowsafehtml` `htmlmode` TINYINT( 4 ) DEFAULT \'0\' NOT NULL');
17 if ($oldversion < 2004042100) {
18 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` ADD `pagename` VARCHAR( 255 ) AFTER `summary`');
19 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki_entries` CHANGE `name` `pagename` VARCHAR( 255 ) NOT NULL');
20 if ($wikis = get_records('wiki')) {
21 foreach ($wikis as $wiki) {
22 if (empty($wiki->pagename
)) {
23 set_field('wiki', 'pagename', $wiki->name
, 'id', $wiki->id
);
29 if ($oldversion < 2004053100) {
30 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki` CHANGE `initialcontent` `initialcontent` VARCHAR( 255 ) DEFAULT NULL');
31 // Remove obsolete 'initialcontent' values.
32 if ($wikis = get_records('wiki')) {
33 foreach ($wikis as $wiki) {
34 if (!empty($wiki->initialcontent
)) {
35 set_field('wiki', 'initialcontent', null, 'id', $wiki->id
);
41 if ($oldversion < 2004061300) {
42 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki`'
43 .' ADD `setpageflags` TINYINT DEFAULT \'1\' NOT NULL AFTER `ewikiacceptbinary`,'
44 .' ADD `strippages` TINYINT DEFAULT \'1\' NOT NULL AFTER `setpageflags`,'
45 .' ADD `removepages` TINYINT DEFAULT \'1\' NOT NULL AFTER `strippages`,'
46 .' ADD `revertchanges` TINYINT DEFAULT \'1\' NOT NULL AFTER `removepages`');
49 if ($oldversion < 2004062400) {
50 execute_sql('ALTER TABLE `'.$CFG->prefix
.'wiki`'
51 .' ADD `disablecamelcase` TINYINT DEFAULT \'0\' NOT NULL AFTER `ewikiacceptbinary`');
54 if ($oldversion < 2004082200) {
55 table_column('wiki_pages', '', 'userid', "integer", "10", "unsigned", "0", "not null", "author");
58 if ($oldversion < 2004082303) { // Try to update userid for old records
59 if ($pages = get_records('wiki_pages', 'userid', 0, 'pagename', 'lastmodified,author,pagename,version')) {
60 foreach ($pages as $page) {
61 $name = explode('(', $page->author
);
62 $name = trim($name[0]);
63 $name = explode(' ', $name);
64 $firstname = $name[0];
66 $lastname = trim(implode(' ', $name));
67 if ($user = get_record('user', 'firstname', $firstname, 'lastname', $lastname)) {
68 set_field('wiki_pages', 'userid', $user->id
, 'pagename', addslashes($page->pagename
), 'version', $page->version
);
74 if ($oldversion < 2004111200) {
75 execute_sql("ALTER TABLE {$CFG->prefix}wiki DROP INDEX course;",false);
76 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX course;",false);
77 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX userid;",false);
78 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX groupid;",false);
79 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX wikiid;",false);
80 execute_sql("ALTER TABLE {$CFG->prefix}wiki_entries DROP INDEX pagename;",false);
82 modify_database('','ALTER TABLE prefix_wiki ADD INDEX course (course);');
83 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX course (course);');
84 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX userid (userid);');
85 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX groupid (groupid);');
86 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX wikiid (wikiid);');
87 modify_database('','ALTER TABLE prefix_wiki_entries ADD INDEX pagename (pagename);');
90 if ($oldversion < 2005022000) {
91 // recreating the wiki_pages table completelly (missing id, bug 2608)
92 if ($rows = count_records("wiki_pages")) {
93 // we need to use the temp stuff
94 modify_database("","CREATE TABLE `prefix_wiki_pages_tmp` (
95 `pagename` VARCHAR(160) NOT NULL,
96 `version` INT(10) UNSIGNED NOT NULL DEFAULT 0,
97 `flags` INT(10) UNSIGNED DEFAULT 0,
99 `author` VARCHAR(100) DEFAULT 'ewiki',
100 `userid` INT(10) UNSIGNED NOT NULL DEFAULT 0,
101 `created` INT(10) UNSIGNED DEFAULT 0,
102 `lastmodified` INT(10) UNSIGNED DEFAULT 0,
105 `hits` INT(10) UNSIGNED DEFAULT 0,
106 `wiki` INT(10) UNSIGNED NOT NULL);");
108 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages_tmp (pagename, version, flags, content,
109 author, userid, created, lastmodified,
110 refs, meta, hits, wiki)
111 SELECT pagename, version, flags, content,
112 author, userid, created, lastmodified,
113 refs, meta, hits, wiki
114 FROM {$CFG->prefix}wiki_pages");
119 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages");
121 modify_database("","CREATE TABLE `prefix_wiki_pages` (
122 `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
123 `pagename` VARCHAR(160) NOT NULL,
124 `version` INT(10) UNSIGNED NOT NULL DEFAULT 0,
125 `flags` INT(10) UNSIGNED DEFAULT 0,
126 `content` MEDIUMTEXT,
127 `author` VARCHAR(100) DEFAULT 'ewiki',
128 `userid` INT(10) UNSIGNED NOT NULL DEFAULT 0,
129 `created` INT(10) UNSIGNED DEFAULT 0,
130 `lastmodified` INT(10) UNSIGNED DEFAULT 0,
133 `hits` INT(10) UNSIGNED DEFAULT 0,
134 `wiki` INT(10) UNSIGNED NOT NULL,
136 UNIQUE KEY `wiki_pages_uk` (`pagename`,`version`,`wiki`))
137 TYPE=MyISAM COMMENT='Holds the Wiki-Pages';");
139 if (!empty($insertafter)) {
140 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages (pagename, version, flags, content,
141 author, userid, created, lastmodified,
142 refs, meta, hits, wiki)
143 SELECT pagename, version, flags, content,
144 author, userid, created, lastmodified,
145 refs, meta, hits, wiki
146 FROM {$CFG->prefix}wiki_pages_tmp");
148 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages_tmp");