Delete also stats notification scheduled tasks when deleting a newsletter
[MAILPOET-3015]
This commit is contained in:
committed by
Veljko V
parent
05eee7bcfa
commit
aaf38a6f96
@@ -253,15 +253,26 @@ class NewslettersRepository extends Repository {
|
|||||||
WHERE nl.`newsletter_id` IN (:ids)
|
WHERE nl.`newsletter_id` IN (:ids)
|
||||||
", ['ids' => $ids], ['ids' => Connection::PARAM_INT_ARRAY]);
|
", ['ids' => $ids], ['ids' => Connection::PARAM_INT_ARRAY]);
|
||||||
|
|
||||||
// Delete stats notifications
|
// Delete stats notifications tasks
|
||||||
|
$scheduledTasksTable = $entityManager->getClassMetadata(ScheduledTaskEntity::class)->getTableName();
|
||||||
$statsNotificationsTable = $entityManager->getClassMetadata(StatsNotificationEntity::class)->getTableName();
|
$statsNotificationsTable = $entityManager->getClassMetadata(StatsNotificationEntity::class)->getTableName();
|
||||||
|
$taskIds = $entityManager->getConnection()->executeQuery("
|
||||||
|
SELECT task_id FROM $statsNotificationsTable sn
|
||||||
|
WHERE sn.`newsletter_id` IN (:ids)
|
||||||
|
", ['ids' => $ids], ['ids' => Connection::PARAM_INT_ARRAY])->fetchAll();
|
||||||
|
$taskIds = array_column($taskIds, 'task_id');
|
||||||
|
$entityManager->getConnection()->executeUpdate("
|
||||||
|
DELETE st FROM $scheduledTasksTable st
|
||||||
|
WHERE st.`id` IN (:ids)
|
||||||
|
", ['ids' => $taskIds], ['ids' => Connection::PARAM_INT_ARRAY]);
|
||||||
|
|
||||||
|
// Delete stats notifications
|
||||||
$entityManager->getConnection()->executeUpdate("
|
$entityManager->getConnection()->executeUpdate("
|
||||||
DELETE sn FROM $statsNotificationsTable sn
|
DELETE sn FROM $statsNotificationsTable sn
|
||||||
WHERE sn.`newsletter_id` IN (:ids)
|
WHERE sn.`newsletter_id` IN (:ids)
|
||||||
", ['ids' => $ids], ['ids' => Connection::PARAM_INT_ARRAY]);
|
", ['ids' => $ids], ['ids' => Connection::PARAM_INT_ARRAY]);
|
||||||
|
|
||||||
// Delete scheduled tasks and scheduled task subscribers
|
// Delete scheduled tasks and scheduled task subscribers
|
||||||
$scheduledTasksTable = $entityManager->getClassMetadata(ScheduledTaskEntity::class)->getTableName();
|
|
||||||
$sendingQueueTable = $entityManager->getClassMetadata(SendingQueueEntity::class)->getTableName();
|
$sendingQueueTable = $entityManager->getClassMetadata(SendingQueueEntity::class)->getTableName();
|
||||||
$scheduledTaskSubscribersTable = $entityManager->getClassMetadata(ScheduledTaskSubscriberEntity::class)->getTableName();
|
$scheduledTaskSubscribersTable = $entityManager->getClassMetadata(ScheduledTaskSubscriberEntity::class)->getTableName();
|
||||||
|
|
||||||
|
@@ -137,8 +137,12 @@ class NewsletterRepositoryTest extends \MailPoetTest {
|
|||||||
assert($notificationHistorySegment instanceof NewsletterSegmentEntity);
|
assert($notificationHistorySegment instanceof NewsletterSegmentEntity);
|
||||||
$notificationHistoryScheduledTaskSubscriber = $this->taskSubscribersRepository->findOneBy(['task' => $notificationHistoryScheduledTask]);
|
$notificationHistoryScheduledTaskSubscriber = $this->taskSubscribersRepository->findOneBy(['task' => $notificationHistoryScheduledTask]);
|
||||||
assert($notificationHistoryScheduledTaskSubscriber instanceof ScheduledTaskSubscriberEntity);
|
assert($notificationHistoryScheduledTaskSubscriber instanceof ScheduledTaskSubscriberEntity);
|
||||||
$standardStatsNotification = $this->createStatNotification($standardNewsletter, $standardScheduledTaks);
|
$standardStatsNotification = $this->createStatNotification($standardNewsletter);
|
||||||
$notificationHistoryStatsNotification = $this->createStatNotification($notificationHistory, $notificationHistoryScheduledTask);
|
$standardStatsNotificationScheduledTask = $standardStatsNotification->getTask();
|
||||||
|
assert($standardStatsNotificationScheduledTask instanceof ScheduledTaskEntity);
|
||||||
|
$notificationHistoryStatsNotification = $this->createStatNotification($notificationHistory);
|
||||||
|
$notificationHistoryStatsNotificationScheduledTask = $notificationHistoryStatsNotification->getTask();
|
||||||
|
assert($notificationHistoryStatsNotificationScheduledTask instanceof ScheduledTaskEntity);
|
||||||
$standardLink = $this->createNewsletterLink($standardNewsletter, $standardQueue);
|
$standardLink = $this->createNewsletterLink($standardNewsletter, $standardQueue);
|
||||||
$notificationHistoryLink = $this->createNewsletterLink($notificationHistory, $notificationHistoryQueue);
|
$notificationHistoryLink = $this->createNewsletterLink($notificationHistory, $notificationHistoryQueue);
|
||||||
$optionField = $this->createNewsletterOptionField(NewsletterEntity::TYPE_NOTIFICATION, 'option');
|
$optionField = $this->createNewsletterOptionField(NewsletterEntity::TYPE_NOTIFICATION, 'option');
|
||||||
@@ -168,7 +172,9 @@ class NewsletterRepositoryTest extends \MailPoetTest {
|
|||||||
$this->entityManager->detach($standardSegment);
|
$this->entityManager->detach($standardSegment);
|
||||||
$this->entityManager->detach($notificationHistorySegment);
|
$this->entityManager->detach($notificationHistorySegment);
|
||||||
$this->entityManager->detach($standardStatsNotification);
|
$this->entityManager->detach($standardStatsNotification);
|
||||||
|
$this->entityManager->detach($standardStatsNotificationScheduledTask);
|
||||||
$this->entityManager->detach($notificationHistoryStatsNotification);
|
$this->entityManager->detach($notificationHistoryStatsNotification);
|
||||||
|
$this->entityManager->detach($notificationHistoryStatsNotificationScheduledTask);
|
||||||
$this->entityManager->detach($standardLink);
|
$this->entityManager->detach($standardLink);
|
||||||
$this->entityManager->detach($notificationHistoryLink);
|
$this->entityManager->detach($notificationHistoryLink);
|
||||||
$this->entityManager->detach($optionValue);
|
$this->entityManager->detach($optionValue);
|
||||||
@@ -201,9 +207,13 @@ class NewsletterRepositoryTest extends \MailPoetTest {
|
|||||||
expect($this->entityManager->find(NewsletterSegmentEntity::class, $notificationHistorySegment->getId()))->null();
|
expect($this->entityManager->find(NewsletterSegmentEntity::class, $notificationHistorySegment->getId()))->null();
|
||||||
|
|
||||||
// Newsletter stats notifications
|
// Newsletter stats notifications
|
||||||
expect($this->entityManager->find(StatsNotificationEntity::class, $standardStatsNotification->getId()))->null();
|
expect($this->entityManager->find(StatsNotificationEntity::class, $standardStatsNotificationScheduledTask->getId()))->null();
|
||||||
expect($this->entityManager->find(StatsNotificationEntity::class, $notificationHistoryStatsNotification->getId()))->null();
|
expect($this->entityManager->find(StatsNotificationEntity::class, $notificationHistoryStatsNotification->getId()))->null();
|
||||||
|
|
||||||
|
// Newsletter stats notifications scheduled tasks
|
||||||
|
expect($this->entityManager->find(ScheduledTaskEntity::class, $standardStatsNotificationScheduledTask->getId()))->null();
|
||||||
|
expect($this->entityManager->find(ScheduledTaskEntity::class, $notificationHistoryStatsNotificationScheduledTask->getId()))->null();
|
||||||
|
|
||||||
// Newsletter links
|
// Newsletter links
|
||||||
expect($this->entityManager->find(NewsletterLinkEntity::class, $standardLink->getId()))->null();
|
expect($this->entityManager->find(NewsletterLinkEntity::class, $standardLink->getId()))->null();
|
||||||
expect($this->entityManager->find(NewsletterLinkEntity::class, $notificationHistoryLink->getId()))->null();
|
expect($this->entityManager->find(NewsletterLinkEntity::class, $notificationHistoryLink->getId()))->null();
|
||||||
@@ -270,7 +280,11 @@ class NewsletterRepositoryTest extends \MailPoetTest {
|
|||||||
return $queue;
|
return $queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createStatNotification(NewsletterEntity $newsletter, ScheduledTaskEntity $task): StatsNotificationEntity {
|
private function createStatNotification(NewsletterEntity $newsletter): StatsNotificationEntity {
|
||||||
|
$task = new ScheduledTaskEntity();
|
||||||
|
$task->setType('stats_notification');
|
||||||
|
$task->setStatus(ScheduledTaskEntity::STATUS_SCHEDULED);
|
||||||
|
$this->entityManager->persist($task);
|
||||||
$statsNotification = new StatsNotificationEntity($newsletter, $task);
|
$statsNotification = new StatsNotificationEntity($newsletter, $task);
|
||||||
$this->entityManager->persist($statsNotification);
|
$this->entityManager->persist($statsNotification);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
Reference in New Issue
Block a user