rest: Verify that file exists before calling filesize

Bug: T252128
Change-Id: I2de87d723fdd99bea0f1dadd23648470759a103e
This commit is contained in:
Peter Ovchyn 2020-05-07 19:29:51 +03:00
parent 34f54dd1ad
commit 6e004092ca
2 changed files with 4 additions and 2 deletions

View file

@ -92,7 +92,9 @@ class SearchResultProvideThumbnailHookHandler {
if ( !$thumb ) {
continue;
}
$thumbSize = $thumb->getLocalCopyPath() ? filesize( $thumb->getLocalCopyPath() ) : null;
$localPath = $thumb->getLocalCopyPath();
$thumbSize = $localPath && file_exists( $localPath ) ? filesize( $localPath ) : null;
$res[$pageId] = new SearchResultThumbnail(
$thumb->getFile()->getMimeType(),

View file

@ -35,7 +35,7 @@ class SearchResultProvideThumbnailHookHandlerTest extends MediaWikiTestCase {
] )
->getMock();
$thumbnail->expects( $this->exactly( $thumbFilePath ? 2 : 1 ) )
$thumbnail->expects( $this->once() )
->method( 'getLocalCopyPath' )
->willReturn( $thumbFilePath );