-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathJobRunRepository.php
More file actions
90 lines (74 loc) · 3.14 KB
/
JobRunRepository.php
File metadata and controls
90 lines (74 loc) · 3.14 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/
namespace Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Repository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Pimcore\Bundle\GenericExecutionEngineBundle\Entity\JobRun;
use Pimcore\Bundle\StudioBackendBundle\Entity\ExecutionEngine\JobRunHidden;
use Pimcore\Bundle\StudioBackendBundle\Filter\MappedParameter\FilterParameter;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionFilterParameter;
/**
* @internal
*/
final readonly class JobRunRepository implements JobRunRepositoryInterface
{
public function __construct(
private EntityManagerInterface $entityManager
) {
}
public function update(JobRunHidden $jobRunHidden): void
{
$existingEntry = $this->getByJobRunId($jobRunHidden->getJobRunId());
if ($existingEntry !== null) {
return;
}
$this->entityManager->persist($jobRunHidden);
$this->entityManager->flush();
}
public function getByJobRunId(int $jobRunId): ?JobRunHidden
{
return $this->entityManager->getRepository(JobRunHidden::class)
->findOneBy(['jobRunId' => $jobRunId]);
}
public function getStudioJobRuns(int $ownerId, CollectionFilterParameter $parameter): Paginator
{
$qb = $this->entityManager
->getRepository(JobRun::class)
->createQueryBuilder('jr')
->leftJoin(JobRunHidden::class, 'jrh', 'WITH', 'jr.id = jrh.jobRunId')
->where('jrh.jobRunId IS NULL');
// Add owner condition
$qb->andWhere('jr.ownerId = :ownerId')
->setParameter('ownerId', $ownerId);
$filters = $parameter->getFilters() ?? new FilterParameter();
$qb->setFirstResult($filters->getStart());
$qb->setMaxResults($filters->getPageSize());
$this->applyFilter($parameter, $qb);
$qb->orderBy(
'jr.'.$filters->getSortFilter()->getKey(),
$filters->getSortFilter()->getDirection());
// Add execution contexts condition
$qb->andWhere('jr.executionContext IN (:executionContexts)')
->setParameter('executionContexts', ['studio_stop_on_error', 'studio_continue_on_error']);
return new Paginator($qb, fetchJoinCollection: true);
}
private function applyFilter(CollectionFilterParameter $parameter, QueryBuilder $queryBuilder): void
{
if ($filter = $parameter->getFilters()->getSimpleColumnFilterByType('state')) {
$queryBuilder->andWhere('jr.state = :state')->setParameter('state', $filter->getFilterValue());
}
if ($filter = $parameter->getFilters()->getSimpleColumnFilterByType('id')) {
$queryBuilder->andWhere('jr.id = :id')->setParameter('id', $filter->getFilterValue());
}
}
}