Add cleanupChanneled() method to clean the channel consistently.
This commit is contained in:
parent
5de5086351
commit
ebed393bbd
1 changed files with 17 additions and 8 deletions
|
|
@ -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" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue