Problem/Motivation
During migrations, I am getting hundreds of error messages like these:
[warning] Missing file with ID . ImageItem.php
[warning] Missing file with ID 0. ImageItem.php
Sometimes it is hundreds of one, sometimes hundreds of the other, and sometimes they are in pairs, one followed by the other hundreds of times over.
I am only seeing these with the ID being empty or 0. These are generated when migrating nodes that have an empty image field.
The errors are triggered by the trigger_error()
in this:
public function preSave() {
parent::preSave();
$width = $this->width;
$height = $this->height;
// Determine the dimensions if necessary.
if ($this->entity && $this->entity instanceof EntityInterface) {
if (empty($width) || empty($height)) {
$image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
if ($image->isValid()) {
$this->width = $image->getWidth();
$this->height = $image->getHeight();
}
}
}
else {
trigger_error(sprintf("Missing file with ID %s.", $this->target_id), E_USER_WARNING);
}
}
I don't think either empty or 0 is a valid ID, so this error message is not correct.
Proposed resolution
Use the existing error message when target_id
is a non-zero integer. Otherwise, use a different message. (Or perhaps none at all; does empty or 0 mean there is no entity and this is not actually a problem?)
Remaining tasks
Decide what the different error message should be. Implement.