-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCronJobRepository.php
More file actions
55 lines (46 loc) · 1.53 KB
/
CronJobRepository.php
File metadata and controls
55 lines (46 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Shapecode\Bundle\CronBundle\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\Persistence\ManagerRegistry;
use Shapecode\Bundle\CronBundle\Collection\CronJobCollection;
use Shapecode\Bundle\CronBundle\Entity\CronJob;
/** @extends ServiceEntityRepository<CronJob> */
class CronJobRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, CronJob::class);
}
public function findOneByCommand(
string $command,
int $number = 1,
): CronJob|null {
return $this->findOneBy([
'command' => $command,
'number' => $number,
]);
}
public function findAllCollection(): CronJobCollection
{
return new CronJobCollection(...$this->findAll());
}
public function findByCommandOrId(string $commandOrId): CronJobCollection
{
$qb = $this->createQueryBuilder('p');
/** @var list<CronJob> $result */
$result = $qb
->andWhere(
$qb->expr()->orX(
'p.command = :command',
'p.id = :commandInt',
),
)
->setParameter('command', $commandOrId, Types::STRING)
->setParameter('commandInt', (int) $commandOrId, Types::INTEGER)
->getQuery()
->getResult();
return new CronJobCollection(...$result);
}
}