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.2 2005-03-15 08:11:16 kimitake Exp $
\r
18 include('../../config.php');
\r
20 // sql_table function did not exists in nucleus <= 2.0
\r
21 if (!function_exists('sql_table'))
\r
23 function sql_table($name) {
\r
24 return 'nucleus_' . $name;
\r
28 function upgrade_checkinstall($version) {
\r
33 $query = 'SELECT bconvertbreaks FROM '.sql_table('blog').' LIMIT 1';
\r
37 $query = 'SELECT cip FROM '.sql_table('comment').' LIMIT 1';
\r
41 $query = 'SELECT mcookiekey FROM '.sql_table('member').' LIMIT 1';
\r
45 $query = 'SELECT bnotifytype FROM '.sql_table('blog').' LIMIT 1';
\r
49 $query = 'SELECT * FROM '.sql_table('plugin_option').' LIMIT 1';
\r
53 $query = 'SELECT sdincpref FROM '.sql_table('skin_desc').' LIMIT 1';
\r
58 $query = 'SELECT oid FROM '.sql_table('plugin_option_desc').' LIMIT 1';
\r
63 $query = 'SELECT bincludesearch FROM ' . sql_table('blog') . ' LIMIT 1';
\r
67 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 250 LIMIT 1';
\r
71 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 300 LIMIT 1';
\r
75 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 310 LIMIT 1';
\r
79 $query = 'SELECT * FROM '.sql_table('config').' WHERE name=\'DatabaseVersion\' and value >= 320 LIMIT 1';
\r
84 $res = mysql_query($query);
\r
85 $installed = ($res != 0) && (mysql_num_rows($res) >= $minrows);
\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
95 function upgrade_getNucleusVersion() {
\r
96 if (!function_exists('getNucleusVersion')) return 96;
\r
97 return getNucleusVersion();
\r
100 function upgrade_showLogin($type) {
\r
103 <h1>Please Log in First</h1>
\r
104 <p>Enter your data below:</p>
\r
106 <form method="post" action="<?php echo $type?>">
\r
109 <li>Name: <input name="login" /></li>
\r
110 <li>Password <input name="password" type="password" /></li>
\r
114 <input name="action" value="login" type="hidden" />
\r
115 <input type="submit" value="Log in" />
\r
119 <?php upgrade_foot();
\r
123 function upgrade_head() {
\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
128 <title>Nucleus Upgrade</title>
\r
130 @import url('../styles/manual.css');
\r
142 function upgrade_foot() {
\r
148 function upgrade_error($msg) {
\r
153 <p>Message was:</p>
\r
157 </div></blockquote>
\r
159 <p><a href="index.php" onclick="history.back();">Go Back</a></p>
\r
166 function upgrade_start() {
\r
167 global $upgrade_failures;
\r
168 $upgrade_failures = 0;
\r
172 <h1>Executing Upgrades</h1>
\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
184 <h1>Upgrade Completed!</h1>
\r
186 <p><?php echo $msg?></p>
\r
188 <p>Back to the <a href="index.php">Upgrades Overview</a></p>
\r
196 * Tries to execute a query, gives a message when failed
\r
198 * @param friendly name
\r
201 function upgrade_query($friendly, $query) {
\r
202 global $upgrade_failures;
\r
204 echo "<li>$friendly ... ";
\r
205 $res = mysql_query($query);
\r
207 echo "<span style='color:red'>FAILED</span>\n";
\r
208 echo "<blockquote>Error was: " . mysql_error() . " </blockquote>";
\r
209 $upgrade_failures++;
\r
211 echo "<span style='color:green'>SUCCESS!</span><br />\n";
\r
219 * table to check (without prefix)
\r
221 * array of column names included
\r
223 function upgrade_checkIfIndexExists($table, $aColumns) {
\r
224 // get info for indices from database
\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
233 array_push($aIndices[$o->Key_name], $o->Column_name);
\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