entityManager = $entityManager; $this->wp = $wp; } public function createSendingTask(NewsletterEntity $email, SubscriberEntity $subscriber, array $meta): ScheduledTaskEntity { if (!in_array($email->getType(), [NewsletterEntity::TYPE_AUTOMATION, NewsletterEntity::TYPE_AUTOMATION_TRANSACTIONAL], true)) { throw InvalidStateException::create()->withMessage( // translators: %s is the type which was given. sprintf(__("Email with type 'automation' or 'automation_transactional' expected, '%s' given.", 'mailpoet'), $email->getType()) ); } $task = new ScheduledTaskEntity(); $task->setType(SendingQueue::TASK_TYPE); $task->setStatus(ScheduledTaskEntity::STATUS_SCHEDULED); $task->setScheduledAt(Carbon::createFromTimestamp($this->wp->currentTime('timestamp'))); $task->setPriority(ScheduledTaskEntity::PRIORITY_MEDIUM); $task->setMeta($meta); $this->entityManager->persist($task); $taskSubscriber = new ScheduledTaskSubscriberEntity($task, $subscriber); $this->entityManager->persist($taskSubscriber); $queue = new SendingQueueEntity(); $queue->setTask($task); $queue->setMeta($meta); $queue->setNewsletter($email); $queue->setCountToProcess(1); $queue->setCountTotal(1); $this->entityManager->persist($queue); $this->entityManager->flush(); return $task; } }