From 803a29127ce02734ab2dd83fff2cf716c98eedad Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Fri, 5 Jan 2018 00:19:55 +0100 Subject: [PATCH] Fix Maintenance::output when called very early If a maintenance script is called with --help (or without required args), this is currently failing, as MediaWikiServices is only loaded after Maintenance::setup is initially called. Follows 336454104d1249439e3ff97746de69c5e7b4a5f9. Change-Id: Ied283d362675b6b98bd3144132a240b432998991 --- maintenance/Maintenance.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 07f547f48a..8bfead372a 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -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; } -- 2.20.1