1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-task library. |
5
|
|
|
* |
6
|
|
|
* (c) php-task |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Task\TaskBundle\Entity; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\EntityRepository; |
15
|
|
|
use Doctrine\ORM\NoResultException; |
16
|
|
|
use Task\Execution\TaskExecutionInterface; |
17
|
|
|
use Task\Storage\TaskExecutionRepositoryInterface; |
18
|
|
|
use Task\TaskInterface; |
19
|
|
|
use Task\TaskStatus; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Repository for task-execution. |
23
|
|
|
*/ |
24
|
|
|
class TaskExecutionRepository extends EntityRepository implements TaskExecutionRepositoryInterface |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
9 |
|
public function create(TaskInterface $task, \DateTime $scheduleTime) |
30
|
|
|
{ |
31
|
9 |
|
return new TaskExecution($task, $task->getHandlerClass(), $scheduleTime, $task->getWorkload()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
9 |
|
public function save(TaskExecutionInterface $execution) |
38
|
|
|
{ |
39
|
9 |
|
$this->_em->persist($execution); |
40
|
|
|
|
41
|
9 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function remove(TaskExecutionInterface $execution) |
48
|
|
|
{ |
49
|
|
|
$this->_em->remove($execution); |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
6 |
View Code Duplication |
public function findAll($page = 1, $pageSize = null) |
|
|
|
|
58
|
|
|
{ |
59
|
6 |
|
$query = $this->createQueryBuilder('e') |
60
|
6 |
|
->innerJoin('e.task', 't') |
61
|
6 |
|
->getQuery(); |
62
|
|
|
|
63
|
6 |
|
if ($pageSize) { |
|
|
|
|
64
|
3 |
|
$query->setMaxResults($pageSize); |
65
|
3 |
|
$query->setFirstResult(($page - 1) * $pageSize); |
66
|
3 |
|
} |
67
|
|
|
|
68
|
6 |
|
return $query->getResult(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
7 |
|
public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime) |
75
|
|
|
{ |
76
|
|
|
try { |
77
|
7 |
|
return $this->createQueryBuilder('e') |
78
|
7 |
|
->innerJoin('e.task', 't') |
79
|
7 |
|
->where('t.uuid = :uuid') |
80
|
7 |
|
->andWhere('e.scheduleTime = :scheduleTime') |
81
|
7 |
|
->setParameter('uuid', $task->getUuid()) |
82
|
7 |
|
->setParameter('scheduleTime', $scheduleTime) |
83
|
7 |
|
->getQuery() |
84
|
7 |
|
->getSingleResult(); |
85
|
7 |
|
} catch (NoResultException $e) { |
86
|
7 |
|
return; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function findByTask(TaskInterface $task) |
94
|
|
|
{ |
95
|
|
|
return $this->createQueryBuilder('e') |
96
|
|
|
->innerJoin('e.task', 't') |
97
|
|
|
->where('t.uuid = :uuid') |
98
|
|
|
->setParameter('uuid', $task->getUuid()) |
99
|
|
|
->getQuery() |
100
|
|
|
->getResult(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
2 |
|
public function findScheduled(\DateTime $dateTime = null) |
107
|
|
|
{ |
108
|
2 |
|
if ($dateTime === null) { |
109
|
2 |
|
$dateTime = new \DateTime(); |
110
|
2 |
|
} |
111
|
|
|
|
112
|
2 |
|
return $this->createQueryBuilder('e') |
113
|
2 |
|
->innerJoin('e.task', 't') |
114
|
2 |
|
->where('e.status = :status AND e.scheduleTime < :dateTime') |
115
|
2 |
|
->setParameter('status', TaskStatus::PLANNED) |
116
|
2 |
|
->setParameter('dateTime', $dateTime) |
117
|
2 |
|
->getQuery() |
118
|
2 |
|
->getResult(); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|