4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2012 The Nucleus Group
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)
14 * Some functions common to all upgrade scripts
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
19 * $NucleusJP: upgrade.functions.php,v 1.10 2007/04/26 06:20:19 kimitake Exp $
22 /*************************************************************
23 * NOTE: With upgrade to 3.6, need to set this to use sql_* API *
24 **************************************************************/
26 include('../../config.php');
28 // sql_table function did not exists in nucleus <= 2.0
29 if (!function_exists('sql_table'))
31 function sql_table($name) {
32 return 'nucleus_' . $name;
36 //intGetVar did not exist in very early versions
37 if (!function_exists('intGetVar')) {
38 function intGetVar($name) {
40 return intval($_GET[$name]);
42 global $HTTP_GET_VARS;
43 return intval($HTTP_GET_VARS[$name]);
48 function upgrade_checkinstall($version) {
53 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
57 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
61 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
65 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
69 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
73 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
78 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
83 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
87 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
91 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
95 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
99 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
103 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 330 LIMIT 1';
107 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 331 LIMIT 1';
111 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 340 LIMIT 1';
115 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 350 LIMIT 1';
119 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 360 LIMIT 1';
124 $res = mysql_query($query);
125 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
131 /** this function gets the nucleus version, even if the getNucleusVersion
132 * function does not exist yet
133 * return 96 for all versions < 100
135 function upgrade_getNucleusVersion() {
136 if (!function_exists('getNucleusVersion')) return 96;
137 return getNucleusVersion();
140 function upgrade_showLogin($type) {
143 <h1>まずはログインして下さい</h1>
144 <p>下記の情報を入力して下さい:</p>
146 <form method="post" action="<?php echo $type?>">
149 <li>名前: <input name="login" /></li>
150 <li>パスワード <input name="password" type="password" /></li>
154 <input name="action" value="login" type="hidden" />
155 <input type="submit" value="ログイン" />
159 <?php upgrade_foot();
163 function upgrade_head() {
165 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
166 <html xmlns="http://www.w3.org/1999/xhtml">
168 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
169 <title>Nucleus アップグレード</title>
170 <?php if (file_exists("../styles/manual.css")) { ?>
171 <link rel="stylesheet" href="../styles/manual.css" type="text/css" />
173 <style type="text/css"><!--
186 function upgrade_foot() {
192 function upgrade_error($msg) {
203 <p><a href="index.php" onclick="history.back();">戻る</a></p>
210 function upgrade_start() {
211 global $upgrade_failures;
212 $upgrade_failures = 0;
220 function upgrade_end($msg = "") {
221 global $upgrade_failures;
222 $from = intGetVar('from');
223 if ($upgrade_failures > 0)
224 $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
231 <p><?php echo $msg?></p>
233 <p><a href="index.php?from=<?php echo $from; ?>">アップグレード最初のページ</a>にもどる</p>
241 * Tries to execute a query, gives a message when failed
243 * @param friendly name
246 function upgrade_query($friendly, $query) {
247 global $upgrade_failures;
249 echo "<li>$friendly ... ";
250 $res = mysql_query($query);
252 echo "<span style='color:red'>失敗</span>\n";
253 echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
256 echo "<span style='color:green'>成功!</span><br />\n";
263 * Tries to update database version, gives a message when failed
266 * Schema version the database has been upgraded to
268 function update_version($version) {
269 global $upgrade_failures;
270 $message='Updating DatabaseVersion in config table to '.$version;
271 if(0==$upgrade_failures){
272 $query = 'UPDATE ' . sql_table('config') . ' set value=\''.$version.'\' where name=\'DatabaseVersion\'';
273 upgrade_query($message, $query);
275 echo '<li>'.$message.' ... <span class="warning">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>';
280 * table to check (without prefix)
282 * array of column names included
284 function upgrade_checkIfIndexExists($table, $aColumns) {
285 // get info for indices from database
288 $query = 'show index from ' . sql_table($table);
289 $res = mysql_query($query);
290 while ($o = mysql_fetch_object($res)) {
291 if (!$aIndices[$o->Key_name]) {
292 $aIndices[$o->Key_name] = array();
294 array_push($aIndices[$o->Key_name], $o->Column_name);
297 // compare each index with parameter
298 foreach ($aIndices as $keyName => $aIndexColumns) {
299 $aDiff = array_diff($aIndexColumns, $aColumns);
300 if (count($aDiff) == 0) return 1;
308 * Checks to see if a given table exists
311 * Name of table to check for existance of
312 * Uses sql_table internally
313 * @return true if table exists, false otherwise.
315 function upgrade_checkIfTableExists($table){
316 $query = 'SHOW TABLES LIKE \''.sql_table($table).'\'';
317 $res = mysql_query($query);
318 return ($res != 0) && (mysql_num_rows($res) == 1);
322 * Checks to see if a given configuration value exists
325 * Config value to check for existance of.
326 * Paramater must be MySQL escaped
327 * @return true if configuration value exists, false otherwise.
329 function upgrade_checkIfCVExists($value){
330 $query = 'SELECT name from '.sql_table('config').' WHERE name = \''.$value.'\'';
331 $res = mysql_query($query);
332 return ($res != 0) && (mysql_num_rows($res) == 1);
336 * Checks to see if a given column exists
339 * Name of table to check for column in
340 * Uses sql_table internally
342 * Name of column to check for existance of
343 * @return true if column exists, false otherwise.
345 function upgrade_checkIfColumnExists($table, $col){
346 $query = 'DESC `'.sql_table($table).'` `'.$col.'`';
347 $res = mysql_query($query);
348 return ($res != 0) && (mysql_num_rows($res) == 1);