|
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
|
|
|
|
|
46
|
9 |
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function remove(TaskInterface $task) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->_em->remove($task); |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
5 |
View Code Duplication |
public function findAll($page = 1, $pageSize = null) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
5 |
|
$query = $this->createQueryBuilder('t') |
|
65
|
5 |
|
->getQuery(); |
|
66
|
|
|
|
|
67
|
5 |
|
if ($pageSize) { |
|
|
|
|
|
|
68
|
|
|
$query->setMaxResults($pageSize); |
|
69
|
|
|
$query->setFirstResult(($page - 1) * $pageSize); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
5 |
|
return $query->getResult(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function findEndBeforeNow() |
|
79
|
|
|
{ |
|
80
|
2 |
|
return $this->findEndBefore(new \DateTime()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Returns task where last-execution is before given date-time. |
|
85
|
|
|
* |
|
86
|
|
|
* @param \DateTime $dateTime |
|
87
|
|
|
* |
|
88
|
|
|
* @return TaskInterface[] |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public function findEndBefore(\DateTime $dateTime) |
|
91
|
|
|
{ |
|
92
|
2 |
|
return $this->createQueryBuilder('t') |
|
93
|
2 |
|
->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime') |
|
94
|
2 |
|
->setParameter('dateTime', $dateTime) |
|
95
|
2 |
|
->getQuery() |
|
96
|
2 |
|
->getResult(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|