[Mailer] [Mailgun] fix parsing of payload timestamp to event date value (DateTimeImmutable) in MailgunPayloadConverter #51529
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix parsing of $payload['timestamp'] in Mailer/Bridge/Mailgun/RemoteEvent/MailgunPayloadConverter.php
Details:
MailgunPayloadConverter uses
\DateTimeImmutable::createFromFormat('U.u', $payload['timestamp'])
in line 53 to convert the payload timestamp value to a DateTimeImmutable.
\DateTimeImmutable::createFromFormat expects a string as its second parameter. $payload['timestamp'] is a float.
\DateTimeImmutable::createFromFormat will try to convert a float to a string, but does not always provide a string that the function then recognizes as being in 'U.u' format.This bugfix replaces $payload['timestamp'] with sprintf('%.6F', $payload['timestamp']) in MailgunPayloadConverter, lines 53 and 54.
It also changes the timestamp in Mailer/Bridge/Mailgun/Tests/Webhook/Fixtures/delivered_messages.json to 1521472262.000002, which provides a case in which \DateTimeImmutable::createFromFormat('U.u', $payload['timestamp']) returns false (at least in my setup). Floats are replaced with strings in calls to \DateTimeImmutable::createFromFormat in Mailer/Bridge/Mailgun/Tests/Webhook/Fixtures/*.php