Update IPSet use statements
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index 07f547f..861a613 100644 (file)
@@ -381,11 +381,15 @@ abstract class Maintenance {
         * @param mixed $channel Unique identifier for the channel. See function outputChanneled.
         */
        protected function output( $out, $channel = null ) {
-               // Try to periodically flush buffered metrics to avoid OOMs
-               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-               if ( $stats->getDataCount() > 1000 ) {
-                       MediaWiki::emitBufferedStatsdData( $stats, $this->getConfig() );
+               // This is sometimes called very early, before Setup.php is included.
+               if ( class_exists( MediaWikiServices::class ) ) {
+                       // Try to periodically flush buffered metrics to avoid OOMs
+                       $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+                       if ( $stats->getDataCount() > 1000 ) {
+                               MediaWiki::emitBufferedStatsdData( $stats, $this->getConfig() );
+                       }
                }
+
                if ( $this->mQuiet ) {
                        return;
                }
@@ -410,7 +414,7 @@ abstract class Maintenance {
                        $this->fatalError( $err, intval( $die ) );
                }
                $this->outputChanneled( false );
-               if ( PHP_SAPI == 'cli' ) {
+               if ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
                        print $err;
@@ -672,7 +676,8 @@ abstract class Maintenance {
                global $IP, $wgCommandLineMode, $wgRequestTime;
 
                # Abort if called from a web server
-               if ( PHP_SAPI !== 'cli' ) {
+               # wfIsCLI() is not available yet
+               if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {
                        $this->fatalError( 'This script must be run from the command line' );
                }