OSDN Git Service

FIX: super-admin disallowed from uploading files if not on any teamlists.
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade2.5.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
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)
11  */
12 /**
13  * @license http://nucleuscms.org/license.txt GNU General Public License
14  * @copyright Copyright (C) 2002-2009 The Nucleus Group
15  * @version $Id$
16  * $NucleusJP: upgrade2.5.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
17  *
18  */
19
20 function upgrade_do250() {
21         global $upgrade_failures;
22                 //needed as some queries depend on the success of others
23
24         if (upgrade_checkinstall(250))
25                 return 'already installed';
26
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),"
40                                    ." odef text,"
41                                    ." oextra text,"
42                                    ." PRIMARY KEY(opid, oname, ocontext)"
43                                    .") TYPE=MyISAM;";
44                         upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
45                 }
46
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);
53                         $aValues = array();
54                         while ($o = mysql_fetch_object($res)) {
55                                 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
56                                            .' (opid, oname, ocontext, odesc, otype)'
57                                            ." VALUES ("
58                                                         ."'".addslashes($o->opid)."',"
59                                                         ."'".addslashes($o->oname) ."',"
60                                                         ."'global',"
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);
64         
65                                 // store new id
66                                 $aValues[] = array ( 
67                                                                 'id' => mysql_insert_id(),
68                                                                 'value' => $o->ovalue
69                                                         );
70                         }
71                 }
72
73                 // 3. alter plugin_options table 
74                 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
75                         $query = 'ALTER TABLE ' . sql_table('plugin_option')
76                                    .' DROP PRIMARY KEY,'
77                                    .' DROP KEY oid,'
78                                    .' DROP COLUMN opid,'
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);
85                         
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);
90                 
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);
97                                 }
98                         }       
99                 }
100         }               
101         
102         // -------------------- 2.0 -> 2.5 --------------------
103         
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'));
110         }
111         
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'));       
116         }       
117         
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);
121         }
122         
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);
126         
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); 
131         }
132         
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);
138         }else{
139                 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
140         }
141 }
142
143 ?>