From eabe90973858de348607bf09fa3811b493cdafd7 Mon Sep 17 00:00:00 2001 From: ozh Date: Sat, 4 May 2013 23:48:06 +0200 Subject: [PATCH] white space --- includes/ezSQL/ez_sql_mysql_yourls.php | 2 +- includes/functions-install.php | 42 ++++++-------------------- includes/functions.php | 25 +++++++++------ 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/includes/ezSQL/ez_sql_mysql_yourls.php b/includes/ezSQL/ez_sql_mysql_yourls.php index 95ff5e9..b230546 100644 --- a/includes/ezSQL/ez_sql_mysql_yourls.php +++ b/includes/ezSQL/ez_sql_mysql_yourls.php @@ -8,7 +8,7 @@ class ezSQL_mysql_YOURLS extends ezSQL_mysql { * @since 1.7 */ function mysql_version() { - return mysql_get_server_info( $this->dbh ) ; + return mysql_get_server_info( $this->dbh ) ; } /** diff --git a/includes/functions-install.php b/includes/functions-install.php index 790d22b..dfa3e02 100644 --- a/includes/functions-install.php +++ b/includes/functions-install.php @@ -1,24 +1,21 @@ mysql_version(); - // Check there was actually a connection to the DB - if( count( $ydb->captured_errors ) ) { - yourls_die ( yourls__( 'Incorrect DB config, or could not connect to DB' ), yourls__( 'Fatal error' ), 503 ); + + // Attempt to get MySQL server version, check result and if error count increased + $num_errors1 = count( $ydb->captured_errors ); + $version = $ydb->mysql_version(); + $num_errors2 = count( $ydb->captured_errors ); + + if( $version == NULL || ( $num_errors2 > $num_errors1 ) ) { + yourls_die( yourls__( 'Incorrect DB config, or could not connect to DB' ), yourls__( 'Fatal error' ), 503 ); } + return ( version_compare( '4.1', $version ) <= 0 ); } @@ -49,27 +46,6 @@ function yourls_is_iis() { return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'IIS' ) !== false ); } -/** - * Check if module exists in Apache config. Input string eg 'mod_rewrite', return true or $default. Stolen from WordPress - * - */ -function yourls_apache_mod_loaded( $mod, $default = false ) { - if ( !yourls_is_apache() ) - return false; - - if ( function_exists( 'apache_get_modules' ) ) { - $mods = apache_get_modules(); - if ( in_array( $mod, $mods ) ) - return true; - } elseif ( function_exists( 'phpinfo' ) ) { - ob_start(); - phpinfo( 8 ); - $phpinfo = ob_get_clean(); - if ( false !== strpos( $phpinfo, $mod ) ) - return true; - } - return $default; -} /** * Create .htaccess or web.config. Returns boolean diff --git a/includes/functions.php b/includes/functions.php index 095b8cf..24881fd 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -429,6 +429,7 @@ function yourls_db_connect() { yourls_set_DB_driver(); } + // Check if connection attempt raised an error. It seems that only PDO does, though. if ( $ydb->last_error ) yourls_die( $ydb->last_error, yourls__( 'Fatal error' ), 503 ); @@ -996,6 +997,9 @@ function yourls_get_all_options() { if( property_exists( $ydb, 'option' ) ) { $ydb->option = yourls_apply_filter( 'get_all_options', $ydb->option ); + } else { + // Zero option found: assume YOURLS is not installed + $ydb->installed = false; } } @@ -1287,18 +1291,21 @@ function yourls_is_upgrading() { /** * Check if YOURLS is installed * + * Checks property $ydb->installed that is created and set to false by yourls_get_all_options() if no + * option was readable. The property doesn't exist otherwise. + * + * See inline comment for updating from 1.3 or prior. + * */ function yourls_is_installed() { - static $is_installed = false; - if ( $is_installed === false ) { - $check_14 = $check_13 = false; - global $ydb; - if( defined('YOURLS_DB_TABLE_NEXTDEC') ) - $check_13 = $ydb->get_var('SELECT `next_id` FROM '.YOURLS_DB_TABLE_NEXTDEC); - $check_14 = yourls_get_option( 'version' ); - $is_installed = $check_13 || $check_14; - } + global $ydb; + $is_installed = ( property_exists( $ydb, 'installed' ) && $ydb->installed == true ); return yourls_apply_filter( 'is_installed', $is_installed ); + + /* Note: this test won't work on YOURLS 1.3 or older (Aug 2009...) + Should someone complain that they cannot upgrade directly from + 1.3 to 1.7: first, laugh at them, then ask them to install 1.6 first. + */ } /** -- 2.45.0