ConfirmationEmailTemplate
1 month ago
ImportExport
2 weeks ago
RestApi
3 days ago
Statistics
1 month ago
BulkActionController.php
3 days ago
BulkActionException.php
1 month ago
BulkConfirmationEmailResender.php
2 months ago
ConfirmationEmailCustomizer.php
2 months ago
ConfirmationEmailMailer.php
2 months ago
ConfirmationEmailResolver.php
2 months ago
EngagementDataBackfiller.php
2 months ago
InactiveSubscribersController.php
5 days ago
LinkTokens.php
2 months ago
NewSubscriberNotificationMailer.php
2 months ago
RequiredCustomFieldValidator.php
2 months ago
SegmentsCountRecalculator.php
2 weeks ago
Source.php
2 months ago
SubscriberActions.php
2 months ago
SubscriberCustomFieldRepository.php
3 years ago
SubscriberIPsRepository.php
2 years ago
SubscriberLimitNotificationEvaluator.php
2 months ago
SubscriberLimitNotificationMailer.php
2 months ago
SubscriberLimitNotificationScheduler.php
2 months ago
SubscriberListingRepository.php
2 weeks ago
SubscriberPersonalDataEraser.php
2 months ago
SubscriberSaveController.php
3 days ago
SubscriberSegmentRepository.php
2 weeks ago
SubscriberSubscribeController.php
2 weeks ago
SubscriberTagRepository.php
4 years ago
SubscribersCountsController.php
2 weeks ago
SubscribersEmailCountsController.php
2 weeks ago
SubscribersRepository.php
3 days ago
TrackingConsentController.php
5 days ago
index.php
3 years ago
SubscriberIPsRepository.php
55 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Subscribers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Doctrine\Repository; |
| 9 | use MailPoet\Entities\SubscriberIPEntity; |
| 10 | use MailPoetVendor\Carbon\Carbon; |
| 11 | |
| 12 | /** |
| 13 | * @extends Repository<SubscriberIPEntity> |
| 14 | */ |
| 15 | class SubscriberIPsRepository extends Repository { |
| 16 | protected function getEntityClassName() { |
| 17 | return SubscriberIPEntity::class; |
| 18 | } |
| 19 | |
| 20 | public function findOneByIPAndCreatedAtAfterTimeInSeconds(string $ip, int $seconds): ?SubscriberIPEntity { |
| 21 | return $this->entityManager->createQueryBuilder() |
| 22 | ->select('sip') |
| 23 | ->from(SubscriberIPEntity::class, 'sip') |
| 24 | ->where('sip.ip = :ip') |
| 25 | ->andWhere('sip.createdAt >= :timeThreshold') |
| 26 | ->setParameter('ip', $ip) |
| 27 | ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds)) |
| 28 | ->setMaxResults(1) |
| 29 | ->getQuery() |
| 30 | ->getOneOrNullResult(); |
| 31 | } |
| 32 | |
| 33 | public function getCountByIPAndCreatedAtAfterTimeInSeconds(string $ip, int $seconds): int { |
| 34 | return (int)$this->entityManager->createQueryBuilder() |
| 35 | ->select('COUNT(sip)') |
| 36 | ->from(SubscriberIPEntity::class, 'sip') |
| 37 | ->where('sip.ip = :ip') |
| 38 | ->andWhere('sip.createdAt >= :timeThreshold') |
| 39 | ->setParameter('ip', $ip) |
| 40 | ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds)) |
| 41 | ->getQuery() |
| 42 | ->getSingleScalarResult(); |
| 43 | } |
| 44 | |
| 45 | public function deleteCreatedAtBeforeTimeInSeconds(int $seconds): int { |
| 46 | return (int)$this->entityManager->createQueryBuilder() |
| 47 | ->delete() |
| 48 | ->from(SubscriberIPEntity::class, 'sip') |
| 49 | ->where('sip.createdAt < :timeThreshold') |
| 50 | ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds)) |
| 51 | ->getQuery() |
| 52 | ->execute(); |
| 53 | } |
| 54 | } |
| 55 |