X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fshell%2FShell.php;h=742e1424ad265d75016c9fac5d511dc8bab42cc2;hb=dfa0cc6df9cf1d4cc2cb7ce87ce245bcdd6d1c89;hp=05463dbf35a738152a8813b672d4912a9fc929f5;hpb=e27cf1f7ef3e09d0ca7f97bee9c046e13abe35f6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/shell/Shell.php b/includes/shell/Shell.php index 05463dbf35..742e1424ad 100644 --- a/includes/shell/Shell.php +++ b/includes/shell/Shell.php @@ -22,6 +22,7 @@ namespace MediaWiki\Shell; +use Hooks; use MediaWiki\MediaWikiServices; /** @@ -31,6 +32,7 @@ use MediaWiki\MediaWikiServices; * * Use call chaining with this class for expressiveness: * $result = Shell::command( 'some command' ) + * ->input( 'foo' ) * ->environment( [ 'ENVIRONMENT_VARIABLE' => 'VALUE' ] ) * ->limits( [ 'time' => 300 ] ) * ->execute(); @@ -99,6 +101,13 @@ class Shell { */ const NO_LOCALSETTINGS = 32; + /** + * Don't apply any restrictions + * + * @since 1.31 + */ + const RESTRICT_NONE = 0; + /** * Returns a new instance of Command class * @@ -211,4 +220,32 @@ class Shell { } return $retVal; } + + /** + * Generate a Command object to run a MediaWiki CLI script. + * Note that $parameters should be a flat array and an option with an argument + * should consist of two consecutive items in the array (do not use "--option value"). + * + * @param string $script MediaWiki CLI script with full path + * @param string[] $parameters Arguments and options to the script + * @param array $options Associative array of options: + * 'php': The path to the php executable + * 'wrapper': Path to a PHP wrapper to handle the maintenance script + * @return Command + */ + public static function makeScriptCommand( $script, $parameters, $options = [] ) { + global $wgPhpCli; + // Give site config file a chance to run the script in a wrapper. + // The caller may likely want to call wfBasename() on $script. + Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] ); + $cmd = isset( $options['php'] ) ? [ $options['php'] ] : [ $wgPhpCli ]; + if ( isset( $options['wrapper'] ) ) { + $cmd[] = $options['wrapper']; + } + $cmd[] = $script; + + return self::command( $cmd ) + ->params( $parameters ) + ->restrict( self::RESTRICT_DEFAULT & ~self::NO_LOCALSETTINGS ); + } }