Merge "Fix Maintenance::output when called very early"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 4 Jan 2018 23:35:55 +0000 (23:35 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Jan 2018 23:35:55 +0000 (23:35 +0000)
maintenance/Maintenance.php

index 07f547f..8bfead3 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;
                }