sendingQueuesRepository = $sendingQueuesRepository; $this->statisticsUnsubscribesRepository = $statisticsUnsubscribesRepository; $this->subscribersRepository = $subscribersRepository; } public function track( int $subscriberId, string $source, int $queueId = null, string $meta = null, string $method = StatisticsUnsubscribeEntity::METHOD_UNKNOWN ) { $queue = null; $statistics = null; if ($queueId) { $queue = $this->sendingQueuesRepository->findOneById($queueId); } $subscriber = $this->subscribersRepository->findOneById($subscriberId); if (!$subscriber instanceof SubscriberEntity) { return; } if (($queue instanceof SendingQueueEntity)) { $newsletter = $queue->getNewsletter(); if ($newsletter instanceof NewsletterEntity) { $statistics = $this->statisticsUnsubscribesRepository->findOneBy( [ 'queue' => $queue, 'newsletter' => $newsletter, 'subscriber' => $subscriber, ] ); if (!$statistics) { $statistics = new StatisticsUnsubscribeEntity($newsletter, $queue, $subscriber); } } } if ($statistics === null) { $statistics = new StatisticsUnsubscribeEntity(null, null, $subscriber); } if ($meta !== null) { $statistics->setMeta($meta); } $statistics->setSource($source); $statistics->setMethod($method); $this->statisticsUnsubscribesRepository->persist($statistics); $this->statisticsUnsubscribesRepository->flush(); } }