3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2011 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-2011 The Nucleus Group
16 * $NucleusJP: upgrade2.5.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
20 function upgrade_do250() {
21 global $upgrade_failures;
22 //needed as some queries depend on the success of others
24 if (upgrade_checkinstall(250))
27 // -------------------- 2.0 -> 2.2 (dev only) --------------------
28 // (avoid doing this twice :))
29 if (!upgrade_checkinstall(220)) {
30 // 1. create nucleus_plugin_option_desc table
31 // create new table: nucleus_plugin_option
32 if (!upgrade_checkIfTableExists('plugin_option_desc')) {
33 $query = 'CREATE TABLE '. sql_table('plugin_option_desc') . ' ('
34 ." oid int(11) NOT NULL auto_increment UNIQUE,"
35 ." opid int(11) NOT NULL,"
36 ." oname varchar(20) NOT NULL,"
37 ." ocontext varchar(20) NOT NULL,"
38 ." odesc varchar(255),"
39 ." otype varchar(20),"
42 ." PRIMARY KEY(opid, oname, ocontext)"
44 upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
47 // 2. move all data from plugin_option to plugin_option_desc
48 if (0 == $upgrade_failures){
49 $query = 'DELETE FROM ' . sql_table('plugin_option_desc');
50 upgrade_query('Flushing plugin option descriptions', $query);
51 $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC';
52 $res = sql_query($query);
54 while ($o = mysql_fetch_object($res)) {
55 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
56 .' (opid, oname, ocontext, odesc, otype)'
58 ."'".addslashes($o->opid)."',"
59 ."'".addslashes($o->oname) ."',"
61 ."'".addslashes($o->odesc) ."',"
62 ."'".addslashes($o->otype) ."')";
63 upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query);
67 'id' => mysql_insert_id(),
73 // 3. alter plugin_options table
74 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
75 $query = 'ALTER TABLE ' . sql_table('plugin_option')
79 .' DROP COLUMN oname,'
80 .' DROP COLUMN odesc,'
81 .' DROP COLUMN otype,'
82 .' ADD ocontextid INT(11) NOT NULL,'
83 .' ADD PRIMARY KEY (oid, ocontextid)';
84 upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query);
86 if(0 == $upgrade_failures){
87 // 4. delete from plugin_options
88 $query = 'DELETE FROM ' . sql_table('plugin_option');
89 upgrade_query('Cleaning ' . sql_table('plugin_option'), $query);
91 // 5. refill plugin_options
92 foreach ($aValues as $aInfo) {
93 $query = 'INSERT INTO ' . sql_table('plugin_option')
94 .' (oid, ocontextid, ovalue)'
95 ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')";
96 upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query);
102 // -------------------- 2.0 -> 2.5 --------------------
104 if (!upgrade_checkIfIndexExists('item', array('ibody', 'ititle', 'imore'))) {
105 // add fulltext indices for search
106 $query = 'ALTER TABLE ' . sql_table('item') . ' ADD FULLTEXT(ibody, ititle, imore)';
107 upgrade_query('Adding fulltext index to item table', $query);
108 // repair table is needed (build index)
109 upgrade_query('Repairing item table', 'REPAIR TABLE ' . sql_table('item'));
112 if (!upgrade_checkIfIndexExists('comment', array('cbody'))) {
113 $query = 'ALTER TABLE ' . sql_table('comment') . ' ADD FULLTEXT(cbody)';
114 upgrade_query('Adding fulltext index to comments table', $query);
115 upgrade_query('Repairing comment table', 'REPAIR TABLE ' . sql_table('comment'));
118 if (!upgrade_checkinstall(240)) {
119 $query = ' ALTER TABLE ' . sql_table('blog') . ' ADD bincludesearch TINYINT(2) DEFAULT 0';
120 upgrade_query('Adding bincludesearch column to blog', $query);
123 // modify plugin option table value column type to TEXT
124 $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\'';
125 upgrade_query('Modifying plugin options column type', $query);
127 // insert External Authentication global option
128 if (!upgrade_checkIfCVExists('ExtAuth')) {
129 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')';
130 upgrade_query('Adding External Authentication option to config table', $query);
133 // insert database version (allows us to do better version checking in v3.0 upgrades)
134 // But only if no errors in upgrade
135 if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) {
136 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')';
137 upgrade_query('Adding DatabaseVersion to config table', $query);
139 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";