From bb45c5e8a3034a24fa7c85f27c4ce035de56ccb0 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 15 Nov 2011 15:04:36 +0000 Subject: [PATCH] Address fixme on r101644 (bug 32325, bug 32263), originally for bug 31822. PHP 5.2 below 5.2.7 throws a warning when you try to fopen() in append mode. Fixed by only fwrite()ing to STDIN|STDERR when in cli, use print otherwise (per Tim's suggestion). People didn't seem to like the idea of bumping the minimum version to 5.2.7 since some distros like being behind the times. --- maintenance/Maintenance.php | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 454891f27f..c807c08a03 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -309,10 +309,11 @@ abstract class Maintenance { } if ( $channel === null ) { $this->cleanupChanneled(); - - $f = fopen( 'php://stdout', 'a' ); - fwrite( $f, $out ); - fclose( $f ); + if( php_sapi_name() == 'cli' ) { + fwrite( STDOUT, $out ); + } else { + print( $out ); + } } else { $out = preg_replace( '/\n\z/', '', $out ); @@ -331,9 +332,7 @@ abstract class Maintenance { if ( php_sapi_name() == 'cli' ) { fwrite( STDERR, $err . "\n" ); } else { - $f = fopen( 'php://stderr', 'a' ); - fwrite( $f, $err . "\n" ); - fclose( $f ); + print $err; } $die = intval( $die ); if ( $die > 0 ) { @@ -349,9 +348,11 @@ abstract class Maintenance { */ public function cleanupChanneled() { if ( !$this->atLineStart ) { - $handle = fopen( 'php://stdout', 'w' ); - fwrite( $handle, "\n" ); - fclose( $handle ); + if( php_sapi_name() == 'cli' ) { + fwrite( STDOUT, "\n" ); + } else { + print "\n"; + } $this->atLineStart = true; } } @@ -370,25 +371,34 @@ abstract class Maintenance { return; } - $handle = fopen( 'php://stdout', 'a' ); + $cli = php_sapi_name() == 'cli'; // End the current line if necessary if ( !$this->atLineStart && $channel !== $this->lastChannel ) { - fwrite( $handle, "\n" ); + if( $cli ) { + fwrite( STDOUT, "\n" ); + } else { + print "\n"; + } } - fwrite( $handle, $msg ); + if( $cli ) { + fwrite( STDOUT, $msg ); + } else { + print $msg; + } $this->atLineStart = false; if ( $channel === null ) { // For unchanneled messages, output trailing newline immediately - fwrite( $handle, "\n" ); + if( $handle ) { + fwrite( STDOUT, "\n" ); + } else { + print "\n"; + } $this->atLineStart = true; } $this->lastChannel = $channel; - - // Cleanup handle - fclose( $handle ); } /** -- 2.20.1