HEX
Server: Apache/2
System: Linux s01 6.1.0-34-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.135-1 (2025-04-25) x86_64
User: beestg (1003)
PHP: 8.3.25
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/beestg/public_html/wp-content/plugins/mailpoet/lib/Subscribers/SubscriberIPsRepository.php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

namespace MailPoet\Subscribers;

if (!defined('ABSPATH')) exit;


use MailPoet\Doctrine\Repository;
use MailPoet\Entities\SubscriberIPEntity;
use MailPoetVendor\Carbon\Carbon;

/**
 * @extends Repository<SubscriberIPEntity>
 */
class SubscriberIPsRepository extends Repository {
  protected function getEntityClassName() {
    return SubscriberIPEntity::class;
  }

  public function findOneByIPAndCreatedAtAfterTimeInSeconds(string $ip, int $seconds): ?SubscriberIPEntity {
    return $this->entityManager->createQueryBuilder()
      ->select('sip')
      ->from(SubscriberIPEntity::class, 'sip')
      ->where('sip.ip = :ip')
      ->andWhere('sip.createdAt >= :timeThreshold')
      ->setParameter('ip', $ip)
      ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds))
      ->setMaxResults(1)
      ->getQuery()
      ->getOneOrNullResult();
  }

  public function getCountByIPAndCreatedAtAfterTimeInSeconds(string $ip, int $seconds): int {
    return (int)$this->entityManager->createQueryBuilder()
      ->select('COUNT(sip)')
      ->from(SubscriberIPEntity::class, 'sip')
      ->where('sip.ip = :ip')
      ->andWhere('sip.createdAt >= :timeThreshold')
      ->setParameter('ip', $ip)
      ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds))
      ->getQuery()
      ->getSingleScalarResult();
  }

  public function deleteCreatedAtBeforeTimeInSeconds(int $seconds): int {
    return (int)$this->entityManager->createQueryBuilder()
      ->delete()
      ->from(SubscriberIPEntity::class, 'sip')
      ->where('sip.createdAt < :timeThreshold')
      ->setParameter('timeThreshold', (new Carbon())->subSeconds($seconds))
      ->getQuery()
      ->execute();
  }
}