From ebed393bbde259f0ea33fa2a9d3f285bfee01d5f Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Thu, 15 Jul 2010 16:27:27 +0000 Subject: [PATCH] Add cleanupChanneled() method to clean the channel consistently. --- maintenance/Maintenance.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 6433296ff0..ab995df982 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -225,8 +225,9 @@ abstract class Maintenance { return; } if ( $channel === null ) { + $this->cleanupChanneled(); + $f = fopen( 'php://stdout', 'w' ); - if ( $this->lastChannel !== null ) fwrite( $f, "\n" ); fwrite( $f, $out ); fclose( $f ); } @@ -259,6 +260,18 @@ abstract class Maintenance { private $atLineStart = true; private $lastChannel = null; + /** + * Clean up channeled output. Output a newline if necessary. + */ + public function cleanupChanneled() { + if ( !$this->atLineStart ) { + $handle = fopen( 'php://stdout', 'w' ); + fwrite( $handle, "\n" ); + fclose( $handle ); + $this->atLineStart = true; + } + } + /** * Message outputter with channeled message support. Messages on the * same channel are concatenated, but any intervening messages in another @@ -268,17 +281,13 @@ abstract class Maintenance { * channel. Channel comparison uses ===. */ public function outputChanneled( $msg, $channel = null ) { - $handle = fopen( 'php://stdout', 'w' ); - if ( $msg === false ) { - // For cleanup - if ( !$this->atLineStart ) { - fwrite( $handle, "\n" ); - } - fclose( $handle ); + $this->cleanupChanneled(); return; } + $handle = fopen( 'php://stdout', 'w' ); + // End the current line if necessary if ( !$this->atLineStart && $channel !== $this->lastChannel ) { fwrite( $handle, "\n" ); -- 2.20.1