Merge "jobqueue: Change internal $params logic to teach Phan (3)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 5 Apr 2019 20:27:16 +0000 (20:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 5 Apr 2019 20:27:16 +0000 (20:27 +0000)
includes/media/JpegHandler.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/media/MediaWikiMediaTestCase.php

index 4bcb53d..4aca5b3 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup Media
  */
 
+use MediaWiki\Shell\Shell;
+
 /**
  * JPEG specific handler.
  * Inherits most stuff from BitmapHandler, just here to do the metadata handler differently.
@@ -140,17 +142,23 @@ class JpegHandler extends ExifBitmapHandler {
                $rotation = ( $params['rotation'] + $this->getRotation( $file ) ) % 360;
 
                if ( $wgJpegTran && is_executable( $wgJpegTran ) ) {
-                       $cmd = wfEscapeShellArg( $wgJpegTran ) .
-                               " -rotate " . wfEscapeShellArg( $rotation ) .
-                               " -outfile " . wfEscapeShellArg( $params['dstPath'] ) .
-                               " " . wfEscapeShellArg( $params['srcPath'] );
-                       wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" );
-                       $retval = 0;
-                       $err = wfShellExecWithStderr( $cmd, $retval );
-                       if ( $retval !== 0 ) {
-                               $this->logErrorForExternalProcess( $retval, $err, $cmd );
-
-                               return new MediaTransformError( 'thumbnail_error', 0, 0, $err );
+                       $command = Shell::command( $wgJpegTran,
+                               '-rotate',
+                               $rotation,
+                               '-outfile',
+                               $params['dstPath'],
+                               $params['srcPath']
+                       );
+                       $result = $command
+                               ->includeStderr()
+                               ->execute();
+                       if ( $result->getExitCode() !== 0 ) {
+                               $this->logErrorForExternalProcess( $result->getExitCode(),
+                                       $result->getStdout(),
+                                       $command
+                               );
+
+                               return new MediaTransformError( 'thumbnail_error', 0, 0, $result->getStdout() );
                        }
 
                        return false;
@@ -240,20 +248,21 @@ class JpegHandler extends ExifBitmapHandler {
                        return false;
                }
 
-               $cmd = wfEscapeShellArg( $wgExiftool,
+               $result = Shell::command(
+                       $wgExiftool,
                        '-EXIF:ColorSpace',
                        '-ICC_Profile:ProfileDescription',
                        '-S',
                        '-T',
                        $filepath
-               );
-
-               $output = wfShellExecWithStderr( $cmd, $retval );
+               )
+                       ->includeStderr()
+                       ->execute();
 
                // Explode EXIF data into an array with [0 => Color Space, 1 => Device Model Desc]
-               $data = explode( "\t", trim( $output ) );
+               $data = explode( "\t", trim( $result->getStdout() ) );
 
-               if ( $retval !== 0 ) {
+               if ( $result->getExitCode() !== 0 ) {
                        return false;
                }
 
@@ -271,16 +280,20 @@ class JpegHandler extends ExifBitmapHandler {
                        return false;
                }
 
-               $cmd = wfEscapeShellArg( $wgExiftool,
+               $command = Shell::command( $wgExiftool,
                        '-overwrite_original',
                        '-icc_profile<=' . $profileFilepath,
                        $filepath
                );
-
-               $output = wfShellExecWithStderr( $cmd, $retval );
-
-               if ( $retval !== 0 ) {
-                       $this->logErrorForExternalProcess( $retval, $output, $cmd );
+               $result = $command
+                       ->includeStderr()
+                       ->execute();
+
+               if ( $result->getExitCode() !== 0 ) {
+                       $this->logErrorForExternalProcess( $result->getExitCode(),
+                               $result->getStdout(),
+                               $command
+                       );
 
                        return false;
                }
index f43f0a9..5119d73 100644 (file)
@@ -1364,6 +1364,9 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                        JobQueueGroup::singleton()->get( $type )->delete();
                }
 
+               // T219673: close any connections from code that failed to call reuseConnection()
+               // or is still holding onto a DBConnRef instance (e.g. in a singleton).
+               MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->closeAll();
                CloneDatabase::changePrefix( self::$oldTablePrefix );
 
                self::$oldTablePrefix = false;
index 7a536df..2e9acfa 100644 (file)
@@ -70,16 +70,10 @@ abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
         *
         * File must be in the path returned by getFilePath()
         * @param string $name File name
-        * @param string|null $type MIME type [optional]
+        * @param string|false $type MIME type [optional]
         * @return UnregisteredLocalFile
         */
-       protected function dataFile( $name, $type = null ) {
-               if ( !$type ) {
-                       // Autodetect by file extension for the lazy.
-                       $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
-                       $parts = explode( $name, '.' );
-                       $type = $magic->guessTypesForExtension( $parts[count( $parts ) - 1] );
-               }
+       protected function dataFile( $name, $type = false ) {
                return new UnregisteredLocalFile( false, $this->repo,
                        "mwstore://localtesting/data/$name", $type );
        }