Problem/Motivation
When used in conjunction with the
S3 File System β
module, thumbnail generation throws an exception:
TypeError: md5_file() expects parameter 1 to be a valid path, bool given in md5_file() (line 195 of /var/www/web/modules/contrib/brightcove/src/Entity/BrightcoveVideo.php)
Steps to reproduce
- Install both the brightcove and s3fs modules.
- Configure Brightcove.
- Configure S3fs and enable the s3fs.use_s3_for_public option so that S3 takes over the public:// file handler.
- Run the Brightcove cron job and check the error log.
Proposed resolution
The problem is caused by lines 194 and 195 of BrightcoveVideo:
$file_path = $file_system->realpath($file->getFileUri());
$file_md5 = md5_file($file_path);
With the s3fs.use_s3_for_public option enabled, the S3 module replaces the public:// file handler with its own. Because S3 is a remote stream wrapper, realpath() will return false, thus triggering the exception when that is passed to md5_file(). This could be solved by changing line 195 to set $file_md5 to false if the $file_path is false, like so:
$file_md5 = $file_path ? md5_file($file_path) : FALSE;
This is essentially the same result as if md5_file() had failed to calculate the file's hash, which is arguably what is happening here given that there isn't a standard method for getting a file's MD5 hash from a remote stream.