• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IGNF / validator-api / 37288971383

05 Oct 2026 09:16AM UTC coverage: 90.328% (+0.5%) from 89.794%
37288971383

push

github

floriancerizay
test(OIDC): fix testAdminRoleFromBearer

1046 of 1158 relevant lines covered (90.33%)

11.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.34
/src/Repository/ValidationRepository.php
1
<?php
2

3
namespace App\Repository;
4

5
use App\Entity\Validation;
6
use DateTime;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\ORM\Tools\Pagination\Paginator;
9
use Doctrine\Persistence\ManagerRegistry;
10
use SortDirection;
11

12
/**
13
 * @method Validation|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method Validation|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method Validation|null findOneByUid(string $uid)
16
 * @method Validation[]    findAll()
17
 * @method Validation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
18
 */
19
class ValidationRepository extends ServiceEntityRepository
20
{
21
    public function __construct(ManagerRegistry $registry)
22
    {
23
        parent::__construct($registry, Validation::class);
78 ✔
24
    }
25

26
    /**
27
     * Update next "pending" validation to "processing" and returns it.
28
     *
29
     * @return Validation|null
30
     */
31
    public function popNextPending()
32
    {
33
        $em = $this->getEntityManager();
4 ✔
34
        $conn = $em->getConnection();
4 ✔
35
        $conn->setNestTransactionsWithSavepoints(true);
4 ✔
36

37
        $conn->beginTransaction();
4 ✔
38
        try {
39
            $conn->executeQuery('LOCK TABLE validation IN ACCESS EXCLUSIVE MODE;');
4 ✔
40

41
            /** @var Validation|null $result */
42
            $result = $this->createQueryBuilder('v')
4 ✔
43
                ->where('v.status = :status')
4 ✔
44
                ->setParameter('status', Validation::STATUS_PENDING)
4 ✔
45
                ->orderBy('v.dateCreation', SortDirection::Ascending)
4 ✔
46
                ->setMaxResults(1)
4 ✔
47
                ->getQuery()
4 ✔
48
                ->getOneOrNullResult();
4 ✔
49

50
            if (!is_null($result)) {
4 ✔
51
                $result->setStatus(Validation::STATUS_PROCESSING);
3 ✔
52
                $result->setDateStart(new DateTime('now'));
3 ✔
53
                $em->flush();
3 ✔
54
                $em->refresh($result);
3 ✔
55
            }
56

57
            $conn->commit();
4 ✔
58
        } catch (\Throwable $th) {
×
59
            // release the table lock
60
            $conn->rollBack();
×
61
            throw $th;
×
62
        }
63

64
        return $result;
4 ✔
65
    }
66

67
    /**
68
     * Finds all archivable validations older than expiryDate
69
     * (validations being processed by a worker are ignored).
70
     *
71
     * @return array<Validation>
72
     */
73
    public function findAllToBeArchived(DateTime $expiryDate)
74
    {
75
        return $this->createQueryBuilder('v')
3 ✔
76
            ->where('v.dateCreation < :expiryDate')
3 ✔
77
            ->andWhere('v.status NOT IN (:ignoredStatus)')
3 ✔
78
            ->setParameter('expiryDate', $expiryDate)
3 ✔
79
            ->setParameter('ignoredStatus', [Validation::STATUS_ARCHIVED, Validation::STATUS_PROCESSING])
3 ✔
80
            ->getQuery()
3 ✔
81
            ->getResult()
3 ✔
82
        ;
3 ✔
83
    }
84

85
    /**
86
     * Finds validations still "processing" after maxDateStart (worker killed, OOM...).
87
     *
88
     * @return array<Validation>
89
     */
90
    public function findAllInterrupted(DateTime $maxDateStart)
91
    {
92
        return $this->createQueryBuilder('v')
3 ✔
93
            ->where('v.status = :status')
3 ✔
94
            ->andWhere('v.dateStart < :maxDateStart')
3 ✔
95
            ->setParameter('status', Validation::STATUS_PROCESSING)
3 ✔
96
            ->setParameter('maxDateStart', $maxDateStart)
3 ✔
97
            ->getQuery()
3 ✔
98
            ->getResult()
3 ✔
99
        ;
3 ✔
100
    }
101

102
    /**
103
     * Finds a page of validations, most recent first (see ValidationsController::listValidations).
104
     *
105
     * @return array{0: array<Validation>, 1: int} the validations and the total number of matching validations
106
     */
107
    public function findPage(int $offset, int $limit, ?string $status = null, ?string $owner = null): array
108
    {
109
        $qb = $this->createQueryBuilder('v')
3 ✔
110
            ->orderBy('v.dateCreation', SortDirection::Descending)
3 ✔
111
            ->addOrderBy('v.uid', SortDirection::Ascending)
3 ✔
112
            ->setFirstResult($offset)
3 ✔
113
            ->setMaxResults($limit);
3 ✔
114
        if (null !== $status) {
3 ✔
115
            $qb->andWhere('v.status = :status')->setParameter('status', $status);
1 ✔
116
        }
117
        if (null !== $owner) {
3 ✔
118
            $qb->andWhere('v.owner = :owner')->setParameter('owner', $owner);
2 ✔
119
        }
120
        $paginator = new Paginator($qb->getQuery(), false);
3 ✔
121

122
        return [iterator_to_array($paginator), count($paginator)];
3 ✔
123
    }
124

125
    /**
126
     * Drop schema corresponding to input validation.
127
     *
128
     * @return bool
129
     */
130
    public function dropSchema(Validation $validation)
131
    {
132
        $sql = sprintf('DROP SCHEMA IF EXISTS "validation%s" CASCADE', $validation->getUid());
8 ✔
133
        $reponse = $this->getEntityManager()->getConnection()->executeQuery($sql);
8 ✔
134

135
        return 0 != $reponse->rowCount();
8 ✔
136
    }
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc