OSDN Git Service

sync with original 3.3
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade.functions.php
1 <?php   
2
3         /**
4           * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
5           * Copyright (C) 2002-2007 The Nucleus Group
6           *
7           * This program is free software; you can redistribute it and/or
8           * modify it under the terms of the GNU General Public License
9           * as published by the Free Software Foundation; either version 2
10           * of the License, or (at your option) any later version.
11           * (see nucleus/documentation/index.html#license for more info)
12           *     
13           * Some functions common to all upgrade scripts
14           *
15           * $Id: upgrade.functions.php,v 1.7 2007-02-04 06:28:46 kimitake Exp $
16           * $NucleusJP: upgrade.functions.php,v 1.6 2006/07/12 07:11:49 kimitake Exp $
17           */
18
19         include('../../config.php');
20         
21         // sql_table function did not exists in nucleus <= 2.0
22         if (!function_exists('sql_table'))
23         {
24                 function sql_table($name) {
25                         return 'nucleus_' . $name;
26                 }
27         }       
28
29         function upgrade_checkinstall($version) {
30                 $installed = 0;
31
32                 switch($version) {
33                         case '95':
34                                 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
35                                 $minrows = -1;
36                                 break;
37                         case '96':
38                                 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
39                                 $minrows = -1;                  
40                                 break;
41                         case '10':
42                                 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
43                                 $minrows = -1;                  
44                                 break;                  
45                         case '11':
46                                 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
47                                 $minrows = -1;                  
48                                 break;
49                         case '15':
50                                 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
51                                 $minrows = -1;                  
52                                 break;                  
53                         case '20':
54                                 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
55                                 $minrows = -1;                  
56                                 break;                          
57                         // dev only (v2.2)
58                         case '22':
59                                 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
60                                 $minrows = -1;                  
61                                 break;
62                         // v2.5 beta
63                         case '24':
64                                 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
65                                 $minrows = -1;                  
66                                 break;                          
67                         case '25':
68                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
69                                 $minrows = 1;
70                                 break;
71                         case '30':
72                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
73                                 $minrows = 1;
74                                 break;
75                         case '31':
76                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
77                                 $minrows = 1;
78                                 break;
79                         case '32':
80                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
81                                 $minrows = 1;
82                                 break;
83                 }
84
85                 $res = mysql_query($query);
86                 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
87
88                 return $installed;
89         }
90         
91         
92         /** this function gets the nucleus version, even if the getNucleusVersion
93          * function does not exist yet
94          * return 96 for all versions < 100
95          */
96         function upgrade_getNucleusVersion() {
97                 if (!function_exists('getNucleusVersion')) return 96;
98                 return getNucleusVersion();
99         }
100         
101         function upgrade_showLogin($type) {
102                 upgrade_head();
103         ?>
104                 <h1>まずはログインして下さい</h1>
105                 <p>下記の情報を入力して下さい:</p>
106                 
107                 <form method="post" action="<?php echo $type?>">
108
109                         <ul>
110                                 <li>名前: <input name="login" /></li>
111                                 <li>パスワード <input name="password" type="password" /></li>
112                         </ul>
113
114                         <p>
115                                 <input name="action" value="login" type="hidden" />
116                                 <input type="submit" value="ログイン" />
117                         </p>
118                 
119                 </form>
120         <?php           upgrade_foot();
121                 exit;
122         }
123         
124         function upgrade_head() {
125         ?>
126                         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
127                         <html xmlns="http://www.w3.org/1999/xhtml">
128                         <head>
129                                 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
130                                 <title>Nucleus アップグレード</title>
131                                 <style><!--
132                                         @import url('../styles/manual.css');
133                                         .warning {
134                                                 color: red;
135                                         }
136                                         .ok {
137                                                 color: green;
138                                         }
139                                 --></style>
140                         </head>
141                         <body>          
142         <?php   }
143
144         function upgrade_foot() {
145         ?>
146                         </body>
147                         </html> 
148         <?php   }       
149         
150         function upgrade_error($msg) {
151                 upgrade_head();
152                 ?>
153                 <h1>エラー!</h1>
154
155                 <p>メッセージは以下の通り:</p>
156                 
157                 <blockquote><div>
158                 <?php echo $msg?>
159                 </div></blockquote>
160
161                 <p><a href="index.php" onclick="history.back();">戻る</a></p>
162                 <?php
163                 upgrade_foot();
164                 exit;
165         }
166         
167         
168         function upgrade_start() {
169                 global $upgrade_failures;
170                 $upgrade_failures = 0;
171                 
172                 upgrade_head();
173                 ?>
174                 <h1>アップグレードの実行</h1>
175                 <ul>
176                 <?php   }
177         
178         function upgrade_end($msg = "") {
179                 global $upgrade_failures;
180                 if ($upgrade_failures > 0)
181                         $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
182         
183                 ?>
184                 </ul>
185                 
186                 <h1>アップグレード完了!</h1>
187
188                 <p><?php echo $msg?></p>
189                 
190                 <p><a href="index.php">アップグレード最初のページ</a>にもどる</p>
191
192                 <?php
193                 upgrade_foot();
194                 exit;
195         }       
196         
197         /**
198           * Tries to execute a query, gives a message when failed
199           *
200           * @param friendly name
201           * @param query                
202           */
203         function upgrade_query($friendly, $query) {
204                 global $upgrade_failures;
205                 
206                 echo "<li>$friendly ... ";
207                 $res = mysql_query($query);
208                 if (!$res) {
209                         echo "<span style='color:red'>失敗</span>\n";
210                         echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
211                         $upgrade_failures++;
212                 } else {
213                         echo "<span style='color:green'>成功!</span><br />\n";
214                 }
215                 echo "</li>";
216                 return $res;
217         }
218         
219         /**
220          * @param $table 
221          *              table to check (without prefix)
222          * @param $aColumns
223          *              array of column names included
224          */
225         function upgrade_checkIfIndexExists($table, $aColumns) {
226                 // get info for indices from database
227                 
228                 $aIndices = array();
229                 $query = 'show index from ' . sql_table($table);
230                 $res = mysql_query($query);
231                 while ($o = mysql_fetch_object($res)) {
232                         if (!$aIndices[$o->Key_name]) {
233                                 $aIndices[$o->Key_name] = array();
234                         }
235                         array_push($aIndices[$o->Key_name], $o->Column_name);
236                 }
237
238                 // compare each index with parameter
239                 foreach ($aIndices as $keyName => $aIndexColumns) {
240                         $aDiff = array_diff($aIndexColumns, $aColumns);
241                         if (count($aDiff) == 0) return 1;
242                 }
243                 
244                 return 0;
245
246         }
247
248
249
250 ?>