OSDN Git Service

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