From: Chad Horohoe Date: Tue, 15 Nov 2011 15:04:36 +0000 (+0000) Subject: Address fixme on r101644 (bug 32325, bug 32263), originally for bug 31822. PHP 5... X-Git-Tag: 1.31.0-rc.0~26491 X-Git-Url: http://git.cyclocoop.org/%27.parametre_url%28%20%20%20generer_action_auteur%28%27charger_plugin%27%2C%20%27update_flux%27%29%2C%27update_flux%27%2C%20%27oui%27%29.%27?a=commitdiff_plain;h=bb45c5e8a3034a24fa7c85f27c4ce035de56ccb0;p=lhc%2Fweb%2Fwiklou.git 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. --- 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 ); } /**