-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating a legacy Redia RSS feed for events. DDFHER-60 #1584
base: develop
Are you sure you want to change the base?
Conversation
0b99bf6
to
a3ae90e
Compare
This feed is needed for some legacy apps to continue working. It will not be updated in the future - rather, this is a 1-1 recreation of the old feed. As I've made a custom redia legacy module, i've also moved the legacy opening hours REST api into this module.
a3ae90e
to
79168fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of code, lots of comments here 😅 .
I think it is a good idea to create a separate module for the legacy integrations and as I see it you have managed to recreate the feed 1-1 compared to the original.
There are a couple of places where we disagree on the overall code structure:
- I would like to see the
EventWrapper
used more. - I would prefer more proper objects and less arrays and strings.
web/modules/custom/dpl_redia_legacy/src/Controller/RssFeeds/EventsController.php
Outdated
Show resolved
Hide resolved
web/modules/custom/dpl_redia_legacy/src/Controller/RssFeeds/EventsController.php
Outdated
Show resolved
Hide resolved
'id' => $event->id(), | ||
'date' => $changed_date->format('r'), | ||
'promoted' => FALSE, | ||
'subtitle' => $event->get('event_description')->getString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing. Our event instances have a description
field. This controller also has an getEventDescription()
function.
I think I understand why this is needed but the current state of the code does not help me much.
$items[] = [ | ||
'title' => $event->label(), | ||
'description' => $this->getEventDescription($event), | ||
'author' => $event->getOwner()->get('field_author_name')->getString(), | ||
'id' => $event->id(), | ||
'date' => $changed_date->format('r'), | ||
'promoted' => FALSE, | ||
'subtitle' => $event->get('event_description')->getString(), | ||
'start_time' => $event_dates[0]['value'] ?? NULL, | ||
'end_time' => $event_dates[0]['end_value'] ?? NULL, | ||
'media' => $this->getEventImageFields($event, 'redia_feed_large'), | ||
'media_thumbnail' => $this->getEventImageFields($event, 'redia_feed_small'), | ||
'branch' => [ | ||
'label' => $branch ? $branch->label() : NULL, | ||
'id' => $branch ? $branch->id() : NULL, | ||
], | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing these array structures with value objects.
The current approach makes it hard to ensure the validity of the datastructure.
$media_field = $event->get('event_image'); | ||
|
||
if (!($media_field instanceof FieldItemListInterface)) { | ||
return NULL; | ||
} | ||
|
||
$media = $media_field->referencedEntities()[0] ?? NULL; | ||
$file_field_name = 'field_media_image'; | ||
|
||
if (!($media instanceof MediaInterface) || !$media->hasField($file_field_name)) { | ||
return NULL; | ||
} | ||
|
||
// @phpstan-ignore-next-line PHPStan does not know that entity is available. | ||
$file = $media->get($file_field_name)->first()?->entity; | ||
|
||
if (!($file instanceof FileInterface)) { | ||
return NULL; | ||
} | ||
|
||
$file_uri = $file->getFileUri(); | ||
$style = $this->entityTypeManager()->getStorage('image_style')->load($image_style); | ||
|
||
if (empty($file_uri) || !($style instanceof ImageStyleInterface)) { | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving (some of) this logic to the EventWrapper
.
$response = new Response(); | ||
$response->setContent($rss_content); | ||
$response->headers->set('Content-Type', 'application/rss+xml'); | ||
return $response; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this to return a cacheable response.
I do not know how often the feed is requested but I do not see a reason why we should not be able to cache it in Varnish.
This feed is needed for some legacy apps to continue working. It will not be updated in the future - rather, this is a 1-1 recreation of the old feed.
As I've made a custom redia legacy module, i've also moved the legacy opening hours REST api into this module.
Link to issue
https://reload.atlassian.net/browse/DDFHER-60
Old feed:
https://www.aakb.dk/ding-redia-rss/event
New feed:
https://varnish.pr-1584.dpl-cms.dplplat01.dpl.reload.dk/ding-redia-rss/event