Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Add 24.1: Cleaning up Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 13, 2022
1 parent bf30fef commit 7a34cbb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Repository/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Entity\Conference;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;

/**
Expand All @@ -16,13 +17,38 @@
*/
class CommentRepository extends ServiceEntityRepository
{
private const DAYS_BEFORE_REJECTED_REMOVAL = 7;

public const PAGINATOR_PER_PAGE = 2;

public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Comment::class);
}

public function countOldRejected(): int
{
return $this->getOldRejectedQueryBuilder()->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();
}

public function deleteOldRejected(): int
{
return $this->getOldRejectedQueryBuilder()->delete()->getQuery()->execute();
}

private function getOldRejectedQueryBuilder(): QueryBuilder
{
return $this->createQueryBuilder('c')
->andWhere('c.state = :state_rejected or c.state = :state_spam')
->andWhere('c.createdAt < :date')
->setParameters([
'state_rejected' => 'rejected',
'state_spam' => 'spam',
'date' => new \DateTimeImmutable(-self::DAYS_BEFORE_REJECTED_REMOVAL.' days'),
])
;
}

public function getCommentPaginator(Conference $conference, int $offset): Paginator
{
$query = $this->createQueryBuilder('c')
Expand Down

0 comments on commit 7a34cbb

Please sign in to comment.