3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2007 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2007 The Nucleus Group
15 * $NucleusJP: upgrade2.5.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
19 function upgrade_do25() {
20 global $upgrade_failures;
21 //needed as some queries depend on the success of others
23 if (upgrade_checkinstall(25))
24 return 'already installed';
26 // -------------------- 2.0 -> 2.2 (dev only) --------------------
27 // (avoid doing this twice :))
28 if (!upgrade_checkinstall(22)) {
29 // 1. create nucleus_plugin_option_desc table
30 // create new table: nucleus_plugin_option
31 if (!upgrade_checkIfTableExists('plugin_option_desc')) {
32 $query = 'CREATE TABLE '. sql_table('plugin_option_desc') . ' ('
33 ." oid int(11) NOT NULL auto_increment UNIQUE,"
34 ." opid int(11) NOT NULL,"
35 ." oname varchar(20) NOT NULL,"
36 ." ocontext varchar(20) NOT NULL,"
37 ." odesc varchar(255),"
38 ." otype varchar(20),"
41 ." PRIMARY KEY(opid, oname, ocontext)"
43 upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
46 // 2. move all data from plugin_option to plugin_option_desc
47 if (0 == $upgrade_failures){
48 $query = 'DELETE FROM ' . sql_table('plugin_option_desc');
49 upgrade_query('Flushing plugin option descriptions', $query);
50 $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC';
51 $res = sql_query($query);
53 while ($o = mysql_fetch_object($res)) {
54 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
55 .' (opid, oname, ocontext, odesc, otype)'
57 ."'".addslashes($o->opid)."',"
58 ."'".addslashes($o->oname) ."',"
60 ."'".addslashes($o->odesc) ."',"
61 ."'".addslashes($o->otype) ."')";
62 upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query);
66 'id' => mysql_insert_id(),
72 // 3. alter plugin_options table
73 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
74 $query = 'ALTER TABLE ' . sql_table('plugin_option')
78 .' DROP COLUMN oname,'
79 .' DROP COLUMN odesc,'
80 .' DROP COLUMN otype,'
81 .' ADD ocontextid INT(11) NOT NULL,'
82 .' ADD PRIMARY KEY (oid, ocontextid)';
83 upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query);
85 if(0 == $upgrade_failures){
86 // 4. delete from plugin_options
87 $query = 'DELETE FROM ' . sql_table('plugin_option');
88 upgrade_query('Cleaning ' . sql_table('plugin_option'), $query);
90 // 5. refill plugin_options
91 foreach ($aValues as $aInfo) {
92 $query = 'INSERT INTO ' . sql_table('plugin_option')
93 .' (oid, ocontextid, ovalue)'
94 ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')";
95 upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query);
101 // -------------------- 2.0 -> 2.5 --------------------
103 if (!upgrade_checkIfIndexExists('item', array('ibody', 'ititle', 'imore'))) {
104 // add fulltext indices for search
105 $query = 'ALTER TABLE ' . sql_table('item') . ' ADD FULLTEXT(ibody, ititle, imore)';
106 upgrade_query('Adding fulltext index to item table', $query);
107 // repair table is needed (build index)
108 upgrade_query('Repairing item table', 'REPAIR TABLE ' . sql_table('item'));
111 if (!upgrade_checkIfIndexExists('comment', array('cbody'))) {
112 $query = 'ALTER TABLE ' . sql_table('comment') . ' ADD FULLTEXT(cbody)';
113 upgrade_query('Adding fulltext index to comments table', $query);
114 upgrade_query('Repairing comment table', 'REPAIR TABLE ' . sql_table('comment'));
117 if (!upgrade_checkinstall(24)) {
118 $query = ' ALTER TABLE ' . sql_table('blog') . ' ADD bincludesearch TINYINT(2) DEFAULT 0';
119 upgrade_query('Adding bincludesearch column to blog', $query);
122 // modify plugin option table value column type to TEXT
123 $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\'';
124 upgrade_query('Modifying plugin options column type', $query);
126 // insert External Authentication global option
127 if (!upgrade_checkIfCVExists('ExtAuth')) {
128 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')';
129 upgrade_query('Adding External Authentication option to config table', $query);
132 // insert database version (allows us to do better version checking in v3.0 upgrades)
133 // But only if no errors in upgrade
134 if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) {
135 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')';
136 upgrade_query('Adding DatabaseVersion to config table', $query);
138 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";