limit( 1 )
->queryRow();
} catch( Exception $e ) {
$database_exists = false;
}
if( !$database_exists ) {
// database schema installation
echo "important tables are missing! assuming no database.\n";
echo "importing the schema for the first time\n";
- execute_queries_from_file( "$documentation_path/schema.sql" );
-
- // if we have not imported any database version, just set the latest one
- $version_exists = get_option( 'database_version', 0 );
- if( !$version_exists ) {
- set_option( 'database_version', DATABASE_VERSION );
- }
+ execute_queries_from_file( "$documentation_path/database-schema.sql" );
}
// get the current database version
$current_database_version = get_option( 'database_version', 0 );
// notify about the current status
printf( "current database version: %d\n", $current_database_version );
printf( "last database version: %d\n", DATABASE_VERSION );
// update to next database versions once at time
while( $current_database_version < DATABASE_VERSION ) {
$current_database_version++;
// note that the patch name can have a name such as 0001-foo.sql
$patch_name = sprintf(
'patch-%04d-*.sql',
$current_database_version
);
// path to the expected patch
$patch_path = "$patch_directory/$patch_name";
// check if there is a database patch to be applied
echo "looking for patch $patch_path\n";
$found = false;
foreach( glob( $patch_path ) as $filename ) {
execute_queries_from_file( $filename );
$found = true;
}
// actually the unexistence of a patch is good
if( !$found ) {
echo "\t skipped unexisting patch\n";
}
// update the database version
echo "\t increment database version to $current_database_version\n";
set_option( 'database_version', $current_database_version );
}
echo "database upgrade end. good for you!\n";
/**
* Execute some queries from a file
*
* @param string $file
*/
function execute_queries_from_file( $file ) {
echo "\t executing queries from $file\n";
// get the patch content
- $queries = file_get_contents( $file );
+ $queries = @file_get_contents( $file );
+ if( !$queries ) {
+ throw new Exception( "missing file $file" );
+ }
// replace the database prefix with the current one
- $database_prefix = DB::instance()->getPrefix();
+ //$database_prefix = DB::instance()->getPrefix(); // this cannot work in this phase
+ $database_prefix = $GLOBALS['prefix'];
$queries = str_replace( '{$prefix}', $database_prefix, $queries );
// execute the patch queries (it will die in case of error)
try {
multiquery( $queries );
} catch( Exception $e ) {
echo "\n";
printf( "ERROR:\n%s\n\n", $e->getMessage() );
printf( "DEBUG QUERIES:\n%s\n", $queries );
exit( 1 );
}
}
diff --git a/cli/update-mailbox-quotas.php b/scripts/update-mailbox-quotas.php
similarity index 100%
rename from cli/update-mailbox-quotas.php
rename to scripts/update-mailbox-quotas.php
diff --git a/www/login.php b/www/login.php
index d17ba6a..978f3bc 100644
--- a/www/login.php
+++ b/www/login.php
@@ -1,77 +1,77 @@
.
/*
* This is the login page
*/
// load framework
require '../load.php';
-// spawn header
-Header::spawn();
-
// go to the wanted page (or homepage)
if( isset( $_POST['user_uid'] ) && login() ) {
http_redirect( after_login_url(), 303 ); // Redirection "See Other"
}
+
+// spawn header
+Header::spawn();
?>
= __( "Authentication failed!" ) ?>
getURL();
}