4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2005 The Nucleus Group
\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
13 * Some functions common to all upgrade scripts
\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
19 include('../../config.php');
\r
21 // sql_table function did not exists in nucleus <= 2.0
\r
22 if (!function_exists('sql_table'))
\r
24 function sql_table($name) {
\r
25 return 'nucleus_' . $name;
\r
29 function upgrade_checkinstall($version) {
\r
34 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
\r
38 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
\r
42 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
\r
46 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
\r
50 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
\r
54 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
\r
59 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
\r
64 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
\r
68 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
\r
72 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
\r
76 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
\r
80 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
\r
85 $res = mysql_query($query);
\r
86 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
\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
96 function upgrade_getNucleusVersion() {
\r
97 if (!function_exists('getNucleusVersion')) return 96;
\r
98 return getNucleusVersion();
\r
101 function upgrade_showLogin($type) {
\r
104 <h1>まずはログインして下さい</h1>
\r
105 <p>下記の情報を入力して下さい:</p>
\r
107 <form method="post" action="<?php echo $type?>">
\r
110 <li>名前: <input name="login" /></li>
\r
111 <li>パスワード <input name="password" type="password" /></li>
\r
115 <input name="action" value="login" type="hidden" />
\r
116 <input type="submit" value="ログイン" />
\r
120 <?php upgrade_foot();
\r
124 function upgrade_head() {
\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
129 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
\r
130 <title>Nucleus アップグレード</title>
\r
132 @import url('../styles/manual.css');
\r
144 function upgrade_foot() {
\r
150 function upgrade_error($msg) {
\r
155 <p>メッセージは以下の通り:</p>
\r
159 </div></blockquote>
\r
161 <p><a href="index.php" onclick="history.back();">戻る</a></p>
\r
168 function upgrade_start() {
\r
169 global $upgrade_failures;
\r
170 $upgrade_failures = 0;
\r
174 <h1>アップグレードの実行</h1>
\r
178 function upgrade_end($msg = "") {
\r
179 global $upgrade_failures;
\r
180 if ($upgrade_failures > 0)
\r
181 $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
\r
186 <h1>アップグレード完了!</h1>
\r
188 <p><?php echo $msg?></p>
\r
190 <p><a href="index.php">アップグレード最初のページ</a>にもどる</p>
\r
198 * Tries to execute a query, gives a message when failed
\r
200 * @param friendly name
\r
203 function upgrade_query($friendly, $query) {
\r
204 global $upgrade_failures;
\r
206 echo "<li>$friendly ... ";
\r
207 $res = mysql_query($query);
\r
209 echo "<span style='color:red'>失敗</span>\n";
\r
210 echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
\r
211 $upgrade_failures++;
\r
213 echo "<span style='color:green'>成功!</span><br />\n";
\r
221 * table to check (without prefix)
\r
223 * array of column names included
\r
225 function upgrade_checkIfIndexExists($table, $aColumns) {
\r
226 // get info for indices from database
\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
235 array_push($aIndices[$o->Key_name], $o->Column_name);
\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