Problem/Motivation
Episode images are not updating.
Steps to reproduce
This one is a bit tricky to reproduce because it relies on having access to the pbs backend in order to update an image.
But assuming you have that:
1. Import an episode that does not have any images.
2. Add an image to the episode.
3. Let cron run to update the episode.
4. You will see the image is still missing.
* You could also import an episode that does have an image, and then modify the image.
Here is an example of an episode that has an image with an updated_at > the episode updated_at:
https://media.services.pbs.org/api/v1/episodes/0748b8b5-86d6-42c5-a30b-2...
Proposed resolution
The "getLatestUpdatedAt" function is used to check an item in the api response and determine if any changes have been made since it was last imported. It does check the "updated_at" timestamp for images in a way that works for shows, but not episodes. Shows have an image directly associated with them ($item->attributes->images), but episode images are indirectly associated through assets.
/**
* Gets latest `updated_at` field from an API response object.
*
* This method accounts for the `updated_at` fields in the images array for a
* an item. These updated dates do not bubble to the top level of the item
* for some reason. Others, e.g. "availabilities" and "geo" do bubble up.
*
* @param object $item
* API object.
*
* @return \DateTime|null
* Latest `updated_at` field value or NULL if DateTime create fails.
*/
public static function getLatestUpdatedAt(object $item): ?DateTime {
$updated_at = self::dateTimeNoMicroseconds($item->attributes->updated_at);
if (isset($item->attributes->images)) {
foreach ($item->attributes->images as $image) {
$image_updated_at = self::dateTimeNoMicroseconds($image->updated_at);
if ($image_updated_at > $updated_at) {
$updated_at = $image_updated_at;
}
}
}
return $updated_at;
}So this function just needs to be updated to check the updated_at property of asset images when the item being checked is an episode.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | pbs_media_manager-episode-image-not-updating-3196301-4.patch | 1.64 KB | jesss |
| #3 | pbs_media_manager-episode-image-not-updating-3196301-3.patch | 1.61 KB | mekal |
Comments
Comment #2
mekal commentedComment #3
mekal commentedHere is a patch.
Comment #4
jesss commentedMy API key couldn't access the example episode, but I was able to confirm the issue with an episode from a WETA program. I've also confirmed that issue affects specials as well, so here's an updated patch with a very slight change to include them in the logic as well.
Comment #6
jesss commented