OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / upgrades / upgrade2.5.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2007 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-2007 The Nucleus Group
15  * $NucleusJP: upgrade2.5.php,v 1.3.2.1 2007/10/24 05:39:16 kimitake Exp $
16  *
17  */
18
19 function upgrade_do25() {
20         global $upgrade_failures;
21                 //needed as some queries depend on the success of others
22
23         if (upgrade_checkinstall(25))
24                 return 'already installed';
25
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),"
39                                    ." odef text,"
40                                    ." oextra text,"
41                                    ." PRIMARY KEY(opid, oname, ocontext)"
42                                    .") TYPE=MyISAM;";
43                         upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
44                 }
45
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);
52                         $aValues = array();
53                         while ($o = mysql_fetch_object($res)) {
54                                 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
55                                            .' (opid, oname, ocontext, odesc, otype)'
56                                            ." VALUES ("
57                                                         ."'".addslashes($o->opid)."',"
58                                                         ."'".addslashes($o->oname) ."',"
59                                                         ."'global',"
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);
63         
64                                 // store new id
65                                 $aValues[] = array ( 
66                                                                 'id' => mysql_insert_id(),
67                                                                 'value' => $o->ovalue
68                                                         );
69                         }
70                 }
71
72                 // 3. alter plugin_options table 
73                 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
74                         $query = 'ALTER TABLE ' . sql_table('plugin_option')
75                                    .' DROP PRIMARY KEY,'
76                                    .' DROP KEY oid,'
77                                    .' DROP COLUMN opid,'
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);
84                         
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);
89                 
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);
96                                 }
97                         }       
98                 }
99         }               
100         
101         // -------------------- 2.0 -> 2.5 --------------------
102         
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'));
109         }
110         
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'));       
115         }       
116         
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);
120         }
121         
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);
125         
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); 
130         }
131         
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);
137         }else{
138                 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
139         }
140 }
141
142 ?>