Problem/Motivation
When the cron job of Bynder fails to process all media in updateMediaEntities
, the error reporting breaks.
The error:
Call to a member function id() on array in Drupal\bynder\BynderService->updateMetadataLastMediaEntities() (line 234 of .../bynder/src/BynderService.php)
This is the piece of code that breaks:
$updated_entities = $this->updateMediaEntities($bynder_media_entities);
$missing_remote_entities = [];
// Log warning in case a media entity has been removed in the remote system.
foreach ($bynder_media_entities as $missing_remote_entity) {
$missing_remote_entities[$missing_remote_entity->id()] = $missing_remote_entity;
The reason is that the array-structure is different then expected.
The actual array structure of $bynder_media_entities
is:
$bynder_media_entities = {array[11]}
1C56D778-DE75-47FA-A660B9AA828B28FF = {array[1]}
3671 = {Drupal\media\Entity\Media}
Notice that the Media entity is nested inside the array with the UUID key.
This
Steps to reproduce
Proposed resolution
Add $missing_remote_entity = reset($missing_remote_entity);
in the foreach loop when reporting erros.
$updated_entities = $this->updateMediaEntities($bynder_media_entities);
$missing_remote_entities = [];
// Log warning in case a media entity has been removed in the remote system.
foreach ($bynder_media_entities as $missing_remote_entity) {
$missing_remote_entity = reset($missing_remote_entity); # <-- new
$missing_remote_entities[$missing_remote_entity->id()] = $missing_remote_entity;
Remaining tasks
User interface changes
API changes
Data model changes