Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12591
Modified Files:
serendipity.css.php serendipity_admin.php
serendipity_admin_installer.inc.php serendipity_config.inc.php
serendipity_functions.inc.php
Added Files:
serendipity_admin_upgrader.inc.php
Removed Files:
db.sql db_update-0.2-0.3.sql db_update-0.3-0.4.sql
db_update-0.5-0.5.1.sql
Log Message:
Okay, here we go. One upgrade script comming up.
Basically it checks if the version last used to save the config is lower than the installed version
If that is the case, it opens a page (like the installer) and attempts to calculate which SQL files and functions needs to be run.
It is then up to the user to accept if he or she wants to perform these actions..
WARNING: Backup your database before you run the upgrader!
Developers will likely never have to use this script (test it anyways?), so it won't make the versioncheck if $srendipity['production'] is false
--- NEW FILE: serendipity_admin_upgrader.inc.php ---
<?php
require_once('serendipity_functions_installer.inc.php');
$abortLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=ignore';
$upgradeLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=upgrade';
/* Functions which needs to be run if installed version is equal or lower */
$tasks = array('0.5.1' => 'serendipity_syncThumbs');
/* Fetch SQL files which needs to be run */
$dir = opendir($serendipity['serendipityPath'] .'sql/');
while ( ($file = readdir($dir)) !== false ) {
if ( preg_match('@db_update_(.*)_(.*)_'. $serendipity['dbType'] .'.sql@', $file, $res) ) {
if ( version_compare($res[1], $serendipity['versionInstalled']) >= 0) {
$sqlfiles[] = $file;
}
}
}
if ( $serendipity['GET']['action'] == 'ignore' ) {
/* Todo: Don't know what to put here? */
} elseif ( $serendipity['GET']['action'] == 'upgrade' ) {
/* Install SQL files */
foreach ($sqlfiles as $sqlfile) {
$sql = file_get_contents($serendipity['serendipityPath'] .'sql/'. $sqlfile);
$sql = str_replace('{PREFIX}', $serendipity['dbPrefix'], $sql);
preg_match_all("@(.*);@iUs", $sql, $res);
foreach ( $res[0] as $sql) {
$r = serendipity_db_query($sql);
if ( is_string($r) ) {
$errors[] = $r;
}
}
}
/* Call functions */
foreach ( $tasks as $version => $function ) {
if ( version_compare($serendipity['version'], $version, '<=') ) {
if ( is_callable($function) ) {
call_user_func($function);
} else {
$errors[] = 'Unable to call '. $function;
}
}
}
if ( is_array($errors) ) {
echo DIAGNOSTIC_ERROR . '<br /><br />';
echo '<span style="color: #FF0000">- ' . implode('<br />', $errors) . '</span><br /><br />';
}
}
if ( $serendipity['GET']['action'] == 'ignore' || $serendipity['GET']['action'] == 'upgrade' ) {
$r = serendipity_updateLocalConfig($serendipity['dbName'], $serendipity['dbPrefix'], $serendipity['dbHost'], $serendipity['dbUser'], $serendipity['dbPass'], $serendipity['dbType']);
if ( $serendipity['GET']['action'] == 'ignore' ) {
echo SERENDIPITY_UPGRADER_YOU_HAVE_IGNORED;
} elseif ( $serendipity['GET']['action'] == 'upgrade' ) {
echo sprintf(SERENDIPITY_UPGRADER_NOW_UPGRADED, $serendipity['version']);
}
echo sprintf(SERENDIPITY_UPGARDER_RETURN_HERE, '<a href="'. $serendipity['serendipityHTTPPath'] .'">', '</a>');
} else {
?>
<?php echo SERENDIPITY_UPGRADER_WELCOME ?>
<br /><?php echo SERENDIPITY_UPGRADER_PURPOSE ?>
<br /><?php echo sprintf(SERENDIPITY_UPGRADER_WHY, $serendipity['version']) ?>
<?php if ( sizeof($sqlfiles) > 0 ) { ?>
<br />
<h3><?php echo sprintf(SERENDIPITY_UPGRADER_DATABASE_UPDATES, $serendipity['dbType']) ?>:</h3>
<?php echo SERENDIPITY_UPGRADER_FOUND_SQL_FILES ?>:
<br />
<?php
foreach ( $sqlfiles as $sqlfile ) {
echo '<strong>- '. $sqlfile .'</strong><br />';
}
?>
<?php } ?>
<h3><?php echo SERENDIPITY_UPGRADER_VERSION_SPECIFIC ?>:</h3>
<?php
$taskCount = 0;
if ( version_compare($serendipity['version'], '0.5.1', '<=') ) {
echo '<strong>0.5.1 - Image sync</strong>';
echo '<br />Version 0.5.1 introduces image sync with the database.';
echo '<br />With your permission I would like to perform the image sync.';
$taskCount++;
}
/*
Add more versions here using:
if ( [version_compare] ) {
[Desc]
$taskCount++;
}
*/
if ( $taskCount == 0 ) {
echo SERENDIPITY_UPGRADER_NO_VERSION_SPECIFIC;
}
?>
<br /><br />
<hr noshade>
<?php if ( $taskCount > 0 || sizeof($sqlfiles) > 0 ) { ?>
<strong><?php echo SERENDIPITY_UPGRADER_PROCEED_QUESTION ?></strong>
<br /><input type="button" value="<?php echo SERENDIPITY_UPGRADER_PROCEED_ABORT ?>" onClick="location.href='<?php echo $abortLoc ?>'"> <input type="button" value="<?php echo SERENDIPITY_UPGRADER_PROCEED_DOIT ?>" onClick="location.href='<?php echo $upgradeLoc ?>'">
<?php } else { ?>
<strong><?php echo SERENDIPITY_UPGRADER_NO_UPGRADES ?></strong>
<br /><input type="button" value="<?php echo SERENDIPITY_UPGRADER_CONSIDER_CONE ?>" onClick="location.href='<?php echo $abortLoc ?>'">
<?php } ?>
<?php } ?>
Index: serendipity.css.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity.css.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- serendipity.css.php 11 Feb 2004 12:23:12 -0000 1.22
+++ serendipity.css.php 2 Mar 2004 17:35:24 -0000 1.23
@@ -1,6 +1,13 @@
<?php # $Id$
include_once('compat.php');
+
+/* This is a small hack to allow CSS display during installations and upgrades */
+define('IN_installer', true);
+define('IN_upgrader', true);
+
+include_once('serendipity_config.inc.php');
+
header('Content-type: text/css');
function serendipity_printStylesheet($file) {
global $serendipity;
Index: serendipity_admin.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- serendipity_admin.php 17 Feb 2004 16:39:55 -0000 1.28
+++ serendipity_admin.php 2 Mar 2004 17:35:24 -0000 1.29
@@ -2,6 +2,7 @@
session_start();
define('IN_installer', true);
+define('IN_upgrader', true);
include('serendipity_config.inc.php');
if ($serendipity['GET']['adminModule'] == 'logout'){
@@ -40,11 +41,18 @@
<table id="mainpane">
<tr valign="top">
<?php
-if (!isset($serendipity['serendipityPath']) || IS_installed === false ) {
+if (!isset($serendipity['serendipityPath']) || IS_installed === false || IS_up2date === false ) {
+ if ( IS_installed === false ) {
+ $file = 'serendipity_admin_installer.inc.php';
+ } elseif ( IS_up2date === 1 ) {
+ $file = 'serendipity_admin_upgrader.inc.php';
+ }
+
+
?>
<td class="serendipity_admin">
<div class="serendipity_date"><?php echo SERENDIPITY_INSTALLATION; ?></div>
- <p><?php require_once('serendipity_admin_installer.inc.php'); ?>
+ <p><?php require_once($file); ?>
<?php
} elseif ( !serendipity_userLoggedIn() ) {
serendipity_printLogin();
Index: serendipity_admin_installer.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin_installer.inc.php,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- serendipity_admin_installer.inc.php 29 Feb 2004 19:53:25 -0000 1.56
+++ serendipity_admin_installer.inc.php 2 Mar 2004 17:35:24 -0000 1.57
@@ -368,7 +368,7 @@
echo CREATE_DATABASE;
// Create tables
- $queries = serendipity_parse_sql_tables('./db.sql');
+ $queries = serendipity_parse_sql_tables('./sql/db.sql');
$queries = str_replace('{PREFIX}', $_POST['dbPrefix'], $queries);
foreach ($queries as $query) {
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- serendipity_config.inc.php 26 Feb 2004 11:37:42 -0000 1.54
+++ serendipity_config.inc.php 2 Mar 2004 17:35:24 -0000 1.55
@@ -28,6 +28,7 @@
// Is the possibility to comment and entry enabled by default?
$serendipity['allowCommentsDefault'] = true;
+
/*
* Load main language file
*/
@@ -39,6 +40,7 @@
if ( !defined('IN_installer') && IS_installed === false ) {
die(sprintf(SERENDIPITY_NOT_INSTALLED, 'serendipity_admin.php'));
}
+
if ( defined('IN_installer') && IS_installed === false) {
return 1;
}
@@ -48,6 +50,21 @@
* Load Functions
*/
include_once("{$serendipity['serendipityPath']}serendipity_config_local.inc.php");
+
+
+/*
+ * Check if the installed version is highter than the version of the config
+ */
+define('IS_up2date', version_compare($serendipity['version'], $serendipity['versionInstalled'], '<='));
+
+if ( IS_up2date === false && $serendipity['production'] && !defined('IN_upgrader') ) {
+ die(sprintf(SERENDIPITY_NEEDS_UPGRADE, $serendipity['versionInstalled'], $serendipity['version'], 'serendipity_admin.php'));
+}
+
+
+/*
+ * Include main functions
+ */
include_once("{$serendipity['serendipityPath']}serendipity_functions.inc.php");
if (serendipity_FUNCTIONS_LOADED!== true) {
@@ -61,6 +78,7 @@
die(DATABASE_ERROR);
}
+
/*
* Load Configuration options from the database
*/
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.221
retrieving revision 1.222
diff -u -d -r1.221 -r1.222
--- serendipity_functions.inc.php 27 Feb 2004 20:15:02 -0000 1.221
+++ serendipity_functions.inc.php 2 Mar 2004 17:35:24 -0000 1.222
@@ -9,6 +9,7 @@
include_once("${serendipity['serendipityPath']}bundled-libs/XML/RPC.php");
include_once("${serendipity['serendipityPath']}serendipity_plugin_api.php");
include_once("${serendipity['serendipityPath']}serendipity_functions_images.inc.php");
+include_once("${serendipity['serendipityPath']}serendipity_functions_installer.inc.php");
function serendipity_logout() {
$_SESSION['serendipityAuthedUser'] = false;
--- db.sql DELETED ---
--- db_update-0.2-0.3.sql DELETED ---
--- db_update-0.3-0.4.sql DELETED ---
--- db_update-0.5-0.5.1.sql DELETED ---
|