From e6748601549a70b8f160ea302590e0611fd618e4 Mon Sep 17 00:00:00 2001 From: ozh Date: Thu, 5 Sep 2013 16:36:47 +0200 Subject: [PATCH] Safer DB version number, and debug feedback if failure on install Related: - https://github.com/YOURLS/YOURLS/issues/1479#issuecomment-23428747 - https://core.trac.wordpress.org/ticket/25228 --- admin/install.php | 10 +++++++--- includes/functions-install.php | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/admin/install.php b/admin/install.php index e0a6580..0567e3a 100644 --- a/admin/install.php +++ b/admin/install.php @@ -4,16 +4,20 @@ require_once( dirname(dirname(__FILE__)).'/includes/load-yourls.php' ); require_once( YOURLS_INC.'/functions-install.php' ); -$error = array(); +$error = array(); $warning = array(); $success = array(); // Check pre-requisites -if ( !yourls_check_database_version() ) +if ( !yourls_check_database_version() ) { $error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'MySQL' ); + $ydb->debug_log[] = 'MySQL version: ' . yourls_get_database_version(); +} -if ( !yourls_check_php_version() ) +if ( !yourls_check_php_version() ) { $error[] = yourls_s( '%s version is too old. Ask your server admin for an upgrade.', 'PHP' ); + $ydb->debug_log[] = 'PHP version: ' . phpversion(); +} // Is YOURLS already installed ? if ( yourls_is_installed() ) { diff --git a/includes/functions-install.php b/includes/functions-install.php index 0ebb3b2..0f43fd5 100644 --- a/includes/functions-install.php +++ b/includes/functions-install.php @@ -9,7 +9,7 @@ function yourls_check_database_version() { // Attempt to get MySQL server version, check result and if error count increased $num_errors1 = count( $ydb->captured_errors ); - $version = preg_replace( '/[^0-9.]/', '', $ydb->mysql_version() ); + $version = yourls_get_database_version(); $num_errors2 = count( $ydb->captured_errors ); if( $version == NULL || ( $num_errors2 > $num_errors1 ) ) { @@ -19,6 +19,26 @@ function yourls_check_database_version() { return ( version_compare( '4.1', $version ) <= 0 ); } +/** + * Get DB version + * + * The regex removes everything that's not a number at the start of the string, or remove anything that's not a number and what + * follows after that. + * 'omgmysql-5.5-ubuntu-4.20' => '5.5' + * 'mysql5.5-ubuntu-4.20' => '5.5' + * '5.5-ubuntu-4.20' => '5.5' + * '5.5-beta2' => '5.5' + * '5.5' => '5.5' + * + * @since 1.7 + * @return string sanitized DB version + */ +function yourls_get_database_version() { + global $ydb; + + return preg_replace( '/(^[^0-9]*)|[^0-9.].*/', '', $ydb->mysql_version() ); +} + /** * Check if PHP > 4.3 * -- 2.45.0