OSDN Git Service

instructions for manually adding .htaccess files to media and skins folder after...
[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-2009 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         /**
14          * Some functions common to all upgrade scripts
15          *
16          * @license http://nucleuscms.org/license.txt GNU General Public License
17          * @copyright Copyright (C) 2002-2009 The Nucleus Group
18          * @version $Id$
19          * $NucleusJP: upgrade.functions.php,v 1.10 2007/04/26 06:20:19 kimitake Exp $
20          */
21
22         include('../../config.php');
23
24         // sql_table function did not exists in nucleus <= 2.0
25         if (!function_exists('sql_table'))
26         {
27                 function sql_table($name) {
28                         return 'nucleus_' . $name;
29                 }
30         }
31
32         //intGetVar did not exist in very early versions
33         if (!function_exists('intGetVar')) {
34                 function intGetVar($name) {
35                         if (defined($_GET)) {
36                                 return intval($_GET[$name]);
37                         } else {
38                                 global $HTTP_GET_VARS;
39                                 return intval($HTTP_GET_VARS[$name]);
40                         }
41                 }
42         }
43
44         function upgrade_checkinstall($version) {
45                 $installed = 0;
46
47                 switch($version) {
48                         case '95':
49                                 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
50                                 $minrows = -1;
51                                 break;
52                         case '96':
53                                 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
54                                 $minrows = -1;
55                                 break;
56                         case '10':
57                                 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
58                                 $minrows = -1;
59                                 break;
60                         case '11':
61                                 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
62                                 $minrows = -1;
63                                 break;
64                         case '15':
65                                 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
66                                 $minrows = -1;
67                                 break;
68                         case '20':
69                                 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
70                                 $minrows = -1;
71                                 break;
72                         // dev only (v2.2)
73                         case '22':
74                                 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
75                                 $minrows = -1;
76                                 break;
77                         // v2.5 beta
78                         case '24':
79                                 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
80                                 $minrows = -1;
81                                 break;
82                         case '25':
83                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
84                                 $minrows = 1;
85                                 break;
86                         case '30':
87                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
88                                 $minrows = 1;
89                                 break;
90                         case '31':
91                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
92                                 $minrows = 1;
93                                 break;
94                         case '32':
95                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
96                                 $minrows = 1;
97                                 break;
98                         case '33':
99                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 330 LIMIT 1';
100                                 $minrows = 1;
101                                 break;
102                         case '331':
103                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 331 LIMIT 1';
104                                 $minrows = 1;
105                                 break;
106                         case '34':
107                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 340 LIMIT 1';
108                                 $minrows = 1;
109                                 break;
110                 }
111
112                 $res = mysql_query($query);
113                 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
114
115                 return $installed;
116         }
117
118
119         /** this function gets the nucleus version, even if the getNucleusVersion
120          * function does not exist yet
121          * return 96 for all versions < 100
122          */
123         function upgrade_getNucleusVersion() {
124                 if (!function_exists('getNucleusVersion')) return 96;
125                 return getNucleusVersion();
126         }
127
128         function upgrade_showLogin($type) {
129                 upgrade_head();
130         ?>
131                 <h1>まずはログインして下さい</h1>
132                 <p>下記の情報を入力して下さい:</p>
133
134                 <form method="post" action="<?php echo $type?>">
135
136                         <ul>
137                                 <li>名前: <input name="login" /></li>
138                                 <li>パスワード <input name="password" type="password" /></li>
139                         </ul>
140
141                         <p>
142                                 <input name="action" value="login" type="hidden" />
143                                 <input type="submit" value="ログイン" />
144                         </p>
145
146                 </form>
147         <?php           upgrade_foot();
148                 exit;
149         }
150
151         function upgrade_head() {
152         ?>
153                         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
154                         <html xmlns="http://www.w3.org/1999/xhtml">
155                         <head>
156                                 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
157                                 <title>Nucleus アップグレード</title>
158 <?php if (file_exists("../styles/manual.css")) { ?>
159                                 <link rel="stylesheet" href="../styles/manual.css" type="text/css" />
160 <?php }else{ ?>
161                                 <style type="text/css"><!--
162                                         .warning {
163                                                 color: red;
164                                         }
165                                         .ok {
166                                                 color: green;
167                                         }
168                                 --></style>
169 <?php } ?>
170                         </head>
171                         <body>
172         <?php   }
173
174         function upgrade_foot() {
175         ?>
176                         </body>
177                         </html>
178         <?php   }
179
180         function upgrade_error($msg) {
181                 upgrade_head();
182                 ?>
183                 <h1>エラー!</h1>
184
185                 <p>メッセージは以下の通り:</p>
186
187                 <blockquote><div>
188                 <?php echo $msg?>
189                 </div></blockquote>
190
191                 <p><a href="index.php" onclick="history.back();">戻る</a></p>
192                 <?php
193                 upgrade_foot();
194                 exit;
195         }
196
197
198         function upgrade_start() {
199                 global $upgrade_failures;
200                 $upgrade_failures = 0;
201
202                 upgrade_head();
203                 ?>
204                 <h1>アップグレードの実行</h1>
205                 <ul>
206                 <?php   }
207
208         function upgrade_end($msg = "") {
209                 global $upgrade_failures;
210                 $from = intGetVar('from');
211                 if ($upgrade_failures > 0)
212                         $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
213
214                 ?>
215                 </ul>
216
217                 <h1>アップグレード完了!</h1>
218
219                 <p><?php echo $msg?></p>
220
221                 <p><a href="index.php?from=<?php echo $from; ?>">アップグレード最初のページ</a>にもどる</p>
222
223                 <?php
224                 upgrade_foot();
225                 exit;
226         }
227
228         /**
229           * Tries to execute a query, gives a message when failed
230           *
231           * @param friendly name
232           * @param query
233           */
234         function upgrade_query($friendly, $query) {
235                 global $upgrade_failures;
236
237                 echo "<li>$friendly ... ";
238                 $res = mysql_query($query);
239                 if (!$res) {
240                         echo "<span style='color:red'>失敗</span>\n";
241                         echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
242                         $upgrade_failures++;
243                 } else {
244                         echo "<span style='color:green'>成功!</span><br />\n";
245                 }
246                 echo "</li>";
247                 return $res;
248         }
249
250         /**
251           * Tries to update database version, gives a message when failed
252           *
253           * @param $version
254           *     Schema version the database has been upgraded to
255           */
256         function update_version($version) {
257                 global $upgrade_failures;
258                 $message='Updating DatabaseVersion in config table to '.$version;
259                 if(0==$upgrade_failures){
260                         $query = 'UPDATE ' . sql_table('config') . ' set value=\''.$version.'\' where name=\'DatabaseVersion\'';
261                         upgrade_query($message, $query);
262                 }else
263                         echo '<li>'.$message.' ... <span class="warning">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>';
264         }
265
266         /**
267          * @param $table
268          *              table to check (without prefix)
269          * @param $aColumns
270          *              array of column names included
271          */
272         function upgrade_checkIfIndexExists($table, $aColumns) {
273                 // get info for indices from database
274
275                 $aIndices = array();
276                 $query = 'show index from ' . sql_table($table);
277                 $res = mysql_query($query);
278                 while ($o = mysql_fetch_object($res)) {
279                         if (!$aIndices[$o->Key_name]) {
280                                 $aIndices[$o->Key_name] = array();
281                         }
282                         array_push($aIndices[$o->Key_name], $o->Column_name);
283                 }
284
285                 // compare each index with parameter
286                 foreach ($aIndices as $keyName => $aIndexColumns) {
287                         $aDiff = array_diff($aIndexColumns, $aColumns);
288                         if (count($aDiff) == 0) return 1;
289                 }
290
291                 return 0;
292
293         }
294
295         /**
296           * Checks to see if a given table exists
297           *
298           * @param $table
299           *     Name of table to check for existance of
300           *     Uses sql_table internally
301           * @return true if table exists, false otherwise.
302           */
303         function upgrade_checkIfTableExists($table){
304                 $query = 'SHOW TABLES LIKE \''.sql_table($table).'\'';
305                 $res = mysql_query($query);
306                 return ($res != 0) && (mysql_num_rows($res) == 1);
307         }
308
309         /**
310           * Checks to see if a given configuration value exists
311           *
312           * @param $value
313           *     Config value to check for existance of.
314           *     Paramater must be MySQL escaped
315           * @return true if configuration value exists, false otherwise.
316           */
317         function upgrade_checkIfCVExists($value){
318                 $query = 'SELECT name from '.sql_table('config').' WHERE name = \''.$value.'\'';
319                 $res = mysql_query($query);
320                 return ($res != 0) && (mysql_num_rows($res) == 1);
321         }
322
323         /**
324           * Checks to see if a given column exists
325           *
326           * @param $table
327           *     Name of table to check for column in
328           *     Uses sql_table internally
329           * @param $col
330           *     Name of column to check for existance of
331           * @return true if column exists, false otherwise.
332           */
333         function upgrade_checkIfColumnExists($table, $col){
334                 $query = 'DESC `'.sql_table($table).'` `'.$col.'`';
335                 $res = mysql_query($query);
336                 return ($res != 0) && (mysql_num_rows($res) == 1);
337         }
338 ?>