Merge "selenium: Use async-await for wdio-mediawiki/Api internals"
[lhc/web/wiklou.git] / maintenance / shell.php
index 5df5b54..f5ebc02 100644 (file)
@@ -36,6 +36,7 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\Logger\ConsoleSpi;
+use MediaWiki\MediaWikiServices;
 
 require_once __DIR__ . '/Maintenance.php';
 
@@ -57,7 +58,7 @@ class MediaWikiShell extends Maintenance {
 
        public function execute() {
                if ( !class_exists( \Psy\Shell::class ) ) {
-                       $this->error( 'PsySH not found. Please run composer with the --dev option.', 1 );
+                       $this->fatalError( 'PsySH not found. Please run composer with the --dev option.' );
                }
 
                $traverser = new \PhpParser\NodeTraverser();
@@ -66,8 +67,12 @@ class MediaWikiShell extends Maintenance {
                // add this after initializing the code cleaner so all the default passes get added first
                $traverser->addVisitor( new CodeCleanerGlobalsPass() );
 
-               $config = new \Psy\Configuration( [ 'codeCleaner' => $codeCleaner ] );
+               $config = new \Psy\Configuration();
+               $config->setCodeCleaner( $codeCleaner );
                $config->setUpdateCheck( \Psy\VersionUpdater\Checker::NEVER );
+               // prevent https://github.com/bobthecow/psysh/issues/443 when using sudo -E
+               $config->setRuntimeDir( wfTempDir() );
+
                $shell = new \Psy\Shell( $config );
                if ( $this->hasOption( 'd' ) ) {
                        $this->setupLegacy();
@@ -83,21 +88,17 @@ class MediaWikiShell extends Maintenance {
                $d = intval( $this->getOption( 'd' ) );
                if ( $d > 0 ) {
                        LoggerFactory::registerProvider( new ConsoleSpi );
+                       // Some services hold Logger instances in object properties
+                       MediaWikiServices::resetGlobalInstance();
                }
                if ( $d > 1 ) {
                        # Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
-                       # XXX copy pasted from eval.php :(
-                       $lb = wfGetLB();
-                       $serverCount = $lb->getServerCount();
-                       for ( $i = 0; $i < $serverCount; $i++ ) {
-                               $server = $lb->getServerInfo( $i );
-                               $server['flags'] |= DBO_DEBUG;
-                               $lb->setServerInfo( $i, $server );
-                       }
+                       $this->getDB( DB_MASTER )->setFlag( DBO_DEBUG );
+                       $this->getDB( DB_REPLICA )->setFlag( DBO_DEBUG );
                }
        }
 
 }
 
-$maintClass = 'MediaWikiShell';
+$maintClass = MediaWikiShell::class;
 require_once RUN_MAINTENANCE_IF_MAIN;