Move plugin files to a subfolder

[MAILPOET-3988]
This commit is contained in:
Jan Jakes
2022-01-13 14:46:43 +01:00
committed by Veljko V
parent d2016701ee
commit 9f790efbf0
3200 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace MailPoet\Subscribers;
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 $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();
}
}