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

fix issue #967, re-save the html in the email_message table when updating the status from SENT to WAITING, as it's removed after sending as a space saving measure. #968

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/alfio/manager/NotificationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ public void sendTicketByEmail(Ticket ticket,

tx.execute(status -> {
emailMessageRepository.findIdByEventIdAndChecksum(event.getId(), checksum).ifPresentOrElse(
id -> emailMessageRepository.updateStatus(event.getId(), WAITING.name(), id),
// see issue #967
id -> emailMessageRepository.updateStatusToWaitingWithHtml(event.getId(), id, renderedTemplate.getHtmlPart()),
() -> emailMessageRepository.insert(event.getId(), reservation.getId(), recipient, null, subject, renderedTemplate.getTextPart(), renderedTemplate.getHtmlPart(), encodedAttachments, checksum, ZonedDateTime.now(clockProvider.getClock()))
);
return null;
Expand Down Expand Up @@ -282,7 +283,10 @@ public void sendSimpleEmail(EventAndOrganizationId event, String reservationId,
//in order to minimize the database size, it is worth checking if there is already another message in the table
Optional<Integer> existing = emailMessageRepository.findIdByEventIdAndChecksum(event.getId(), checksum);

existing.ifPresentOrElse(id -> emailMessageRepository.updateStatus(event.getId(), WAITING.name(), id),
existing.ifPresentOrElse(id ->
//see issue #967
emailMessageRepository.updateStatusToWaitingWithHtml(event.getId(), id, renderedTemplate.getHtmlPart())
,
() -> emailMessageRepository.insert(event.getId(), reservationId, recipient, encodedCC, subject, renderedTemplate.getTextPart(), renderedTemplate.getHtmlPart(), encodedAttachments, checksum, ZonedDateTime.now(clockProvider.getClock())));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/alfio/repository/EmailMessageRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ int insert(@Bind("eventId") int eventId,
@Query("update email_message set status = :status where event_id = :eventId and checksum = :checksum and status in (:expectedStatuses)")
int updateStatus(@Bind("eventId") int eventId, @Bind("checksum") String checksum, @Bind("status") String status, @Bind("expectedStatuses") List<String> expectedStatuses);

@Query("update email_message set status = :status where id = :messageId and event_id = :eventId")
int updateStatus(@Bind("eventId") int eventId, @Bind("status") String status, @Bind("messageId") int messageId);
@Query("update email_message set status = 'WAITING', html_message = :htmlMessage where id = :messageId and event_id = :eventId")
int updateStatusToWaitingWithHtml(@Bind("eventId") int eventId, @Bind("messageId") int messageId, @Bind("htmlMessage") String htmlMessage);

@Query("update email_message set status = :status, attempts = :attempts where id = :messageId and status in (:expectedStatuses) ")
int updateStatusAndAttempts(@Bind("messageId") int messageId, @Bind("status") String status, @Bind("attempts") int attempts, @Bind("expectedStatuses") List<String> expectedStatuses);
Expand Down