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 Task\Storage\TaskRepositoryInterface; |
16
|
|
|
use Task\TaskInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Repository for task. |
20
|
|
|
*/ |
21
|
|
|
class TaskRepository extends EntityRepository implements TaskRepositoryInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
9 |
|
public function create($handlerClass, $workload = null) |
27
|
|
|
{ |
28
|
9 |
|
return new Task($handlerClass, $workload); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function findByUuid($uuid) |
35
|
|
|
{ |
36
|
|
|
return $this->find($uuid); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
9 |
|
public function save(TaskInterface $task) |
43
|
|
|
{ |
44
|
9 |
|
$this->_em->persist($task); |
45
|
9 |
|
$this->_em->flush($task); |
46
|
|
|
|
47
|
9 |
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
|
public function remove(TaskInterface $task) |
54
|
|
|
{ |
55
|
|
|
$this->_em->remove($task); |
56
|
|
|
$this->_em->flush($task); |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
5 |
View Code Duplication |
public function findAll($page = 1, $pageSize = null) |
|
|
|
|
65
|
|
|
{ |
66
|
5 |
|
$query = $this->createQueryBuilder('t') |
67
|
5 |
|
->getQuery(); |
68
|
|
|
|
69
|
5 |
|
if ($pageSize) { |
|
|
|
|
70
|
|
|
$query->setMaxResults($pageSize); |
71
|
|
|
$query->setFirstResult(($page - 1) * $pageSize); |
72
|
|
|
} |
73
|
|
|
|
74
|
5 |
|
return $query->getResult(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
2 |
|
public function findEndBeforeNow() |
81
|
|
|
{ |
82
|
2 |
|
return $this->findEndBefore(new \DateTime()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns task where last-execution is before given date-time. |
87
|
|
|
* |
88
|
|
|
* @param \DateTime $dateTime |
89
|
|
|
* |
90
|
|
|
* @return TaskInterface[] |
91
|
|
|
*/ |
92
|
2 |
|
public function findEndBefore(\DateTime $dateTime) |
93
|
|
|
{ |
94
|
2 |
|
return $this->createQueryBuilder('t') |
95
|
2 |
|
->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime') |
96
|
2 |
|
->setParameter('dateTime', $dateTime) |
97
|
2 |
|
->getQuery() |
98
|
2 |
|
->getResult(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|