MaxSem has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/391156 )
Change subject: Convert RandomImageGenerator to use the new execution framework
......................................................................
Convert RandomImageGenerator to use the new execution framework
Introduces a stringifier for Command, useful for debugging.
Change-Id: Ifcfccaef5a609e0cf30186e39a6bd0fa971c2dbd
---
M includes/shell/Command.php
M tests/phpunit/includes/api/RandomImageGenerator.php
2 files changed, 33 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/56/391156/1
diff --git a/includes/shell/Command.php b/includes/shell/Command.php
index 9f080d5..9090c97 100644
--- a/includes/shell/Command.php
+++ b/includes/shell/Command.php
@@ -450,4 +450,15 @@
return new Result( $retval, $outBuffer, $errBuffer );
}
+
+ /**
+ * Returns the final command line before environment/limiting, etc are
applied.
+ * Use string conversion only for debugging, don't try to pass this to
+ * some other execution medium.
+ *
+ * @return string
+ */
+ public function __toString() {
+ return $this->command;
+ }
}
diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php
b/tests/phpunit/includes/api/RandomImageGenerator.php
index 50a59f9..dd68647 100644
--- a/tests/phpunit/includes/api/RandomImageGenerator.php
+++ b/tests/phpunit/includes/api/RandomImageGenerator.php
@@ -23,6 +23,8 @@
* @author Neil Kandalgaonkar <[email protected]>
*/
+use MediaWiki\Shell\Shell;
+
/**
* RandomImageGenerator: does what it says on the tin.
* Can fetch a random image, or also write a number of them to disk with
random filenames.
@@ -310,16 +312,16 @@
// for now (only works if you have exiv2 installed, a program
to read
// and manipulate exif).
if ( $wgExiv2Command ) {
- $cmd = wfEscapeShellArg( $wgExiv2Command )
- . " -M "
- . wfEscapeShellArg( "set Exif.Image.Orientation
" . $orientation['exifCode'] )
- . " "
- . wfEscapeShellArg( $filename );
+ $command = Shell::command( $wgExiv2Command,
+ '-M',
+ "set Exif.Image.Orientation
{$orientation['exifCode']}",
+ $filename
+ )->includeStderr();
- $retval = 0;
- $err = wfShellExec( $cmd, $retval );
+ $result = $command->execute();
+ $retval = $result->getExitCode();
if ( $retval !== 0 ) {
- print "Error with $cmd: $retval, $err\n";
+ print "Error with $command: $retval,
{$result->getStdout()}\n";
}
}
}
@@ -396,22 +398,25 @@
*/
public function writeImageWithCommandLine( $spec, $format, $filename ) {
global $wgImageMagickConvertCommand;
- $args = [];
- $args[] = "-size " . wfEscapeShellArg( $spec['width'] . 'x' .
$spec['height'] );
- $args[] = wfEscapeShellArg( "xc:" . $spec['fill'] );
+
+ $args = [
+ $wgImageMagickConvertCommand,
+ '-size',
+ $spec['width'] . 'x' . $spec['height'],
+ "xc:{$spec['fill']}",
+ ];
foreach ( $spec['draws'] as $draw ) {
$fill = $draw['fill'];
$polygon = self::shapePointsToString( $draw['shape'] );
$drawCommand = "fill $fill polygon $polygon";
- $args[] = '-draw ' . wfEscapeShellArg( $drawCommand );
+ $args[] = '-draw';
+ $args[] = $drawCommand;
}
- $args[] = wfEscapeShellArg( $filename );
+ $args[] = $filename;
- $command = wfEscapeShellArg( $wgImageMagickConvertCommand ) . "
" . implode( " ", $args );
- $retval = null;
- wfShellExec( $command, $retval );
+ $result = Shell::command( $args )->execute();
- return ( $retval === 0 );
+ return ( $result->getExitCode() === 0 );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/391156
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifcfccaef5a609e0cf30186e39a6bd0fa971c2dbd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits