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

Hotfix/display 1019 feed errors #166

Merged
merged 12 commits into from
Oct 13, 2023
Merged

Conversation

tuj
Copy link
Contributor

@tuj tuj commented Oct 11, 2023

Link to ticket

https://jira.itkdev.dk/browse/DISPLAY-1019

Description

  • Wrapped feeds in try-catch to avoid throw errors.
  • Added unpublished flow to EventDatabase feed when occurrence returns 404.
  • Fixed EventDatabase feed poster subscription parameters not being applied when calling getData().

Checklist

  • My code is covered by test cases.
  • My code passes our test (all our tests).
  • My code passes our static analysis suite.
  • My code passes our continuous integration process.

@tuj tuj changed the base branch from develop to main October 11, 2023 17:33
@tuj tuj requested a review from rimi-itk October 11, 2023 17:34
Copy link
Contributor

@rimi-itk rimi-itk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. However, we should use placeholders in log messages, cf. https://symfony.com/doc/5.4/logging.html#logging-a-message.

CHANGELOG.md Outdated Show resolved Hide resolved
}
} catch (\Throwable $throwable) {
// If the content does not exist anymore, unpublished the slide.
if ($throwable instanceof ClientException && 404 == $throwable->getCode()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($throwable instanceof ClientException && 404 == $throwable->getCode()) {
if ($throwable instanceof ClientException && Response::HTTP_NOT_FOUND == $throwable->getCode()) {

(cf. https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/HttpFoundation/Response.php#L51)

// If the content does not exist anymore, unpublished the slide.
if ($throwable instanceof ClientException && 404 == $throwable->getCode()) {
try {
$this->logger->info('Feed with id: '.$feed->getId().' depends on an item that does not exist in Event Database. Unpublished slide with id: '.$feed->getSlide()->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use placeholders in the log message: https://symfony.com/doc/5.4/logging.html#logging-a-message

And probably move the logging to after unpublishing the slide (cf. “Unpublished …” (past tense)).

if ($throwable instanceof ClientException && 404 == $throwable->getCode()) {
try {
$this->logger->info('Feed with id: '.$feed->getId().' depends on an item that does not exist in Event Database. Unpublished slide with id: '.$feed->getSlide()->getId());
$feed->getSlide()->setPublishedTo(new \DateTime('now', new \DateTimeZone('UTC')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this unpublish a slide? To the untrained eye, it seems to publish a slide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.
A slide has publishedFrom, publishedTo. By setting publishedTo to now, the slide becomes unpublished.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the “To” had escaped my untrained eye …

$feed->getSlide()->setPublishedTo(new \DateTime('now', new \DateTimeZone('UTC')));
$this->entityManager->flush();
} catch (\Exception $exception) {
$this->logger->error($exception->getCode().': '.$exception->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use message placeholders.

$this->logger->error($exception->getCode().': '.$exception->getMessage());
}
} else {
$this->logger->error($throwable->getCode().': '.$throwable->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use message placeholders.

return $result;
}
} catch (\Throwable $throwable) {
$this->logger->error($throwable->getCode().': '.$throwable->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use message placeholders.

@tuj tuj requested a review from rimi-itk October 12, 2023 10:21
Copy link
Contributor

@rimi-itk rimi-itk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final fly fornication!

Comment on lines 58 to 60
'occurrences.place.id' => array_map(function ($place) { return str_replace('/api/places/', '', $place['value']); }, $places),
'organizer.id' => array_map(function ($organizer) { return str_replace('/api/organizers/', '', $organizer['value']); }, $organizers),
'tags' => array_map(function ($tag) { return str_replace('/api/tags/', '', $tag['value']); }, $tags),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.php.net/manual/en/functions.arrow.php are designed for this. Consider using them, i.e.

Suggested change
'occurrences.place.id' => array_map(function ($place) { return str_replace('/api/places/', '', $place['value']); }, $places),
'organizer.id' => array_map(function ($organizer) { return str_replace('/api/organizers/', '', $organizer['value']); }, $organizers),
'tags' => array_map(function ($tag) { return str_replace('/api/tags/', '', $tag['value']); }, $tags),
'occurrences.place.id' => array_map(static fn($place) => str_replace('/api/places/', '', $place['value']), $places),
'organizer.id' => array_map(static fn($organizer) => str_replace('/api/organizers/', '', $organizer['value']), $organizers),
'tags' => array_map(static fn($tag) => str_replace('/api/tags/', '', $tag['value']), $tags),

@tuj tuj requested a review from rimi-itk October 12, 2023 11:15
@tuj tuj changed the base branch from main to develop October 12, 2023 18:45
@tuj tuj merged commit 144cc54 into develop Oct 13, 2023
@tuj tuj deleted the hotfix/display-1019-feed-errors branch October 13, 2023 04:39
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.

2 participants