3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 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-2012 The Nucleus Group
15 * @version $Id: upgrade2.5.php 1889 2012-06-17 08:46:45Z sakamocchi $
18 function upgrade_do250() {
19 global $upgrade_failures;
20 //needed as some queries depend on the success of others
22 if (upgrade_checkinstall(250))
23 return 'already installed';
25 // -------------------- 2.0 -> 2.2 (dev only) --------------------
26 // (avoid doing this twice :))
27 if (!upgrade_checkinstall(220)) {
28 // 1. create nucleus_plugin_option_desc table
29 // create new table: nucleus_plugin_option
30 if (!upgrade_checkIfTableExists('plugin_option_desc')) {
31 $query = 'CREATE TABLE '. sql_table('plugin_option_desc') . ' ('
32 ." oid int(11) NOT NULL auto_increment UNIQUE,"
33 ." opid int(11) NOT NULL,"
34 ." oname varchar(20) NOT NULL,"
35 ." ocontext varchar(20) NOT NULL,"
36 ." odesc varchar(255),"
37 ." otype varchar(20),"
40 ." PRIMARY KEY(opid, oname, ocontext)"
42 upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
45 // 2. move all data from plugin_option to plugin_option_desc
46 if (0 == $upgrade_failures){
47 $query = 'DELETE FROM ' . sql_table('plugin_option_desc');
48 upgrade_query('Flushing plugin option descriptions', $query);
49 $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC';
50 $res = DB::getResult($query);
52 foreach ( $res as $row) {
53 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
54 .' (opid, oname, ocontext, odesc, otype)'
56 ."'".addslashes($row['opid'])."',"
57 ."'".addslashes($row['oname']) ."',"
59 ."'".addslashes($row['odesc']) ."',"
60 ."'".addslashes($row['otype']) ."')";
61 upgrade_query('Moving option description for '.i18n::hsc($row['oname']).' to ' . sql_table('plugin_option_desc'), $query);
65 'id' => DB::getInsertId(),
66 'value' => $row['ovalue']
71 // 3. alter plugin_options table
72 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
73 $query = 'ALTER TABLE ' . sql_table('plugin_option')
77 .' DROP COLUMN oname,'
78 .' DROP COLUMN odesc,'
79 .' DROP COLUMN otype,'
80 .' ADD ocontextid INT(11) NOT NULL,'
81 .' ADD PRIMARY KEY (oid, ocontextid)';
82 upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query);
84 if(0 == $upgrade_failures){
85 // 4. delete from plugin_options
86 $query = 'DELETE FROM ' . sql_table('plugin_option');
87 upgrade_query('Cleaning ' . sql_table('plugin_option'), $query);
89 // 5. refill plugin_options
90 foreach ($aValues as $aInfo) {
91 $query = 'INSERT INTO ' . sql_table('plugin_option')
92 .' (oid, ocontextid, ovalue)'
93 ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')";
94 upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query);
100 // -------------------- 2.0 -> 2.5 --------------------
102 if (!upgrade_checkIfIndexExists('item', array('ibody', 'ititle', 'imore'))) {
103 // add fulltext indices for search
104 $query = 'ALTER TABLE ' . sql_table('item') . ' ADD FULLTEXT(ibody, ititle, imore)';
105 upgrade_query('Adding fulltext index to item table', $query);
106 // repair table is needed (build index)
107 upgrade_query('Repairing item table', 'REPAIR TABLE ' . sql_table('item'));
110 if (!upgrade_checkIfIndexExists('comment', array('cbody'))) {
111 $query = 'ALTER TABLE ' . sql_table('comment') . ' ADD FULLTEXT(cbody)';
112 upgrade_query('Adding fulltext index to comments table', $query);
113 upgrade_query('Repairing comment table', 'REPAIR TABLE ' . sql_table('comment'));
116 if (!upgrade_checkinstall(240)) {
117 $query = ' ALTER TABLE ' . sql_table('blog') . ' ADD bincludesearch TINYINT(2) DEFAULT 0';
118 upgrade_query('Adding bincludesearch column to blog', $query);
121 // modify plugin option table value column type to TEXT
122 $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\'';
123 upgrade_query('Modifying plugin options column type', $query);
125 // insert External Authentication global option
126 if (!upgrade_checkIfCVExists('ExtAuth')) {
127 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')';
128 upgrade_query('Adding External Authentication option to config table', $query);
131 // insert database version (allows us to do better version checking in v3.0 upgrades)
132 // But only if no errors in upgrade
133 if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) {
134 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')';
135 upgrade_query('Adding DatabaseVersion to config table', $query);
137 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";