OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / upgrades / upgrade.functions.php
index 6ea18c3..45b7e14 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2009 The Nucleus Group
+ * Copyright (C) 2002-2012 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
@@ -12,8 +12,8 @@
  */
 /**
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: upgrade.functions.php 1592 2011-10-29 22:24:24Z gregorlove $
+ * @copyright Copyright (C) 2002-2012 The Nucleus Group
+ * @version $Id: upgrade.functions.php 1889 2012-06-17 08:46:45Z sakamocchi $
  */
 
        /**
@@ -21,7 +21,7 @@
         */
 
        /*************************************************************
-        *     NOTE: With upgrade to 3.6, need to set this to use sql_* API
+        * NOTE: With upgrade to 4.0, need to set this to use DB::* API
         **************************************************************/
 
        include('../../config.php');
                                $query = 'SELECT * FROM ' . sql_table('config') . ' WHERE name=\'DatabaseVersion\' and value >= 360 LIMIT 1';
                                $minrows = 1;
                        break;
+
+                       case '400':
+                               $query = 'SELECT * FROM ' . sql_table('config') . ' WHERE name=\'DatabaseVersion\' and value >= 400 LIMIT 1';
+                               $minrows = 1;
+                       break;
                }
 
+<<<<<<< HEAD
+               $result = DB::getResult($query);
+               $installed = ( $result !== FALSE ) && ($result->rowCount() >= $minrows);
+
+=======
                $result = mysql_query($query);
                $installed = ( $result != 0 ) && (mysql_num_rows($result) >= $minrows);
-
+               
+>>>>>>> skinnable-master
                return $installed;
        }
 
                return getNucleusVersion();
        }
 
-
        /**
         * Show the login form
         * @param string $action
        function upgrade_showLogin($action)
        {
                upgrade_head();
-?>
-       <h1> Log In </h1>
-       <p> Please enter your login name and password. </p>
-
-       <form method="POST" action="<?php echo $action; ?>">
-       <ul>
-               <li> <label for="i_login">Name:</label> <input type="text" name="login" id="i_login" size="20" /> </li>
-               <li> <label for="i_password">Password:</label> <input type="password" name="password" id="i_password" size="20" /> </li>
-       </ul>
-       <p> <input type="submit" value="Log In" /> </p>
-       <input name="action" value="login" type="hidden" />
-       </form>
-
-<?php
+               
+               echo "<h1> Log In </h1>\n";
+               echo "<p>Please enter your login name and password. </p>\n";
+       
+               echo "<form method=\"POST\" action=\"{$action}\">\n";
+               echo "<ul>\n";
+               echo "<li><label for=\"i_login\">Name:</label> <input type=\"text\" name=\"login\" id=\"i_login\" size=\"20\" /></li>\n";
+               echo "<li><label for=\"i_password\">Password:</label> <input type=\"password\" name=\"password\" id=\"i_password\" size=\"20\" /></li>\n";
+               echo "</ul>\n";
+               echo "<p><input type=\"submit\" value=\"Log In\" /></p>\n";
+               echo "<input name=\"action\" value=\"login\" type=\"hidden\" />\n";
+               echo "</form>\n";
+               
                upgrade_foot();
                exit;
-       } // end function upgrade_showLogin()
-
+       }
 
        /**
         * Display the HTML header
         */
        function upgrade_head()
        {
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-       <head>
-               <title> Nucleus Upgrade </title>
-<?php
-       // begin if: manual.css exists - <link> it
-       if ( file_exists('../styles/manual.css') )
-       {
-?>
-               <link rel="stylesheet" href="../styles/manual.css" type="text/css" />
-<?php
+               echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
+               echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
+               echo "<head>\n";
+               echo "<title> Nucleus Upgrade </title>\n";
+               
+               if ( file_exists('../documentation/styles/manual.css') )
+               {
+                       echo "<link rel=\"stylesheet\" href=\"../documentation/styles/manual.css\" type=\"text/css\" />\n";
+               }
+               else
+               {
+                       echo "<style type=\"text/css\">\n";
+                       echo ".warning { color: red; }\n";
+                       echo ".ok { color: green; }\n";
+                       echo "</style>\n";
+               }
+               
+               echo "</head>\n";
+               echo "<body>\n";
        }
-       // else: include some CSS
-       else
-       {
-?>
-               <style type="text/css">
-                       .warning { color: red; }
-                       .ok { color: green; }
-               </style>
-<?php
-       } // end if
-?>
-       </head>
-       <body>
-
-<?php
-       } // end function upgrade_head()
 
 
        /**
                echo "<li> $friendly &mdash; ";
 
                # execute the query
-               $result = @mysql_query($query);
+               $result = @DB::execute($query);
 
                // begin if: error executing query
                if ( $result === FALSE )
                {
                        echo '<span class="warning"> FAILED </span> <br />';
-                       echo 'Error: <code>', mysql_error(), '</code>';
+                       $err = DB::getError();
+                       echo 'Error: <code>', $err[2], '</code>';
                        $upgrade_failures++;
                }
                // else: query was successful
                // begin if: no upgrade failures; update the database version in the config table
                if ( $upgrade_failures == 0 )
                {
-                       $query = 'UPDATE `%s` ' .
-                               'SET `value` = "%s" ' .
-                               'WHERE `name` = "DatabaseVersion"';
-
+                       $query = 'UPDATE %s SET value = "%s" WHERE name = "DatabaseVersion";';
+                       
                        $query = sprintf($query, sql_table('config'), $version);
                        upgrade_query($message, $query);
                }
                // get info for indices from database
                $indices = array();
 
-               $query = 'SHOW INDEX FROM `' . sql_table($table) . '`';
-               $result = @mysql_query($query);
+               $query = 'SHOW INDEX FROM ' . sql_table($table);
+               $result = @DB::getResult($query);
 
                // begin loop: each result object
-               while ( $object = mysql_fetch_object($result) )
+               foreach ( $result as $row )
                {
 
                        // begin if: key has not been added to the indeces array yet
-                       if ( !isset($indices[$object->Key_name]) )
+                       if ( !isset($indices[$row['Key_name']]) )
                        {
-                               $indices[$object->Key_name] = array();
+                               $indices[$row['Key_name']] = array();
                        } // end if
 
-                       array_push($indices[$object->Key_name], $object->Column_name);
+                       array_push($indices[$row['Key_name']], $row['Column_name']);
                }
 
                // compare each index with parameter
         */
        function upgrade_checkIfTableExists($table)
        {
-               $query = 'SHOW TABLES LIKE `' . sql_table($table) . '`';
-               $result = @mysql_query($query);
+               $query = 'SHOW TABLES LIKE ' . sql_table($table);
+               $result = DB::getResult($query);
 
                // begin if: query executed successfully and one row was returned
-               if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) )
+               if ( ($result !== FALSE) && ($result->rowCount() == 1) )
                {
                        return TRUE;
                }
          */
        function upgrade_checkIfCVExists($value)
        {
-               $query = 'SELECT `name` FROM `' . sql_table('config') . '` WHERE `name` = "' . $value . '"';
-               $result = @mysql_query($query);
+               $query = 'SELECT name FROM ' . sql_table('config') . ' WHERE name = "' . $value . '"';
+               $result = DB::getResult($query);
 
                // begin if: query executed successfully and one row was returned
-               if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) )
+               if ( ($result !== FALSE) && ($result->rowCount() == 1) )
                {
                        return TRUE;
                }
          */
        function upgrade_checkIfColumnExists($table, $column)
        {
-               $query = 'DESC `' . sql_table($table) . '` `' . $column . '`';
-               $result = @mysql_query($query);
+               $query = 'DESC ' . sql_table($table) . ' ' . $column;
+               $result = DB::getResult($query);
 
                // begin if: query executed successfully and one row was returned
-               if ( ($result !== FALSE) && (@mysql_num_rows($result) == 1) )
+               if ( ($result !== FALSE) && ($result->rowCount() == 1) )
                {
                        return TRUE;
                }