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 function upgrade_do250() {
14 global $upgrade_failures;
15 //needed as some queries depend on the success of others
17 if (upgrade_checkinstall(250))
20 // -------------------- 2.0 -> 2.2 (dev only) --------------------
21 // (avoid doing this twice :))
22 if (!upgrade_checkinstall(220)) {
23 // 1. create nucleus_plugin_option_desc table
24 // create new table: nucleus_plugin_option
25 if (!upgrade_checkIfTableExists('plugin_option_desc')) {
26 $query = 'CREATE TABLE '. sql_table('plugin_option_desc') . ' ('
27 ." oid int(11) NOT NULL auto_increment UNIQUE,"
28 ." opid int(11) NOT NULL,"
29 ." oname varchar(20) NOT NULL,"
30 ." ocontext varchar(20) NOT NULL,"
31 ." odesc varchar(255),"
32 ." otype varchar(20),"
35 ." PRIMARY KEY(opid, oname, ocontext)"
37 upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
40 // 2. move all data from plugin_option to plugin_option_desc
41 if (0 == $upgrade_failures){
42 $query = 'DELETE FROM ' . sql_table('plugin_option_desc');
43 upgrade_query('Flushing plugin option descriptions', $query);
44 $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC';
45 $res = sql_query($query);
47 while ($o = mysql_fetch_object($res)) {
48 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
49 .' (opid, oname, ocontext, odesc, otype)'
51 ."'".addslashes($o->opid)."',"
52 ."'".addslashes($o->oname) ."',"
54 ."'".addslashes($o->odesc) ."',"
55 ."'".addslashes($o->otype) ."')";
56 upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query);
60 'id' => mysql_insert_id(),
66 // 3. alter plugin_options table
67 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
68 $query = 'ALTER TABLE ' . sql_table('plugin_option')
72 .' DROP COLUMN oname,'
73 .' DROP COLUMN odesc,'
74 .' DROP COLUMN otype,'
75 .' ADD ocontextid INT(11) NOT NULL,'
76 .' ADD PRIMARY KEY (oid, ocontextid)';
77 upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query);
79 if(0 == $upgrade_failures){
80 // 4. delete from plugin_options
81 $query = 'DELETE FROM ' . sql_table('plugin_option');
82 upgrade_query('Cleaning ' . sql_table('plugin_option'), $query);
84 // 5. refill plugin_options
85 foreach ($aValues as $aInfo) {
86 $query = 'INSERT INTO ' . sql_table('plugin_option')
87 .' (oid, ocontextid, ovalue)'
88 ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')";
89 upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query);
95 // -------------------- 2.0 -> 2.5 --------------------
97 if (!upgrade_checkIfIndexExists('item', array('ibody', 'ititle', 'imore'))) {
98 // add fulltext indices for search
99 $query = 'ALTER TABLE ' . sql_table('item') . ' ADD FULLTEXT(ibody, ititle, imore)';
100 upgrade_query('Adding fulltext index to item table', $query);
101 // repair table is needed (build index)
102 upgrade_query('Repairing item table', 'REPAIR TABLE ' . sql_table('item'));
105 if (!upgrade_checkIfIndexExists('comment', array('cbody'))) {
106 $query = 'ALTER TABLE ' . sql_table('comment') . ' ADD FULLTEXT(cbody)';
107 upgrade_query('Adding fulltext index to comments table', $query);
108 upgrade_query('Repairing comment table', 'REPAIR TABLE ' . sql_table('comment'));
111 if (!upgrade_checkinstall(240)) {
112 $query = ' ALTER TABLE ' . sql_table('blog') . ' ADD bincludesearch TINYINT(2) DEFAULT 0';
113 upgrade_query('Adding bincludesearch column to blog', $query);
116 // modify plugin option table value column type to TEXT
117 $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\'';
118 upgrade_query('Modifying plugin options column type', $query);
120 // insert External Authentication global option
121 if (!upgrade_checkIfCVExists('ExtAuth')) {
122 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')';
123 upgrade_query('Adding External Authentication option to config table', $query);
126 // insert database version (allows us to do better version checking in v3.0 upgrades)
127 // But only if no errors in upgrade
128 if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) {
129 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')';
130 upgrade_query('Adding DatabaseVersion to config table', $query);
132 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";