Problem/Motivation
In PHP 8, passing an empty string to file_get_contents()
throws an error which completely stops further code execution.
[error] ValueError: Path cannot be empty in file_get_contents()
The File
@DataFetcher
plugin does not check to see if $url
is not empty before passing it through to file_get_contents()
.
In PHP <8 this would not error in this way and the rest of the code in the block would execute as intended (if file_get_contents()
returned false
), ending up with the MigrateException being throw.
This may seem edge casey, but on a particular project we deliberately have this set to an empty string in the yml and then use a hook_migration_plugins_alter()
implementation to set the urls
key dynamically.
Previously under PHP7, running migrate:status
would still work, but under PHP8+ running migrate:status
will fail and execution is halted when it encounters the empty value.
Steps to reproduce
Use PHP 8, define a migration source plugin (inside if a migration .yml) to use the file
data_fetcher_plugin with a blank string for urls
, e.g. (excerpt below)
#... the start of the migration yml
source:
plugin: url
data_fetcher_plugin: file
data_parser_plugin: json
urls: ''
item_selector: some_field
fields:
-
name: some_name
label: some_label
selector: some_selector
#... the rest of the migration yml
Proposed resolution
Set the $response
to FALSE
and only call file_get_contents()
if $url
is not empty.
Remaining tasks
MR to follow.
User interface changes
n/a
API changes
n/a
Data model changes
n/a