r97954 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97953‎ | r97954 | r97955 >
Date:20:42, 23 September 2011
Author:aaron
Status:resolved (Comments)
Tags:config 
Comment:
Added wfShellMaintenanceCmd() for Het Deploy support
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -905,6 +905,32 @@
906906 return $a;
907907 }
908908
 909+ /**
 910+ * @dataProvider provideWfShellMaintenanceCmdList
 911+ */
 912+ function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
 913+ $actual = wfShellMaintenanceCmd( $script, $parameters, $options );
 914+ $this->assertEquals( $expected, $actual, $description );
 915+ }
 916+
 917+ function provideWfShellMaintenanceCmdList() {
 918+ global $wgPhpCli;
 919+ return array(
 920+ array( 'eval.php', array( '--help', '--test' ), array(),
 921+ "\"$wgPhpCli\" \"eval.php\" \"--help\" \"--test\"",
 922+ "Called eval.php --help --test" ),
 923+ array( 'eval.php', array( '--help', '--test space' ), array('php' => 'php5'),
 924+ "\"php5\" \"eval.php\" \"--help\" \"--test space\"",
 925+ "Called eval.php --help --test with php option" ),
 926+ array( 'eval.php', array( '--help', '--test', 'X' ), array('wrapper' => 'MWScript.php'),
 927+ "\"$wgPhpCli\" \"MWScript.php\" \"eval.php\" \"--help\" \"--test\" \"X\"",
 928+ "Called eval.php --help --test with wrapper option" ),
 929+ array( 'eval.php', array( '--help', '--test', 'y' ), array('php' => 'php5', 'wrapper' => 'MWScript.php'),
 930+ "\"php5\" \"MWScript.php\" \"eval.php\" \"--help\" \"--test\" \"y\"",
 931+ "Called eval.php --help --test with wrapper and php option" ),
 932+ );
 933+ }
 934+
909935 /* TODO: many more! */
910936 }
911937
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2805,6 +2805,31 @@
28062806 }
28072807
28082808 /**
 2809+ * Generate a shell-escaped command line string to run a maintenance script.
 2810+ * Note that $parameters should be a flat array and an option with an argument
 2811+ * should consist of two consecutive items in the array (do not use "--option value").
 2812+ * @param $script string MediaWiki maintenance script path
 2813+ * @param $parameters Array Arguments and options to the script
 2814+ * @param $options Array Associative array of options:
 2815+ * 'php': The path to the php executable
 2816+ * 'wrapper': Path to a PHP wrapper to handle the maintenance script
 2817+ * @return Array
 2818+ */
 2819+function wfShellMaintenanceCmd( $script, array $parameters = array(), array $options = array() ) {
 2820+ global $wgPhpCli;
 2821+ // Give site config file a chance to run the script in a wrapper.
 2822+ // The caller may likely want to call wfBasename() on $script.
 2823+ wfRunHooks( 'wfShellMaintenanceCmd', array( &$script, &$parameters, &$options ) );
 2824+ $cmd = isset( $options['php'] ) ? array( $options['php'] ) : array( $wgPhpCli );
 2825+ if ( isset( $options['wrapper'] ) ) {
 2826+ $cmd[] = $options['wrapper'];
 2827+ }
 2828+ $cmd[] = $script;
 2829+ // Escape each parameter for shell
 2830+ return implode( " ", array_map( 'wfEscapeShellArg', array_merge( $cmd, $parameters ) ) );
 2831+}
 2832+
 2833+/**
28092834 * This function works like "use VERSION" in Perl, the program will die with a
28102835 * backtrace if the current version of PHP is less than the version provided
28112836 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r97963Followup r97954: fix unit tests for wfShellMaintenanceCmd() to work on Unix a...brion22:17, 23 September 2011

Comments

#Comment by Catrope (talk | contribs)   21:45, 23 September 2011

Tests fail with things like:

-"/usr/bin/php" "eval.php" "--help" "--test"
+'/usr/bin/php' 'eval.php' '--help' '--test'
#Comment by Brion VIBBER (talk | contribs)   21:48, 23 September 2011

wfEscapeShellArg uses double quotes on Windows; on Unix it passes through to PHP's escapeshellarg, which traditionally uses single quotes. So you will get different results out of Windows and Unix runs.

#Comment by Aaron Schulz (talk | contribs)   22:14, 23 September 2011

That would explain. I guess the test could check for the respectively correct quotes then.

#Comment by Brion VIBBER (talk | contribs)   22:18, 23 September 2011

I tweaked it in r97963

Status & tagging log