From 3b03a3ea797f5e5e85385b2ca3208c1b05b9765b Mon Sep 17 00:00:00 2001 From: ozh Date: Thu, 26 Dec 2013 15:40:47 +0100 Subject: [PATCH] Introduce function yourls_debug_log() --- admin/install.php | 4 ++-- includes/class-mysql.php | 2 +- includes/functions-auth.php | 6 ++---- includes/functions.php | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/admin/install.php b/admin/install.php index 0567e3a..0461ec5 100644 --- a/admin/install.php +++ b/admin/install.php @@ -11,12 +11,12 @@ // Check pre-requisites 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(); + yourls_debug_log( 'MySQL version: ' . yourls_get_database_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(); + yourls_debug_log( 'PHP version: ' . phpversion() ); } // Is YOURLS already installed ? diff --git a/includes/class-mysql.php b/includes/class-mysql.php index c1b2b6e..08d1143 100644 --- a/includes/class-mysql.php +++ b/includes/class-mysql.php @@ -46,6 +46,6 @@ function yourls_set_DB_driver( ) { $ydb = new $class( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST ); - $ydb->debug_log[] = "DB driver: $driver"; + yourls_debug_log( "DB driver: $driver" ); } diff --git a/includes/functions-auth.php b/includes/functions-auth.php index 4a34d77..303d57e 100644 --- a/includes/functions-auth.php +++ b/includes/functions-auth.php @@ -182,8 +182,7 @@ function yourls_hash_passwords_now( $config_file ) { $configdata = preg_replace( $pattern, $replace, $configdata, -1, $count ); // There should be exactly one replacement. Otherwise, fast fail. if ( $count != 1 ) { - global $ydb; - $ydb->debug_log[] = "Problem with preg_replace for password hash of user $user"; + yourls_debug_log( "Problem with preg_replace for password hash of user $user" ); return 'preg_replace problem'; } } @@ -194,8 +193,7 @@ function yourls_hash_passwords_now( $config_file ) { $success = file_put_contents( $config_file, $configdata ); if ( $success === FALSE ) { - global $ydb; - $ydb->debug_log[] = "Failed writing to " . $config_file; + yourls_debug_log( 'Failed writing to ' . $config_file ); return 'could not write file'; } return true; diff --git a/includes/functions.php b/includes/functions.php index 05f9fa1..03a2681 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2183,3 +2183,19 @@ function yourls_deprecated_function( $function, $version, $replacement = null ) function yourls_return_if_not_empty_string( $val ) { return( $val !== '' ); } + +/** + * Add a message to the debug log + * + * When in debug mode ( YOURLS_DEBUG == true ) the debug log is echoed in yourls_html_footer() + * Log messages are appended to $ydb->debug_log array, which is instanciated within class ezSQLcore_YOURLS + * + * @since 1.7 + * @param string $msg Message to add to the debug log + * @return string The message itself + */ +function yourls_debug_log( $msg ) { + global $ydb; + $ydb->debug_log[] = $msg; + return $msg; +} \ No newline at end of file -- 2.45.0