Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 13ef403f3b
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 190 lines (166 sloc) 9.583 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
<?PHP

function wiki_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality

    global $CFG;

    if ($oldversion < 2004073000) {

       modify_database("", "ALTER TABLE prefix_wiki_pages DROP COLUMN id;");
       modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
ADD CONSTRAINT id PRIMARY KEY (pagename, \"version\");");
    }
    if ($oldversion < 2004073001) {

       modify_database("", "ALTER TABLE prefix_wiki_pages DROP CONSTRAINT id;");
       modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
ADD CONSTRAINT id PRIMARY KEY (pagename, \"version\", wiki);");
    }
    if ($oldversion < 2004082200) {
        table_column('wiki_pages', '', 'userid', "integer", "10", "unsigned", "0", "not null", "author");
    }
    if ($oldversion < 2004082303) { // Try to update userid for old records
        if ($pages = get_records('wiki_pages', 'userid', 0, 'pagename', 'lastmodified,author,pagename,version')) {
            foreach ($pages as $page) {
                $name = explode('(', $page->author);
                $name = trim($name[0]);
                $name = explode(' ', $name);
                $firstname = $name[0];
                unset($name[0]);
                $lastname = trim(implode(' ', $name));
                if ($user = get_record('user', 'firstname', $firstname, 'lastname', $lastname)) {
                    set_field('wiki_pages', 'userid', $user->id, 'pagename', addslashes($page->pagename), 'version', $page->version);
                }
            }
        }
    }
    
    if ($oldversion < 2004111200) {
        execute_sql("DROP INDEX {$CFG->prefix}wiki_course_idx;",false);
        execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_wikiid_idx;",false);
        execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_userid_idx;",false);
        execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_groupid_idx;",false);
        execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_course_idx;",false);
        execute_sql("DROP INDEX {$CFG->prefix}wiki_entries_pagename_idx;",false);

        modify_database('','CREATE INDEX prefix_wiki_course_idx ON prefix_wiki (course);');
        modify_database('','CREATE INDEX prefix_wiki_entries_wikiid_idx ON prefix_wiki_entries (wikiid);');
        modify_database('','CREATE INDEX prefix_wiki_entries_userid_idx ON prefix_wiki_entries (userid);');
        modify_database('','CREATE INDEX prefix_wiki_entries_groupid_idx ON prefix_wiki_entries (groupid);');
        modify_database('','CREATE INDEX prefix_wiki_entries_course_idx ON prefix_wiki_entries (course);');
        modify_database('','CREATE INDEX prefix_wiki_entries_pagename_idx ON prefix_wiki_entries (pagename);');
    }


    if ($oldversion < 2004112400) {
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT id;",false);
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT {$CFG->prefix}wiki_pages_id;",false);
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP CONSTRAINT {$CFG->prefix}wiki_pages_pagename_version_wiki_unique;",false);
        modify_database("", "ALTER TABLE ONLY prefix_wiki_pages
ADD CONSTRAINT prefix_wiki_pages_pagename_version_wiki_unique PRIMARY KEY (pagename, \"version\", wiki);");
    }

    if ($oldversion < 2005022000) {
        // recreating the wiki_pages table completelly (missing id, bug 2608)
        if ($rows = count_records("wiki_pages")) {
            // we need to use the temp stuff
            modify_database("","CREATE TABLE prefix_wiki_pages_tmp (
id SERIAL8 PRIMARY KEY,
pagename VARCHAR(160) NOT NULL,
version INTEGER NOT NULL DEFAULT 0,
flags INTEGER DEFAULT 0,
content TEXT,
author VARCHAR(100) DEFAULT 'ewiki',
userid INTEGER NOT NULL DEFAULT 0,
created INTEGER DEFAULT 0,
lastmodified INTEGER DEFAULT 0,
refs TEXT,
meta TEXT,
hits INTEGER DEFAULT 0,
wiki INT8 NOT NULL);");
            
            execute_sql("INSERT INTO {$CFG->prefix}wiki_pages_tmp (pagename, version, flags, content,
author, userid, created, lastmodified,
refs, meta, hits, wiki)
SELECT pagename, version, flags, content,
author, userid, created, lastmodified,
refs, meta, hits, wiki
FROM {$CFG->prefix}wiki_pages");

            $insertafter = true;
        }

        execute_sql("DROP TABLE {$CFG->prefix}wiki_pages");

        modify_database("","CREATE TABLE prefix_wiki_pages (
id SERIAL8 PRIMARY KEY,
pagename VARCHAR(160) NOT NULL,
version INTEGER NOT NULL DEFAULT 0,
flags INTEGER DEFAULT 0,
content TEXT,
author VARCHAR(100) DEFAULT 'ewiki',
userid INTEGER NOT NULL DEFAULT 0,
created INTEGER DEFAULT 0,
lastmodified INTEGER DEFAULT 0,
refs TEXT,
meta TEXT,
hits INTEGER DEFAULT 0,
wiki INT8 NOT NULL);");

        modify_database("","CREATE UNIQUE INDEX prefix_wiki_pages_pagename_version_wiki_uk
ON prefix_wiki_pages (pagename, version, wiki);");
        
        if (!empty($insertafter)) {
            execute_sql("INSERT INTO {$CFG->prefix}wiki_pages (pagename, version, flags, content,
author, userid, created, lastmodified,
refs, meta, hits, wiki)
SELECT pagename, version, flags, content,
author, userid, created, lastmodified,
refs, meta, hits, wiki
FROM {$CFG->prefix}wiki_pages_tmp");

            execute_sql("DROP TABLE {$CFG->prefix}wiki_pages_tmp");
        }
    }
    
    if ($oldversion < 2006032900) {
        global $db;
        table_column("wiki_pages",'','content_base64','text');
        table_column("wiki_pages",'','refs_base64','text');
        $olddebug = $db->debug;
        $db->debug = false;
        $data = $db->GetAll("SELECT id,content,refs FROM {$CFG->prefix}wiki_pages");
        foreach ($data as $d) {
            $db->AutoExecute("{$CFG->prefix}wiki_pages", array('refs_base64' => base64_encode($d['refs']), 'content_base64' => base64_encode($d['content'])), 'UPDATE', 'id = '.$d['id']);
        }
        $db->debug = $olddebug;
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP COLUMN content");
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP COLUMN refs");
        table_column("wiki_pages",'','content','bytea');
        table_column("wiki_pages",'','refs','bytea');
        execute_sql("UPDATE {$CFG->prefix}wiki_pages SET refs = decode(refs_base64, 'base64'), content = decode(content_base64, 'base64')");
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP COLUMN content_base64");
        execute_sql("ALTER TABLE {$CFG->prefix}wiki_pages DROP COLUMN refs_base64");
    }

    if ($oldversion < 2006042801) {
        modify_database('', 'ALTER TABLE prefix_wiki_pages
ALTER COLUMN content SET DEFAULT \'\'');
        modify_database('', 'ALTER TABLE prefix_wiki_pages
ALTER COLUMN refs SET DEFAULT \'\'');
        modify_database('', 'ALTER TABLE prefix_wiki_pages
ALTER COLUMN content DROP NOT NULL');
        modify_database('', 'ALTER TABLE prefix_wiki_pages
ALTER COLUMN refs DROP NOT NULL');
    }
    
    if ($oldversion < 2006092502) {
        modify_database("","
CREATE TABLE prefix_wiki_locks
(
id SERIAL PRIMARY KEY,
wikiid INTEGER NOT NULL,
pagename VARCHAR(160) NOT NULL DEFAULT '',
lockedby INTEGER NOT NULL DEFAULT 0,
lockedsince INTEGER NOT NULL DEFAULT 0,
lockedseen INTEGER NOT NULL DEFAULT 0
);");
        modify_database("","CREATE INDEX prefix_wikilock_loc_ix ON prefix_wiki_locks (lockedseen);");
        modify_database("","CREATE UNIQUE INDEX prefix_wikilock_wikpag_uix ON prefix_wiki_locks (wikiid, pagename);");
    }
    
    if($oldversion < 2006092602) {
     // This used to be a BYTEA type for no apparent reason, which caused various queries to fail. The new
     // install.xml uses TEXT so I figure it's safe to change it in upgrade too. This one broke the links page...
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN refs DROP DEFAULT;");
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN refs TYPE TEXT USING ENCODE(refs,'escape');");
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN refs SET DEFAULT '';");
// ...and this one broke the search page.
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN content DROP DEFAULT;");
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN content TYPE TEXT USING ENCODE(content,'escape');");
     modify_database('',"ALTER TABLE prefix_wiki_pages ALTER COLUMN content SET DEFAULT '';");
    }

    return true;
}

?>
Something went wrong with that request. Please try again.