OSDN Git Service

This commit was generated by cvs2svn to compensate for changes in r4,
[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-2004 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.1.1.1 2005-02-28 07:15:03 kimitake Exp $\r
16           */\r
17 \r
18         include('../../config.php');\r
19         \r
20         // sql_table function did not exists in nucleus <= 2.0\r
21         if (!function_exists('sql_table'))\r
22         {\r
23                 function sql_table($name) {\r
24                         return 'nucleus_' . $name;\r
25                 }\r
26         }       \r
27 \r
28         function upgrade_checkinstall($version) {\r
29                 $installed = 0;\r
30 \r
31                 switch($version) {\r
32                         case '95':\r
33                                 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';\r
34                                 $minrows = -1;\r
35                                 break;\r
36                         case '96':\r
37                                 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';\r
38                                 $minrows = -1;                  \r
39                                 break;\r
40                         case '10':\r
41                                 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';\r
42                                 $minrows = -1;                  \r
43                                 break;                  \r
44                         case '11':\r
45                                 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';\r
46                                 $minrows = -1;                  \r
47                                 break;\r
48                         case '15':\r
49                                 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';\r
50                                 $minrows = -1;                  \r
51                                 break;                  \r
52                         case '20':\r
53                                 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';\r
54                                 $minrows = -1;                  \r
55                                 break;                          \r
56                         // dev only (v2.2)\r
57                         case '22':\r
58                                 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';\r
59                                 $minrows = -1;                  \r
60                                 break;\r
61                         // v2.5 beta\r
62                         case '24':\r
63                                 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';\r
64                                 $minrows = -1;                  \r
65                                 break;                          \r
66                         case '25':\r
67                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';\r
68                                 $minrows = 1;\r
69                                 break;\r
70                         case '30':\r
71                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';\r
72                                 $minrows = 1;\r
73                                 break;\r
74                         case '31':\r
75                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';\r
76                                 $minrows = 1;\r
77                                 break;\r
78                         case '32':\r
79                                 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';\r
80                                 $minrows = 1;\r
81                                 break;\r
82                 }\r
83 \r
84                 $res = mysql_query($query);\r
85                 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);\r
86 \r
87                 return $installed;\r
88         }\r
89         \r
90         \r
91         /** this function gets the nucleus version, even if the getNucleusVersion\r
92          * function does not exist yet\r
93          * return 96 for all versions < 100\r
94          */\r
95         function upgrade_getNucleusVersion() {\r
96                 if (!function_exists('getNucleusVersion')) return 96;\r
97                 return getNucleusVersion();\r
98         }\r
99         \r
100         function upgrade_showLogin($type) {\r
101                 upgrade_head();\r
102         ?>\r
103                 <h1>Please Log in First</h1>\r
104                 <p>Enter your data below:</p>\r
105                 \r
106                 <form method="post" action="<?php echo $type?>">\r
107 \r
108                         <ul>\r
109                                 <li>Name: <input name="login" /></li>\r
110                                 <li>Password <input name="password" type="password" /></li>\r
111                         </ul>\r
112 \r
113                         <p>\r
114                                 <input name="action" value="login" type="hidden" />\r
115                                 <input type="submit" value="Log in" />\r
116                         </p>\r
117                 \r
118                 </form>\r
119         <?php           upgrade_foot();\r
120                 exit;\r
121         }\r
122         \r
123         function upgrade_head() {\r
124         ?>\r
125                         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
126                         <html xmlns="http://www.w3.org/1999/xhtml">\r
127                         <head>\r
128                                 <title>Nucleus Upgrade</title>\r
129                                 <style><!--\r
130                                         @import url('../styles/manual.css');\r
131                                         .warning {\r
132                                                 color: red;\r
133                                         }\r
134                                         .ok {\r
135                                                 color: green;\r
136                                         }\r
137                                 --></style>\r
138                         </head>\r
139                         <body>          \r
140         <?php   }\r
141 \r
142         function upgrade_foot() {\r
143         ?>\r
144                         </body>\r
145                         </html> \r
146         <?php   }       \r
147         \r
148         function upgrade_error($msg) {\r
149                 upgrade_head();\r
150                 ?>\r
151                 <h1>Error!</h1>\r
152 \r
153                 <p>Message was:</p>\r
154                 \r
155                 <blockquote><div>\r
156                 <?php echo $msg?>\r
157                 </div></blockquote>\r
158 \r
159                 <p><a href="index.php" onclick="history.back();">Go Back</a></p>\r
160                 <?php\r
161                 upgrade_foot();\r
162                 exit;\r
163         }\r
164         \r
165         \r
166         function upgrade_start() {\r
167                 global $upgrade_failures;\r
168                 $upgrade_failures = 0;\r
169                 \r
170                 upgrade_head();\r
171                 ?>\r
172                 <h1>Executing Upgrades</h1>\r
173                 <ul>\r
174                 <?php   }\r
175         \r
176         function upgrade_end($msg = "") {\r
177                 global $upgrade_failures;\r
178                 if ($upgrade_failures > 0)\r
179                         $msg = "Some queries have failed. If you've runned this upgrade script before, this should be normal.";\r
180         \r
181                 ?>\r
182                 </ul>\r
183                 \r
184                 <h1>Upgrade Completed!</h1>\r
185 \r
186                 <p><?php echo $msg?></p>\r
187                 \r
188                 <p>Back to the <a href="index.php">Upgrades Overview</a></p>\r
189 \r
190                 <?php\r
191                 upgrade_foot();\r
192                 exit;\r
193         }       \r
194         \r
195         /**\r
196           * Tries to execute a query, gives a message when failed\r
197           *\r
198           * @param friendly name\r
199           * @param query                \r
200           */\r
201         function upgrade_query($friendly, $query) {\r
202                 global $upgrade_failures;\r
203                 \r
204                 echo "<li>$friendly ... ";\r
205                 $res = mysql_query($query);\r
206                 if (!$res) {\r
207                         echo "<span style='color:red'>FAILED</span>\n";\r
208                         echo "<blockquote>Error was: " . mysql_error() . " </blockquote>";\r
209                         $upgrade_failures++;\r
210                 } else {\r
211                         echo "<span style='color:green'>SUCCESS!</span><br />\n";\r
212                 }\r
213                 echo "</li>";\r
214                 return $res;\r
215         }\r
216         \r
217         /**\r
218          * @param $table \r
219          *              table to check (without prefix)\r
220          * @param $aColumns\r
221          *              array of column names included\r
222          */\r
223         function upgrade_checkIfIndexExists($table, $aColumns) {\r
224                 // get info for indices from database\r
225                 \r
226                 $aIndices = array();\r
227                 $query = 'show index from ' . sql_table($table);\r
228                 $res = mysql_query($query);\r
229                 while ($o = mysql_fetch_object($res)) {\r
230                         if (!$aIndices[$o->Key_name]) {\r
231                                 $aIndices[$o->Key_name] = array();\r
232                         }\r
233                         array_push($aIndices[$o->Key_name], $o->Column_name);\r
234                 }\r
235 \r
236                 // compare each index with parameter\r
237                 foreach ($aIndices as $keyName => $aIndexColumns) {\r
238                         $aDiff = array_diff($aIndexColumns, $aColumns);\r
239                         if (count($aDiff) == 0) return 1;\r
240                 }\r
241                 \r
242                 return 0;\r
243 \r
244         }\r
245 \r
246 \r
247 \r
248 ?>