|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00023 function wiki_add_wiki_fields() { 00024 global $DB; 00025 00026 upgrade_set_timeout(); 00027 $dbman = $DB->get_manager(); 00029 $table = new xmldb_table('wiki'); 00030 00031 // Adding fields to wiki table 00032 $wikitable = new xmldb_table('wiki'); 00033 00034 // in MOODLE_20_SABLE branch, summary field is renamed as intro 00035 // so we renamed it back to summary to keep upgrade going as moodle 1.9 00036 $field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); 00037 if ($dbman->field_exists($wikitable, $field)) { 00038 $dbman->rename_field($wikitable, $field, 'summary'); 00039 } 00040 $dbman->add_field($wikitable, $field); 00041 00042 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); 00043 if (!$dbman->field_exists($wikitable, $field)) { 00044 $dbman->add_field($wikitable, $field); 00045 } 00046 00047 $field = new xmldb_field('firstpagetitle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'First Page', null); 00048 $dbman->add_field($wikitable, $field); 00049 00050 $field = new xmldb_field('wikimode', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'collaborative', null); 00051 $dbman->add_field($wikitable, $field); 00052 00053 $field = new xmldb_field('defaultformat', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'creole', null); 00054 $dbman->add_field($wikitable, $field); 00055 00056 $field = new xmldb_field('forceformat', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null); 00057 $dbman->add_field($wikitable, $field); 00058 00059 $field = new xmldb_field('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); 00060 $dbman->add_field($wikitable, $field); 00061 00062 $field = new xmldb_field('editbegin', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null); 00063 $dbman->add_field($wikitable, $field); 00064 00065 $field = new xmldb_field('editend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', null); 00066 $dbman->add_field($wikitable, $field); 00067 00068 } 00069 00073 function wiki_upgrade_install_20_tables() { 00074 global $DB; 00075 upgrade_set_timeout(); 00076 $dbman = $DB->get_manager(); 00077 00079 $table = new xmldb_table('wiki_subwikis'); 00080 00082 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00083 $table->add_field('wikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00084 $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00085 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00086 00088 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00089 $table->add_key('wikiidgroupiduserid', XMLDB_KEY_UNIQUE, array('wikiid', 'groupid', 'userid')); 00090 $table->add_key('wikifk', XMLDB_KEY_FOREIGN, array('wikiid'), 'wiki', array('id')); 00091 00093 if (!$dbman->table_exists($table)) { 00094 $dbman->create_table($table); 00095 } 00096 00098 $table = new xmldb_table('wiki_pages'); 00099 00101 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00102 $table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00103 $table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'title'); 00104 $table->add_field('cachedcontent', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null); 00105 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00106 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00107 $table->add_field('timerendered', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00108 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00109 $table->add_field('pageviews', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00110 $table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00111 00113 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00114 $table->add_key('subwikititleuser', XMLDB_KEY_UNIQUE, array('subwikiid', 'title', 'userid')); 00115 $table->add_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwiki', array('id')); 00116 00118 if (!$dbman->table_exists($table)) { 00119 $dbman->create_table($table); 00120 } 00121 00123 $table = new xmldb_table('wiki_versions'); 00124 00126 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00127 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00128 $table->add_field('content', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null); 00129 $table->add_field('contentformat', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'creole'); 00130 $table->add_field('version', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00131 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00132 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00133 00135 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00136 $table->add_key('pagefk', XMLDB_KEY_FOREIGN, array('pageid'), 'wiki_pages', array('id')); 00137 00139 if (!$dbman->table_exists($table)) { 00140 $dbman->create_table($table); 00141 } 00142 00144 $table = new xmldb_table('wiki_synonyms'); 00145 00147 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00148 $table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00149 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00150 $table->add_field('pagesynonym', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'Pagesynonym'); 00151 00153 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00154 $table->add_key('pageidsyn', XMLDB_KEY_UNIQUE, array('pageid', 'pagesynonym')); 00155 00157 if (!$dbman->table_exists($table)) { 00158 $dbman->create_table($table); 00159 } 00160 00162 $table = new xmldb_table('wiki_links'); 00163 00165 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00166 $table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00167 $table->add_field('frompageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00168 $table->add_field('topageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00169 $table->add_field('tomissingpage', XMLDB_TYPE_CHAR, '255', null, null, null, null); 00170 00172 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00173 $table->add_key('frompageidfk', XMLDB_KEY_FOREIGN, array('frompageid'), 'wiki_pages', array('id')); 00174 $table->add_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwiki', array('id')); 00175 00177 if (!$dbman->table_exists($table)) { 00178 $dbman->create_table($table); 00179 } 00180 00182 $table = new xmldb_table('wiki_locks'); 00183 00185 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 00186 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00187 $table->add_field('sectionname', XMLDB_TYPE_CHAR, '255', null, null, null, null); 00188 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00189 $table->add_field('lockedat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); 00190 00192 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 00193 00195 if (!$dbman->table_exists($table)) { 00196 $dbman->create_table($table); 00197 } 00198 } 00199 00203 function wiki_upgrade_migrate_versions() { 00204 global $DB, $CFG, $OUTPUT; 00205 require_once($CFG->dirroot . '/mod/wiki/db/migration/lib.php'); 00206 // need to move the binary data in db 00207 $fs = get_file_storage(); 00208 // select all wiki pages history 00209 $sql = "SELECT po.id AS oldpage_id, po.pagename AS oldpage_pagename, po.version, po.flags, 00210 po.content, po.author, po.userid AS oldpage_userid, po.created, po.lastmodified, po.refs, po.meta, po.hits, po.wiki, 00211 p.id AS newpage_id, p.subwikiid, p.title, p.cachedcontent, p.timecreated, p.timemodified AS newpage_timemodified, 00212 p.timerendered, p.userid AS newpage_userid, p.pageviews, p.readonly, e.id AS entry_id, e.wikiid, e.course AS entrycourse, 00213 e.groupid, e.userid AS entry_userid, e.pagename AS entry_pagename, e.timemodified AS entry_timemodified, 00214 w.id AS wiki_id, w.course AS wiki_course, w.name, w.summary AS summary, w.pagename AS wiki_pagename, w.wtype, 00215 w.ewikiprinttitle, w.htmlmode, w.ewikiacceptbinary, w.disablecamelcase, w.setpageflags, w.strippages, w.removepages, 00216 w.revertchanges, w.initialcontent, w.timemodified AS wiki_timemodified, 00217 cm.id AS cmid 00218 FROM {wiki_pages_old} po 00219 LEFT OUTER JOIN {wiki_entries_old} e ON e.id = po.wiki 00220 LEFT OUTER JOIN {wiki} w ON w.id = e.wikiid 00221 LEFT OUTER JOIN {wiki_subwikis} s ON e.groupid = s.groupid AND e.wikiid = s.wikiid AND e.userid = s.userid 00222 LEFT OUTER JOIN {wiki_pages} p ON po.pagename = p.title AND p.subwikiid = s.id 00223 JOIN {modules} m ON m.name = 'wiki' 00224 JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = w.id)"; 00225 00226 $pagesinfo = $DB->get_recordset_sql($sql, array()); 00227 00228 foreach ($pagesinfo as $pageinfo) { 00229 upgrade_set_timeout(); 00230 00231 $mimetype = ewiki_mime_magic($pageinfo->content); 00232 if (!empty($mimetype)) { 00233 // if mimetype is not empty, means this is a file stored in db 00234 $context = get_context_instance(CONTEXT_MODULE, $pageinfo->cmid); 00235 // clean up file name 00236 $filename = clean_param($pageinfo->oldpage_pagename, PARAM_FILE); 00237 $filerecord = array('contextid' => $context->id, 00238 'component' => 'mod_wiki', 00239 'filearea' => 'attachments', 00240 'itemid' => $pageinfo->subwikiid, 00241 'filepath' => '/', 00242 'filename' => $filename, 00243 'userid' => $pageinfo->oldpage_userid); 00244 if (!$fs->file_exists($context->id, 'mod_wiki', 'attachments', $pageinfo->subwikiid, '/', $pageinfo->pagename)) { 00245 $storedfile = $fs->create_file_from_string($filerecord, $pageinfo->content); 00246 } 00247 00248 // replace page content to a link point to the file 00249 $pageinfo->content = "<a href='@@PLUGINFILE@@/$filename'>$pageinfo->oldpage_pagename</a>"; 00250 } 00251 00252 $oldpage = new StdClass(); 00253 $oldpage->id = $pageinfo->oldpage_id; 00254 $oldpage->pagename = $pageinfo->oldpage_pagename; 00255 $oldpage->version = $pageinfo->version; 00256 $oldpage->flags = $pageinfo->flags; 00257 $oldpage->content = $pageinfo->content; 00258 $oldpage->author = $pageinfo->author; 00259 $oldpage->userid = $pageinfo->oldpage_userid; 00260 $oldpage->created = $pageinfo->created; 00261 $oldpage->lastmodified = $pageinfo->lastmodified; 00262 $oldpage->refs = $pageinfo->refs; 00263 $oldpage->meta = $pageinfo->meta; 00264 $oldpage->hits = $pageinfo->hits; 00265 $oldpage->wiki = $pageinfo->wiki; 00266 00267 $page = new StdClass(); 00268 $page->id = $pageinfo->newpage_id; 00269 $page->subwikiid = $pageinfo->subwikiid; 00270 $page->title = $pageinfo->title; 00271 $page->cachedcontent = $pageinfo->cachedcontent; 00272 $page->timecreated = $pageinfo->timecreated; 00273 $page->timemodified = $pageinfo->newpage_timemodified; 00274 $page->timerendered = $pageinfo->timerendered; 00275 $page->userid = $pageinfo->newpage_userid; 00276 $page->pageviews = $pageinfo->pageviews; 00277 $page->readonly = $pageinfo->readonly; 00278 00279 $entry = new StdClass(); 00280 $entry->id = $pageinfo->entry_id; 00281 $entry->wikiid = $pageinfo->wikiid; 00282 $entry->course = $pageinfo->entrycourse; 00283 $entry->groupid = $pageinfo->groupid; 00284 $entry->userid = $pageinfo->entry_userid; 00285 $entry->pagename = $pageinfo->entry_pagename; 00286 $entry->timemodified = $pageinfo->entry_timemodified; 00287 00288 $wiki = new StdClass(); 00289 $wiki->id = $pageinfo->wiki_id; 00290 $wiki->course = $pageinfo->wiki_course; 00291 $wiki->name = $pageinfo->name; 00292 $wiki->summary = $pageinfo->summary; 00293 $wiki->pagename = $pageinfo->wiki_pagename; 00294 $wiki->wtype = $pageinfo->wtype; 00295 $wiki->ewikiprinttitle = $pageinfo->ewikiprinttitle; 00296 $wiki->htmlmode = $pageinfo->htmlmode; 00297 $wiki->ewikiacceptbinary = $pageinfo->ewikiacceptbinary; 00298 $wiki->disablecamelcase = $pageinfo->disablecamelcase; 00299 $wiki->setpageflags = $pageinfo->setpageflags; 00300 $wiki->strippages = $pageinfo->strippages; 00301 $wiki->removepages = $pageinfo->removepages; 00302 $wiki->revertchanges = $pageinfo->revertchanges; 00303 $wiki->initialcontent = $pageinfo->initialcontent; 00304 $wiki->timemodified = $pageinfo->wiki_timemodified; 00305 00306 $version = new StdClass(); 00307 $version->pageid = $page->id; 00308 // convert wiki content to html format 00309 $version->content = wiki_ewiki_2_html($entry, $oldpage, $wiki); 00310 $version->contentformat = 'html'; 00311 $version->version = $oldpage->version; 00312 $version->timecreated = $oldpage->lastmodified; 00313 $version->userid = $oldpage->userid; 00314 if ($version->version == 1) { 00315 // The oldest version of page in moodle 2.0 is 0 which has empty content 00316 // so we need to insert an extra record 00317 try { 00318 $content = $version->content; 00319 $version->version = 0; 00320 $version->content = ''; 00321 $DB->insert_record('wiki_versions', $version); 00322 $version->version = 1; 00323 $version->content = $content; 00324 $DB->insert_record('wiki_versions', $version); 00325 } catch (dml_exception $e) { 00326 debugging($e->getMessage()); 00327 } 00328 } else { 00329 try { 00330 $DB->insert_record('wiki_versions', $version); 00331 } catch (dml_exception $e) { 00332 debugging($e->getMessage()); 00333 } 00334 } 00335 } 00336 00337 $pagesinfo->close(); 00338 }