Merge "tests: Commit initial version of DevelopmentSettings.php"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 15 Feb 2018 23:52:26 +0000 (23:52 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 15 Feb 2018 23:52:26 +0000 (23:52 +0000)
1  2 
.travis.yml
maintenance/Maintenance.php

diff --combined .travis.yml
@@@ -27,12 -27,10 +27,12 @@@ matrix
      - env: dbtype=postgres dbuser=travis
        php: 5.5
      # https://docs.travis-ci.com/user/languages/php#HHVM-versions
 -    - env: dbtype=mysql dbuser=root
 -      php: hhvm-3.12
      - env: dbtype=mysql dbuser=root
        php: hhvm-3.18
 +    - env: dbtype=mysql dbuser=root
 +      php: hhvm-3.21
 +    - env: dbtype=mysql dbuser=root
 +      php: hhvm-3.24
      - env: dbtype=mysql dbuser=root
        php: 7
      - env: dbtype=mysql dbuser=root
@@@ -69,6 -67,8 +69,8 @@@ before_script
        --dbuser "$dbuser"
        --dbpass ""
        --scriptpath "/w"
+   - echo -en "\n\nrequire_once __DIR__ . '/includes/DevelopmentSettings.php';\n" >> ./LocalSettings.php
+   - php -l ./LocalSettings.php
  
  script:
    - php tests/phpunit/phpunit.php
@@@ -182,7 -182,7 +182,7 @@@ abstract class Maintenance 
                if ( $count < 2 ) {
                        return false; // sanity
                }
 -              if ( $bt[0]['class'] !== 'Maintenance' || $bt[0]['function'] !== 'shouldExecute' ) {
 +              if ( $bt[0]['class'] !== self::class || $bt[0]['function'] !== 'shouldExecute' ) {
                        return false; // last call should be to this function
                }
                $includeFuncs = [ 'require_once', 'require', 'include', 'include_once' ];
         * @param mixed $channel Unique identifier for the channel. See function outputChanneled.
         */
        protected function output( $out, $channel = null ) {
 +              // 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;
                }
                        $this->fatalError( $err, intval( $die ) );
                }
                $this->outputChanneled( false );
 -              if ( PHP_SAPI == 'cli' ) {
 +              if (
 +                      ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) &&
 +                      !defined( 'MW_PHPUNIT_TEST' )
 +              ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
                        print $err;
                        "http://en.wikipedia.org. This is sometimes necessary because " .
                        "server name detection may fail in command line scripts.", false, true );
                $this->addOption( 'profiler', 'Profiler output format (usually "text")', false, true );
+               // This is named --mwdebug, because --debug would conflict in the phpunit.php CLI script.
+               $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, true );
  
                # Save generic options to display them separately in help
                $this->mGenericParameters = $this->mParams;
                $lbFactory->setAgentName(
                        mb_strlen( $agent ) > 15 ? mb_substr( $agent, 0, 15 ) . '...' : $agent
                );
 -              self::setLBFactoryTriggers( $lbFactory );
 +              self::setLBFactoryTriggers( $lbFactory, $this->getConfig() );
        }
  
        /**
         * @param LBFactory $LBFactory
 +       * @param Config $config
         * @since 1.28
         */
 -      public static function setLBFactoryTriggers( LBFactory $LBFactory ) {
 +      public static function setLBFactoryTriggers( LBFactory $LBFactory, Config $config ) {
 +              $services = MediaWikiServices::getInstance();
 +              $stats = $services->getStatsdDataFactory();
                // Hook into period lag checks which often happen in long-running scripts
 -              $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
 +              $lbFactory = $services->getDBLoadBalancerFactory();
                $lbFactory->setWaitForReplicationListener(
                        __METHOD__,
 -                      function () {
 -                              global $wgCommandLineMode;
 +                      function () use ( $stats, $config ) {
                                // Check config in case of JobRunner and unit tests
 -                              if ( $wgCommandLineMode ) {
 +                              if ( $config->get( 'CommandLineMode' ) ) {
                                        DeferredUpdates::tryOpportunisticExecute( 'run' );
                                }
 +                              // Try to periodically flush buffered metrics to avoid OOMs
 +                              MediaWiki::emitBufferedStatsdData( $stats, $config );
                        }
                );
                // Check for other windows to run them. A script may read or do a few writes
                // to the master but mostly be writing to something else, like a file store.
                $lbFactory->getMainLB()->setTransactionListener(
                        __METHOD__,
 -                      function ( $trigger ) {
 -                              global $wgCommandLineMode;
 +                      function ( $trigger ) use ( $stats, $config ) {
                                // Check config in case of JobRunner and unit tests
 -                              if ( $wgCommandLineMode && $trigger === IDatabase::TRIGGER_COMMIT ) {
 +                              if ( $config->get( 'CommandLineMode' ) && $trigger === IDatabase::TRIGGER_COMMIT ) {
                                        DeferredUpdates::tryOpportunisticExecute( 'run' );
                                }
 +                              // Try to periodically flush buffered metrics to avoid OOMs
 +                              MediaWiki::emitBufferedStatsdData( $stats, $config );
                        }
                );
        }
                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' );
                }
  
                        MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
                }
  
+               # Apply debug settings
+               if ( $this->hasOption( 'mwdebug' ) ) {
+                       require __DIR__ . '/../includes/DevelopmentSettings.php';
+               }
                // Per-script profiling; useful for debugging
                $this->activateProfiler();
  
  
                $wgShowSQLErrors = true;
  
 -              MediaWiki\suppressWarnings();
 +              Wikimedia\suppressWarnings();
                set_time_limit( 0 );
 -              MediaWiki\restoreWarnings();
 +              Wikimedia\restoreWarnings();
  
                $this->adjustMemoryLimit();
        }
                                "must exist and be readable in the source directory.\n" .
                                "Use --conf to specify it." );
                }
 +              if ( isset( $this->mOptions['server'] ) ) {
 +                      $_SERVER['SERVER_NAME'] = $this->mOptions['server'];
 +              }
                $wgCommandLineMode = true;
  
                return $settingsFile;