Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

rasben
Copy link
Contributor

@rasben rasben commented Sep 18, 2024

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

@github-actions github-actions bot temporarily deployed to pr-1584 September 18, 2024 08:43 Destroyed
@github-actions github-actions bot temporarily deployed to pr-1584 September 18, 2024 08:45 Destroyed
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.
@github-actions github-actions bot temporarily deployed to pr-1584 September 18, 2024 08:51 Destroyed
Copy link
Contributor

@kasperg kasperg left a 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.

config/sync/core.extension.yml Show resolved Hide resolved
'id' => $event->id(),
'date' => $changed_date->format('r'),
'promoted' => FALSE,
'subtitle' => $event->get('event_description')->getString(),
Copy link
Contributor

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.

Comment on lines 85 to 101
$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,
],
];
Copy link
Contributor

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.

Comment on lines +114 to +139
$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;
}
Copy link
Contributor

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.

Comment on lines +52 to +55
$response = new Response();
$response->setContent($rss_content);
$response->headers->set('Content-Type', 'application/rss+xml');
return $response;
Copy link
Contributor

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.

config/sync/image.style.redia_feed_large.yml Show resolved Hide resolved
@kasperg kasperg assigned rasben and unassigned kasperg, xendk and kasperbirch1 Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants