Replace Newsletter model with NewsletterEntity in SendingQueue

This was the easiest way to fix failing integration tests related to
updating some Sending methods to use Doctrine instead of Paris. Using
Paris in SendingQueue to update the database was creating a state where
Doctrine had stale data and this was causing the tests to fail.

[MAILPOET-4368]
This commit is contained in:
Rodrigo Primo
2023-10-20 12:02:04 -03:00
committed by Aschepikov
parent 18d34202a8
commit dc1cee5118
3 changed files with 108 additions and 21 deletions

View File

@@ -223,4 +223,36 @@ class SendingQueueEntity {
public function setNewsletter(NewsletterEntity $newsletter) {
$this->newsletter = $newsletter;
}
public function toArray(): array {
if (!$this->getTask() instanceof ScheduledTaskEntity) {
throw new \RuntimeException('Invalid state. SendingQueue has ScheduledTask associated.');
}
return [
'id' => $this->getId(),
'type' => $this->getTask()->getType(),
'status' => $this->getTask()->getStatus(),
'priority' => $this->getTask()->getPriority(),
'scheduled_at' => $this->getFormattedDateOrNull($this->getTask()->getScheduledAt()),
'processed_at' => $this->getFormattedDateOrNull($this->getTask()->getProcessedAt()),
'created_at' => $this->getFormattedDateOrNull($this->getTask()->getCreatedAt()),
'updated_at' => $this->getFormattedDateOrNull($this->getTask()->getUpdatedAt()),
'deleted_at' => $this->getFormattedDateOrNull($this->getTask()->getDeletedAt()),
'in_progress' => $this->getTask()->getInProgress(),
'reschedule_count' => $this->getTask()->getRescheduleCount(),
'meta' => $this->getMeta(),
'task_id' => $this->getTask()->getId(),
'newsletter_id' => ($this->getNewsletter() instanceof NewsletterEntity) ? $this->getNewsletter()->getId() : null,
'newsletter_rendered_body' => $this->getNewsletterRenderedBody(),
'newsletter_rendered_subject' => $this->getNewsletterRenderedSubject(),
'count_total' => $this->getCountTotal(),
'count_processed' => $this->getCountProcessed(),
'count_to_process' => $this->getCountToProcess(),
];
}
private function getFormattedDateOrNull(?\DateTimeInterface $date): ?string {
return $date ? $date->format('Y-m-d H:i:s') : null;
}
}