repository = $repository; } public function getInconsistentDataStatus(): array { $result = [ self::ORPHANED_SENDING_TASKS => $this->repository->getOrphanedSendingTasksCount(), self::ORPHANED_SENDING_TASK_SUBSCRIBERS => $this->repository->getOrphanedScheduledTasksSubscribersCount(), self::SENDING_QUEUE_WITHOUT_NEWSLETTER => $this->repository->getSendingQueuesWithoutNewsletterCount(), self::ORPHANED_SUBSCRIPTIONS => $this->repository->getOrphanedSubscriptionsCount(), self::ORPHANED_LINKS => $this->repository->getOrphanedNewsletterLinksCount(), self::ORPHANED_NEWSLETTER_POSTS => $this->repository->getOrphanedNewsletterPostsCount(), ]; $result['total'] = array_sum($result); return $result; } public function fixInconsistentData(string $inconsistency): void { if (!in_array($inconsistency, self::SUPPORTED_INCONSISTENCY_CHECKS, true)) { throw new UnexpectedValueException(__('Unsupported data inconsistency check.', 'mailpoet')); } if ($inconsistency === self::ORPHANED_SENDING_TASKS) { $this->repository->cleanupOrphanedSendingTasks(); } elseif ($inconsistency === self::ORPHANED_SENDING_TASK_SUBSCRIBERS) { $this->repository->cleanupOrphanedScheduledTaskSubscribers(); } elseif ($inconsistency === self::SENDING_QUEUE_WITHOUT_NEWSLETTER) { $this->repository->cleanupSendingQueuesWithoutNewsletter(); } elseif ($inconsistency === self::ORPHANED_SUBSCRIPTIONS) { $this->repository->cleanupOrphanedSubscriptions(); } elseif ($inconsistency === self::ORPHANED_LINKS) { $this->repository->cleanupOrphanedNewsletterLinks(); } elseif ($inconsistency === self::ORPHANED_NEWSLETTER_POSTS) { $this->repository->cleanupOrphanedNewsletterPosts(); } } }