OSDN Git Service

4467f6c22b0d842fa4cbfa93b134a8957dd1eadd
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade2.5.php
1 <?php
2 function upgrade_do25() {
3         global $upgrade_failures;
4                 //needed as some queries depend on the success of others
5
6         if (upgrade_checkinstall(25))
7                 return 'already installed';
8
9         // -------------------- 2.0 -> 2.2 (dev only) --------------------
10         // (avoid doing this twice :))
11         if (!upgrade_checkinstall(22))  {
12                 // 1. create nucleus_plugin_option_desc table
13                 // create new table: nucleus_plugin_option
14                 if (!upgrade_checkIfTableExists('plugin_option_desc')) {
15                         $query = 'CREATE TABLE '. sql_table('plugin_option_desc') . ' ('
16                                    ." oid int(11) NOT NULL auto_increment UNIQUE,"
17                                    ." opid int(11) NOT NULL,"
18                                    ." oname varchar(20) NOT NULL,"
19                                    ." ocontext varchar(20) NOT NULL,"
20                                    ." odesc varchar(255),"
21                                    ." otype varchar(20),"
22                                    ." odef text,"
23                                    ." oextra text,"
24                                    ." PRIMARY KEY(opid, oname, ocontext)"
25                                    .") TYPE=MyISAM;";
26                         upgrade_query('Creating ' . sql_table('plugin_option_desc') . ' table',$query);
27                 }
28
29                 // 2. move all data from plugin_option to plugin_option_desc
30                 if (0 == $upgrade_failures){
31                         $query = 'DELETE FROM ' . sql_table('plugin_option_desc');
32                         upgrade_query('Flushing plugin option descriptions', $query);
33                         $query = 'SELECT * FROM ' . sql_table('plugin_option') .' ORDER BY oid ASC';
34                         $res = sql_query($query);
35                         $aValues = array();
36                         while ($o = mysql_fetch_object($res)) {
37                                 $query = 'INSERT INTO ' . sql_table('plugin_option_desc')
38                                            .' (opid, oname, ocontext, odesc, otype)'
39                                            ." VALUES ("
40                                                         ."'".addslashes($o->opid)."',"
41                                                         ."'".addslashes($o->oname) ."',"
42                                                         ."'global',"
43                                                         ."'".addslashes($o->odesc) ."',"
44                                                         ."'".addslashes($o->otype) ."')";
45                                 upgrade_query('Moving option description for '.htmlspecialchars($o->oname).' to ' . sql_table('plugin_option_desc'), $query);
46         
47                                 // store new id
48                                 $aValues[] = array ( 
49                                                                 'id' => mysql_insert_id(),
50                                                                 'value' => $o->ovalue
51                                                         );
52                         }
53                 }
54
55                 // 3. alter plugin_options table 
56                 if (0 == $upgrade_failures && !upgrade_checkIfColumnExists('plugin_option','ocontextid')) {
57                         $query = 'ALTER TABLE ' . sql_table('plugin_option')
58                                    .' DROP PRIMARY KEY,'
59                                    .' DROP KEY oid,'
60                                    .' DROP COLUMN opid,'
61                                    .' DROP COLUMN oname,'
62                                    .' DROP COLUMN odesc,'
63                                    .' DROP COLUMN otype,'               
64                                    .' ADD ocontextid INT(11) NOT NULL,'
65                                    .' ADD PRIMARY KEY (oid, ocontextid)';
66                         upgrade_query('Altering ' . sql_table('plugin_option') . ' table', $query);
67                         
68                         if(0 == $upgrade_failures){
69                                 // 4. delete from plugin_options
70                                 $query = 'DELETE FROM ' . sql_table('plugin_option');
71                                 upgrade_query('Cleaning ' . sql_table('plugin_option'), $query);
72                 
73                                 // 5. refill plugin_options
74                                 foreach ($aValues as $aInfo) {
75                                         $query = 'INSERT INTO ' . sql_table('plugin_option') 
76                                                    .' (oid, ocontextid, ovalue)'
77                                                    ." VALUES (".$aInfo['id'].",'0','".addslashes($aInfo['value'])."')";
78                                         upgrade_query('Re-filling ' . sql_table('plugin_option') . ' ('.$aInfo['id'].')', $query);
79                                 }
80                         }       
81                 }
82         }               
83         
84         // -------------------- 2.0 -> 2.5 --------------------
85         
86         if (!upgrade_checkIfIndexExists('item', array('ibody', 'ititle', 'imore'))) {
87                 // add fulltext indices for search
88                 $query = 'ALTER TABLE ' . sql_table('item') . ' ADD FULLTEXT(ibody, ititle, imore)';
89                 upgrade_query('Adding fulltext index to item table', $query);
90                 // repair table is needed (build index)
91                 upgrade_query('Repairing item table', 'REPAIR TABLE ' . sql_table('item'));
92         }
93         
94         if (!upgrade_checkIfIndexExists('comment', array('cbody'))) {
95                 $query = 'ALTER TABLE ' . sql_table('comment') . ' ADD FULLTEXT(cbody)';
96                 upgrade_query('Adding fulltext index to comments table', $query);       
97                 upgrade_query('Repairing comment table', 'REPAIR TABLE ' . sql_table('comment'));       
98         }       
99         
100         if (!upgrade_checkinstall(24))  {
101             $query = ' ALTER TABLE ' . sql_table('blog') . ' ADD bincludesearch TINYINT(2) DEFAULT 0';
102                 upgrade_query('Adding bincludesearch column to blog', $query);
103         }
104         
105         // modify plugin option table value column type to TEXT
106         $query = 'ALTER TABLE ' . sql_table('plugin_option') . ' MODIFY ovalue TEXT NOT NULL default \'\'';
107         upgrade_query('Modifying plugin options column type', $query);
108         
109         // insert External Authentication global option
110         if (!upgrade_checkIfCVExists('ExtAuth')) {
111                 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'ExtAuth\',\'0\')';
112                 upgrade_query('Adding External Authentication option to config table', $query); 
113         }
114         
115         // insert database version  (allows us to do better version checking in v3.0 upgrades)
116         // But only if no errors in upgrade
117         if (0 == $upgrade_failures && !upgrade_checkIfCVExists('DatabaseVersion')) {
118                 $query = 'INSERT INTO ' . sql_table('config') . ' (name,value) VALUES (\'DatabaseVersion\',\'250\')';
119                 upgrade_query('Adding DatabaseVersion to config table', $query);
120         }else{
121                 echo "<li>Adding DatabaseVersion to config table ... <span class=\"warning\">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>";
122         }
123 }
124
125 ?>