Skip to content

Commit 7c07bd2

Browse files
committed
incrementViews
1 parent 4785567 commit 7c07bd2

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/Domain/Analytics/Service/UserMessageService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\ORM\EntityManagerInterface;
88
use PhpList\Core\Domain\Analytics\Model\UserMessageView;
9+
use PhpList\Core\Domain\Messaging\Model\Message\MessageStatus;
910
use PhpList\Core\Domain\Messaging\Repository\MessageRepository;
1011
use PhpList\Core\Domain\Messaging\Repository\UserMessageRepository;
1112
use PhpList\Core\Domain\Subscription\Repository\SubscriberRepository;
@@ -23,7 +24,7 @@ public function __construct(
2324
public function trackUserMessageView(string $uid, int $messageId, array $metadata): void
2425
{
2526
$subscriber = $this->subscriberRepository->findOneByUniqueId($uid);
26-
$message = $this->messageRepository->find($messageId);
27+
$message = $this->messageRepository->findById($messageId);
2728

2829
if ($subscriber === null || $message === null) {
2930
return;
@@ -35,7 +36,7 @@ public function trackUserMessageView(string $uid, int $messageId, array $metadat
3536
}
3637

3738
$userMessage->setViewedNow();
38-
$message->incrementViews();
39+
$message->getMetadata()->incrementViews();
3940

4041
$data = [];
4142
foreach (['HTTP_USER_AGENT', 'HTTP_REFERER'] as $key) {

src/Domain/Messaging/Model/Message/MessageMetadata.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function setViews(int $viewed): self
8181
return $this;
8282
}
8383

84+
public function incrementViews(): self
85+
{
86+
$this->viewed += 1;
87+
88+
return $this;
89+
}
90+
8491
public function getViews(): int
8592
{
8693
return $this->viewed;

src/Domain/Messaging/Repository/MessageRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function findCampaignsWithoutUuid(): array
2727
->getResult();
2828
}
2929

30+
/** @return Message[] */
3031
public function getByOwnerId(int $ownerId): array
3132
{
3233
return $this->createQueryBuilder('m')
@@ -36,6 +37,15 @@ public function getByOwnerId(int $ownerId): array
3637
->getResult();
3738
}
3839

40+
public function findById(int $id): ?Message
41+
{
42+
return $this->createQueryBuilder('m')
43+
->where('m.id = :id')
44+
->setParameter('id', $id)
45+
->getQuery()
46+
->getOneOrNullResult();
47+
}
48+
3949
/** @return Message[] */
4050
public function getFilteredAfterId(int $lastId, int $limit, ?FilterRequestInterface $filter = null): array
4151
{

0 commit comments

Comments
 (0)