From: Aaron Schulz Date: Wed, 30 Apr 2014 07:50:16 +0000 (-0700) Subject: Fixed "getCachedWork" callback in thumb.php to avoid 404s in the stream method X-Git-Tag: 1.31.0-rc.0~15951^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=41730cbfb9289b38c6808bc14bfdbb7e304b3a21;p=lhc%2Fweb%2Fwiklou.git Fixed "getCachedWork" callback in thumb.php to avoid 404s in the stream method Change-Id: Id3781b87023291b9f7b2c7b3d8ae429a4065c227 --- diff --git a/thumb.php b/thumb.php index c5da918e08..a5a2bcc12f 100644 --- a/thumb.php +++ b/thumb.php @@ -327,7 +327,7 @@ function wfStreamThumb( array $params ) { } // Actually generate a new thumbnail - list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName ); + list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); // Check for thumbnail generation errors... $msg = wfMessage( 'thumbnail_error' ); @@ -356,9 +356,10 @@ function wfStreamThumb( array $params ) { * @param File $file * @param array $params * @param string $thumbName + * @param string $thumbPath * @return array (MediaTransformOutput|bool, string|bool error message HTML) */ -function wfGenerateThumbnail( File $file, array $params, $thumbName ) { +function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath ) { global $wgMemc, $wgAttemptFailureEpoch; $key = wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch, @@ -389,8 +390,12 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName ) { 'doWork' => function() use ( $file, $params ) { return $file->transform( $params, File::RENDER_NOW ); }, - 'getCachedWork' => function() use ( $file, $params ) { - return $file->transform( $params ); + 'getCachedWork' => function() use ( $file, $params, $thumbPath ) { + // If the worker that finished made this thumbnail then use it. + // Otherwise, it probably made a different thumbnail for this file. + return $file->getRepo()->fileExists( $thumbPath ) + ? $file->transform( $params ) + : false; // retry once more in exclusive mode }, 'fallback' => function() { return wfMessage( 'generic-pool-error' )->parse();