1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00
wallabag/src/Repository/EntryDeletionRepository.php

58 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Pagerfanta\Doctrine\ORM\QueryAdapter as DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use Wallabag\Entity\EntryDeletion;
class EntryDeletionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EntryDeletion::class);
}
/**
* Find deletions for a specific user since a given date. The result is paginated.
*/
2025-06-04 11:36:44 +02:00
public function findEntryDeletions(int $userId, int $since = 0, string $order = 'asc'): Pagerfanta
{
$qb = $this->createQueryBuilder('de')
->where('de.user = :userId')->setParameter('userId', $userId)
->orderBy('de.deletedAt', $order);
if ($since > 0) {
$qb->andWhere('de.deletedAt >= :since')
->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since)));
}
$pagerAdapter = new DoctrineORMAdapter($qb, true, false);
$pager = new Pagerfanta($pagerAdapter);
return $pager;
}
public function countAllBefore(\DateTime $date): int
{
return $this->createQueryBuilder('de')
->select('COUNT(de.id)')
->where('de.deletedAt < :date')
->setParameter('date', $date)
->getQuery()
->getSingleScalarResult();
}
public function deleteAllBefore(\DateTime $date)
{
$this->createQueryBuilder('de')
->delete()
->where('de.deletedAt < :date')
->setParameter('date', $date)
->getQuery()
->execute();
}
}