OSDN Git Service

sync with trunk
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / upgrades / upgrade.functions.php
index 8365aa8..ebc9d79 100755 (executable)
@@ -1,30 +1,45 @@
-<?php  
+<?php
 
+       /*
+        * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+        * Copyright (C) 2002-2007 The Nucleus Group
+        *
+        * This program is free software; you can redistribute it and/or
+        * modify it under the terms of the GNU General Public License
+        * as published by the Free Software Foundation; either version 2
+        * of the License, or (at your option) any later version.
+        * (see nucleus/documentation/index.html#license for more info)
+        */
        /**
-         * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
-         * Copyright (C) 2002-2007 The Nucleus Group
-         *
-         * This program is free software; you can redistribute it and/or
-         * modify it under the terms of the GNU General Public License
-         * as published by the Free Software Foundation; either version 2
-         * of the License, or (at your option) any later version.
-         * (see nucleus/documentation/index.html#license for more info)
-         *     
-         * Some functions common to all upgrade scripts
-         *
-         * $Id: upgrade.functions.php,v 1.9 2007-04-14 00:44:27 kmorimatsu Exp $
-         * $NucleusJP: upgrade.functions.php,v 1.8 2007/04/10 03:55:20 kmorimatsu Exp $
-         */
+        * Some functions common to all upgrade scripts
+        *
+        * @license http://nucleuscms.org/license.txt GNU General Public License
+        * @copyright Copyright (C) 2002-2007 The Nucleus Group
+        * @version $Id: upgrade.functions.php,v 1.10 2007-04-26 06:20:19 kimitake Exp $
+        * $NucleusJP: upgrade.functions.php,v 1.9 2007/04/14 00:44:27 kmorimatsu Exp $
+        */
 
        include('../../config.php');
-       
+
        // sql_table function did not exists in nucleus <= 2.0
        if (!function_exists('sql_table'))
        {
                function sql_table($name) {
                        return 'nucleus_' . $name;
                }
-       }       
+       }
+
+       //intGetVar did not exist in very early versions
+       if (!function_exists('intGetVar')) {
+               function intGetVar($name) {
+                       if (defined($_GET)) {
+                               return intval($_GET[$name]);
+                       } else {
+                               global $HTTP_GET_VARS;
+                               return intval($HTTP_GET_VARS[$name]);
+                       }
+               }
+       }
 
        function upgrade_checkinstall($version) {
                $installed = 0;
                                break;
                        case '96':
                                $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
-                               $minrows = -1;                  
+                               $minrows = -1;
                                break;
                        case '10':
                                $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
-                               $minrows = -1;                  
-                               break;                  
+                               $minrows = -1;
+                               break;
                        case '11':
                                $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
-                               $minrows = -1;                  
+                               $minrows = -1;
                                break;
                        case '15':
                                $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
-                               $minrows = -1;                  
-                               break;                  
+                               $minrows = -1;
+                               break;
                        case '20':
                                $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
-                               $minrows = -1;                  
-                               break;                          
+                               $minrows = -1;
+                               break;
                        // dev only (v2.2)
                        case '22':
                                $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
-                               $minrows = -1;                  
+                               $minrows = -1;
                                break;
                        // v2.5 beta
                        case '24':
                                $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
-                               $minrows = -1;                  
-                               break;                          
+                               $minrows = -1;
+                               break;
                        case '25':
                                $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
                                $minrows = 1;
 
                return $installed;
        }
-       
-       
+
+
        /** this function gets the nucleus version, even if the getNucleusVersion
         * function does not exist yet
         * return 96 for all versions < 100
                if (!function_exists('getNucleusVersion')) return 96;
                return getNucleusVersion();
        }
-       
+
        function upgrade_showLogin($type) {
                upgrade_head();
        ?>
                <h1>まずはログインして下さい</h1>
                <p>下記の情報を入力して下さい:</p>
-               
+
                <form method="post" action="<?php echo $type?>">
 
                        <ul>
                                <input name="action" value="login" type="hidden" />
                                <input type="submit" value="ログイン" />
                        </p>
-               
+
                </form>
        <?php           upgrade_foot();
                exit;
        }
-       
+
        function upgrade_head() {
        ?>
                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                        <head>
                                <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
                                <title>Nucleus アップグレード</title>
-                               <style><!--
-                                       @import url('../styles/manual.css');
+<?php if (file_exists("../styles/manual.css")) { ?>
+                               <link rel="stylesheet" href="../styles/manual.css" type="text/css" />
+<?php }else{ ?>
+                               <style type="text/css"><!--
                                        .warning {
                                                color: red;
                                        }
                                                color: green;
                                        }
                                --></style>
+<?php } ?>
                        </head>
-                       <body>          
+                       <body>
        <?php   }
 
        function upgrade_foot() {
        ?>
                        </body>
-                       </html> 
-       <?php   }       
-       
+                       </html>
+       <?php   }
+
        function upgrade_error($msg) {
                upgrade_head();
                ?>
                <h1>エラー!</h1>
 
                <p>メッセージは以下の通り:</p>
-               
+
                <blockquote><div>
                <?php echo $msg?>
                </div></blockquote>
                upgrade_foot();
                exit;
        }
-       
-       
+
+
        function upgrade_start() {
                global $upgrade_failures;
                $upgrade_failures = 0;
-               
+
                upgrade_head();
                ?>
                <h1>アップグレードの実行</h1>
                <ul>
                <?php   }
-       
+
        function upgrade_end($msg = "") {
                global $upgrade_failures;
                if ($upgrade_failures > 0)
                        $msg = "いくつかのデータベース操作に失敗しました。もし以前にこのアップグレードスクリプトを実行していたのであれば、問題ないと思われます。";
-       
+
                ?>
                </ul>
-               
+
                <h1>アップグレード完了!</h1>
 
                <p><?php echo $msg?></p>
-               
+
                <p><a href="index.php">アップグレード最初のページ</a>にもどる</p>
 
                <?php
                upgrade_foot();
                exit;
-       }       
-       
+       }
+
        /**
          * Tries to execute a query, gives a message when failed
          *
          * @param friendly name
-         * @param query                
+         * @param query
          */
        function upgrade_query($friendly, $query) {
                global $upgrade_failures;
-               
+
                echo "<li>$friendly ... ";
-               $res = sql_query($query);
+               $res = mysql_query($query);
                if (!$res) {
                        echo "<span style='color:red'>失敗</span>\n";
                        echo "<blockquote>失敗の理由: " . mysql_error() . " </blockquote>";
                echo "</li>";
                return $res;
        }
-       
+
+       /**
+         * Tries to update database version, gives a message when failed
+         *
+         * @param $version
+         *     Schema version the database has been upgraded to
+         */
+       function update_version($version) {
+               global $upgrade_failures;
+               $message='Updating DatabaseVersion in config table to '.$version;
+               if(0==$upgrade_failures){
+                       $query = 'UPDATE ' . sql_table('config') . ' set value=\''.$version.'\' where name=\'DatabaseVersion\'';
+                       upgrade_query($message, $query);
+               }else
+                       echo '<li>'.$message.' ... <span class="warning">NOT EXECUTED</span>\n<blockquote>Errors occurred during upgrade process.</blockquote>';
+       }
+
        /**
-        * @param $table 
+        * @param $table
         *              table to check (without prefix)
         * @param $aColumns
         *              array of column names included
         */
        function upgrade_checkIfIndexExists($table, $aColumns) {
                // get info for indices from database
-               
+
                $aIndices = array();
                $query = 'show index from ' . sql_table($table);
                $res = mysql_query($query);
                        $aDiff = array_diff($aIndexColumns, $aColumns);
                        if (count($aDiff) == 0) return 1;
                }
-               
+
                return 0;
 
        }
 
+       /**
+         * Checks to see if a given table exists
+         *
+         * @param $table
+         *     Name of table to check for existance of
+         *     Uses sql_table internally
+         * @return true if table exists, false otherwise.
+         */
+       function upgrade_checkIfTableExists($table){
+               $query = 'SHOW TABLES LIKE \''.sql_table($table).'\'';
+               $res = mysql_query($query);
+               return ($res != 0) && (mysql_num_rows($res) == 1);
+       }
 
+       /**
+         * Checks to see if a given configuration value exists
+         *
+         * @param $value
+         *     Config value to check for existance of.
+         *     Paramater must be MySQL escaped
+         * @return true if configuration value exists, false otherwise.
+         */
+       function upgrade_checkIfCVExists($value){
+               $query = 'SELECT name from '.sql_table('config').' WHERE name = \''.$value.'\'';
+               $res = mysql_query($query);
+               return ($res != 0) && (mysql_num_rows($res) == 1);
+       }
 
+       /**
+         * Checks to see if a given column exists
+         *
+         * @param $table
+         *     Name of table to check for column in
+         *     Uses sql_table internally
+         * @param $col
+         *     Name of column to check for existance of
+         * @return true if column exists, false otherwise.
+         */
+       function upgrade_checkIfColumnExists($table, $col){
+               $query = 'DESC `'.sql_table($table).'` `'.$col.'`';
+               $res = mysql_query($query);
+               return ($res != 0) && (mysql_num_rows($res) == 1);
+       }
 ?>