MediaWiki master
MediaWiki\Maintenance\MaintenanceRunner Class Reference

A runner for maintenance scripts. More...

Public Member Functions

 __construct ()
 Default constructor.
 
 defineSettings ()
 Define how settings are loaded (e.g.
 
 getName ()
 Returns the maintenance script name to show in the help message.
 
 initForClass (string $scriptClass, $argv)
 Initialize the runner for the given class.
 
 initFromWrapper (array $argv)
 Initialize the runner from the given command line arguments as passed to a wrapper script.
 
 run ()
 Run the maintenance script.
 
 setup (SettingsBuilder $settings)
 MW_FINAL_SETUP_CALLBACK handler, for setting up the Maintenance object.
 

Static Public Member Functions

static shouldExecute ()
 Should we execute the maintenance script, or just allow it to be included as a standalone class? It checks that the call stack only includes this function and "requires" (meaning was called from the file scope)
 

Protected Member Functions

 addDefaultParams ()
 Add the default parameters to the scripts.
 
 cleanup ()
 Handler for register_shutdown_function.
 
 error (string $msg)
 
 fatalError ( $msg, $exitCode=1)
 Output a message and terminate the current script.
 
 findScriptClass (string $script)
 
 getExtensionInfo (string $extName)
 
 getMwInstallPath ()
 
 getScriptClass ()
 
 preloadScriptFile (string $script)
 Preload the script file, so any defines in file level code are executed.
 

Detailed Description

A runner for maintenance scripts.

Since
1.39
Stability: unstable

Definition at line 25 of file MaintenanceRunner.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Maintenance\MaintenanceRunner::__construct ( )

Default constructor.

Children should call this first if implementing their own constructors

Stability: stable
to call

Definition at line 62 of file MaintenanceRunner.php.

References MediaWiki\Maintenance\MaintenanceRunner\addDefaultParams().

Member Function Documentation

◆ addDefaultParams()

MediaWiki\Maintenance\MaintenanceRunner::addDefaultParams ( )
protected

Add the default parameters to the scripts.

Definition at line 78 of file MaintenanceRunner.php.

References MediaWiki\Maintenance\Maintenance\GENERIC_MAINTENANCE_PARAMETERS.

Referenced by MediaWiki\Maintenance\MaintenanceRunner\__construct().

◆ cleanup()

MediaWiki\Maintenance\MaintenanceRunner::cleanup ( )
protected

Handler for register_shutdown_function.

Access: internal
Returns
void

Definition at line 775 of file MaintenanceRunner.php.

◆ defineSettings()

MediaWiki\Maintenance\MaintenanceRunner::defineSettings ( )

Define how settings are loaded (e.g.

LocalSettings.php)

Note
Called before Setup.php
Access: internal
Returns
void

Definition at line 538 of file MaintenanceRunner.php.

References $IP, and wfDetectLocalSettingsFile().

◆ error()

MediaWiki\Maintenance\MaintenanceRunner::error ( string $msg)
protected

Definition at line 733 of file MaintenanceRunner.php.

◆ fatalError()

MediaWiki\Maintenance\MaintenanceRunner::fatalError ( $msg,
$exitCode = 1 )
protected

Output a message and terminate the current script.

Parameters
string$msgError message
int$exitCodePHP exit status. Should be in range 1-254.
Returns
never

Definition at line 728 of file MaintenanceRunner.php.

◆ findScriptClass()

MediaWiki\Maintenance\MaintenanceRunner::findScriptClass ( string $script)
protected
Access: internal
Parameters
string$script
Returns
class-string<Maintenance>

Definition at line 399 of file MaintenanceRunner.php.

◆ getExtensionInfo()

MediaWiki\Maintenance\MaintenanceRunner::getExtensionInfo ( string $extName)
protected

Definition at line 242 of file MaintenanceRunner.php.

◆ getMwInstallPath()

MediaWiki\Maintenance\MaintenanceRunner::getMwInstallPath ( )
protected
Returns
string The value of the constant MW_INSTALL_PATH. This method mocked in unit tests.

Definition at line 294 of file MaintenanceRunner.php.

◆ getName()

MediaWiki\Maintenance\MaintenanceRunner::getName ( )

Returns the maintenance script name to show in the help message.

Definition at line 495 of file MaintenanceRunner.php.

◆ getScriptClass()

MediaWiki\Maintenance\MaintenanceRunner::getScriptClass ( )
protected
Returns
class-string<Maintenance>

Definition at line 377 of file MaintenanceRunner.php.

◆ initForClass()

MediaWiki\Maintenance\MaintenanceRunner::initForClass ( string $scriptClass,
$argv )

Initialize the runner for the given class.

This is used when running scripts directly, without a wrapper.

Note
Called before Setup.php
Parameters
string$scriptClassThe script class to run
string[]$argvThe arguments to passed to the script, including the script itself at index 0.

Definition at line 187 of file MaintenanceRunner.php.

◆ initFromWrapper()

MediaWiki\Maintenance\MaintenanceRunner::initFromWrapper ( array $argv)

Initialize the runner from the given command line arguments as passed to a wrapper script.

Note
Called before Setup.php
Parameters
string[]$argvThe arguments passed from the command line, including the wrapper script at index 0, and usually the script to run at index 1.

Definition at line 129 of file MaintenanceRunner.php.

◆ preloadScriptFile()

MediaWiki\Maintenance\MaintenanceRunner::preloadScriptFile ( string $script)
protected

Preload the script file, so any defines in file level code are executed.

This way, scripts can control what Setup.php does.

Access: internal
Parameters
string$script

Definition at line 342 of file MaintenanceRunner.php.

◆ run()

MediaWiki\Maintenance\MaintenanceRunner::run ( )

Run the maintenance script.

Note
The process should exit immediately after this method returns. At that point, MediaWiki will already have been shut down. It is no longer safe to perform any write operations on the database.
Any exceptions thrown by the maintenance script will cause this method to terminate the process after reporting the error to the user, without shutdown and cleanup.
Returns
bool true on success, false on failure, passed through from Maintenance::execute().

Definition at line 656 of file MaintenanceRunner.php.

◆ setup()

MediaWiki\Maintenance\MaintenanceRunner::setup ( SettingsBuilder $settings)

MW_FINAL_SETUP_CALLBACK handler, for setting up the Maintenance object.

Definition at line 443 of file MaintenanceRunner.php.

◆ shouldExecute()

static MediaWiki\Maintenance\MaintenanceRunner::shouldExecute ( )
static

Should we execute the maintenance script, or just allow it to be included as a standalone class? It checks that the call stack only includes this function and "requires" (meaning was called from the file scope)

Returns
bool

Definition at line 749 of file MaintenanceRunner.php.

References MW_ENTRY_POINT.


The documentation for this class was generated from the following file: