3 function wiki_upgrade($oldversion) {
4 /// This function does anything necessary to upgrade
5 /// older versions to match current functionality
9 if ($oldversion < 2004073000) {
11 modify_database("", "ALTER TABLE prefix_wiki_pages DROP COLUMN id;");
12 modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
13 ADD CONSTRAINT id PRIMARY KEY (pagename, \"version\");");
15 if ($oldversion < 2004073001) {
17 modify_database("", "ALTER TABLE prefix_wiki_pages DROP CONSTRAINT id;");
18 modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
19 ADD CONSTRAINT id PRIMARY KEY (pagename, \"version\", wiki);");
21 if ($oldversion < 2004082200) {
22 table_column('wiki_pages', '', 'userid', "integer", "10", "unsigned", "0", "not null", "author");
24 if ($oldversion < 2004082303) { // Try to update userid for old records
25 if ($pages = get_records('wiki_pages', 'userid', 0, 'pagename', 'lastmodified,author,pagename,version')) {
26 foreach ($pages as $page) {
27 $name = explode('(', $page->author
);
28 $name = trim($name[0]);
29 $name = explode(' ', $name);
30 $firstname = $name[0];
32 $lastname = trim(implode(' ', $name));
33 if ($user = get_record('user', 'firstname', $firstname, 'lastname', $lastname)) {
34 set_field('wiki_pages', 'userid', $user->id
, 'pagename', addslashes($page->pagename
), 'version', $page->version
);
40 if ($oldversion < 2004111200) {
41 execute_sql("DROP INDEX {$CFG->prefix}wiki_course_idx;",false);
42 execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_wikiid_idx;",false);
43 execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_userid_idx;",false);
44 execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_groupid_idx;",false);
45 execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_course_idx;",false);
46 execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_pagename_idx;",false);
48 modify_database('','CREATE INDEX prefix_wiki_course_idx ON prefix_wiki (course);');
49 modify_database('','CREATE INDEX prefix_wiki_entries_wikiid_idx ON prefix_wiki_entries (wikiid);');
50 modify_database('','CREATE INDEX prefix_wiki_entries_userid_idx ON prefix_wiki_entries (userid);');
51 modify_database('','CREATE INDEX prefix_wiki_entries_groupid_idx ON prefix_wiki_entries (groupid);');
52 modify_database('','CREATE INDEX prefix_wiki_entries_course_idx ON prefix_wiki_entries (course);');
53 modify_database('','CREATE INDEX prefix_wiki_entries_pagename_idx ON prefix_wiki_entries (pagename);');
57 if ($oldversion < 2004112400) {
58 execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT id;",false);
59 execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT {$CFG->prefix}wiki_pages_id;",false);
60 execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT {$CFG->prefix}wiki_pages_pagename_version_wiki_unique;",false);
61 modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
62 ADD CONSTRAINT prefix_wiki_pages_pagename_version_wiki_unique PRIMARY KEY (pagename, \"version\", wiki);");
65 if ($oldversion < 2005022000) {
66 // recreating the wiki_pages table completelly (missing id, bug 2608)
67 if ($rows = count_records("wiki_pages")) {
68 // we need to use the temp stuff
69 modify_database("","CREATE TABLE prefix_wiki_pages_tmp (
70 id SERIAL8 PRIMARY KEY,
71 pagename VARCHAR(160) NOT NULL,
72 version INTEGER NOT NULL DEFAULT 0,
73 flags INTEGER DEFAULT 0,
75 author VARCHAR(100) DEFAULT 'ewiki',
76 userid INTEGER NOT NULL DEFAULT 0,
77 created INTEGER DEFAULT 0,
78 lastmodified INTEGER DEFAULT 0,
81 hits INTEGER DEFAULT 0,
82 wiki INT8 NOT NULL);");
84 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages_tmp (pagename, version, flags, content,
85 author, userid, created, lastmodified,
86 refs, meta, hits, wiki)
87 SELECT pagename, version, flags, content,
88 author, userid, created, lastmodified,
89 refs, meta, hits, wiki
90 FROM {$CFG->prefix}wiki_pages");
95 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages");
97 modify_database("","CREATE TABLE prefix_wiki_pages (
98 id SERIAL8 PRIMARY KEY,
99 pagename VARCHAR(160) NOT NULL,
100 version INTEGER NOT NULL DEFAULT 0,
101 flags INTEGER DEFAULT 0,
103 author VARCHAR(100) DEFAULT 'ewiki',
104 userid INTEGER NOT NULL DEFAULT 0,
105 created INTEGER DEFAULT 0,
106 lastmodified INTEGER DEFAULT 0,
109 hits INTEGER DEFAULT 0,
110 wiki INT8 NOT NULL);");
112 modify_database("","CREATE UNIQUE INDEX prefix_wiki_pages_pagename_version_wiki_uk
113 ON prefix_wiki_pages (pagename, version, wiki);");
115 if (!empty($insertafter)) {
116 execute_sql("INSERT INTO {$CFG->prefix}wiki_pages (pagename, version, flags, content,
117 author, userid, created, lastmodified,
118 refs, meta, hits, wiki)
119 SELECT pagename, version, flags, content,
120 author, userid, created, lastmodified,
121 refs, meta, hits, wiki
122 FROM {$CFG->prefix}wiki_pages_tmp");
124 execute_sql("DROP TABLE {$CFG->prefix}wiki_pages_tmp");