http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97954
Revision: 97954
Author: aaron
Date: 2011-09-23 20:42:22 +0000 (Fri, 23 Sep 2011)
Log Message:
-----------
Added wfShellMaintenanceCmd() for Het Deploy support
Modified Paths:
--------------
trunk/phase3/includes/GlobalFunctions.php
trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
Modified: trunk/phase3/includes/GlobalFunctions.php
===================================================================
--- trunk/phase3/includes/GlobalFunctions.php 2011-09-23 20:30:23 UTC (rev
97953)
+++ trunk/phase3/includes/GlobalFunctions.php 2011-09-23 20:42:22 UTC (rev
97954)
@@ -2805,6 +2805,31 @@
}
/**
+ * Generate a shell-escaped command line string to run a maintenance 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 $script string MediaWiki maintenance script path
+ * @param $parameters Array Arguments and options to the script
+ * @param $options Array Associative array of options:
+ * 'php': The path to the php executable
+ * 'wrapper': Path to a PHP wrapper to handle the maintenance
script
+ * @return Array
+ */
+function wfShellMaintenanceCmd( $script, array $parameters = array(), array
$options = array() ) {
+ 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.
+ wfRunHooks( 'wfShellMaintenanceCmd', array( &$script, &$parameters,
&$options ) );
+ $cmd = isset( $options['php'] ) ? array( $options['php'] ) : array(
$wgPhpCli );
+ if ( isset( $options['wrapper'] ) ) {
+ $cmd[] = $options['wrapper'];
+ }
+ $cmd[] = $script;
+ // Escape each parameter for shell
+ return implode( " ", array_map( 'wfEscapeShellArg', array_merge( $cmd,
$parameters ) ) );
+}
+
+/**
* This function works like "use VERSION" in Perl, the program will die with a
* backtrace if the current version of PHP is less than the version provided
*
Modified: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
2011-09-23 20:30:23 UTC (rev 97953)
+++ trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
2011-09-23 20:42:22 UTC (rev 97954)
@@ -905,6 +905,32 @@
return $a;
}
+ /**
+ * @dataProvider provideWfShellMaintenanceCmdList
+ */
+ function testWfShellMaintenanceCmd( $script, $parameters, $options,
$expected, $description ) {
+ $actual = wfShellMaintenanceCmd( $script, $parameters, $options
);
+ $this->assertEquals( $expected, $actual, $description );
+ }
+
+ function provideWfShellMaintenanceCmdList() {
+ global $wgPhpCli;
+ return array(
+ array( 'eval.php', array( '--help', '--test' ), array(),
+ "\"$wgPhpCli\" \"eval.php\" \"--help\"
\"--test\"",
+ "Called eval.php --help --test" ),
+ array( 'eval.php', array( '--help', '--test space' ),
array('php' => 'php5'),
+ "\"php5\" \"eval.php\" \"--help\" \"--test
space\"",
+ "Called eval.php --help --test with php option"
),
+ array( 'eval.php', array( '--help', '--test', 'X' ),
array('wrapper' => 'MWScript.php'),
+ "\"$wgPhpCli\" \"MWScript.php\" \"eval.php\"
\"--help\" \"--test\" \"X\"",
+ "Called eval.php --help --test with wrapper
option" ),
+ array( 'eval.php', array( '--help', '--test', 'y' ),
array('php' => 'php5', 'wrapper' => 'MWScript.php'),
+ "\"php5\" \"MWScript.php\" \"eval.php\"
\"--help\" \"--test\" \"y\"",
+ "Called eval.php --help --test with wrapper and
php option" ),
+ );
+ }
+
/* TODO: many more! */
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs