1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Task\TaskBundle\DoctrineStorage; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
6
|
|
|
use Task\Execution\TaskExecutionInterface; |
7
|
|
|
use Task\Execution\TaskExecutionRepositoryInterface; |
8
|
|
|
use Task\TaskBundle\Entity\TaskExecutionRepository as ORMTaskExecutionRepository; |
9
|
|
|
use Task\TaskInterface; |
10
|
|
|
|
11
|
|
|
class TaskExecutionRepository implements TaskExecutionRepositoryInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ObjectManager |
15
|
|
|
*/ |
16
|
|
|
private $objectManager; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ORMTaskExecutionRepository |
20
|
|
|
*/ |
21
|
|
|
private $taskExecutionRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param ObjectManager $objectManager |
25
|
|
|
* @param ORMTaskExecutionRepository $taskExecutionRepository |
26
|
|
|
*/ |
27
|
|
|
public function __construct(ObjectManager $objectManager, ORMTaskExecutionRepository $taskExecutionRepository) |
28
|
|
|
{ |
29
|
|
|
$this->objectManager = $objectManager; |
30
|
|
|
$this->taskExecutionRepository = $taskExecutionRepository; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function store(TaskExecutionInterface $execution) |
37
|
|
|
{ |
38
|
|
|
$this->objectManager->persist($execution); |
39
|
|
|
|
40
|
|
|
// FIXME move this flush to somewhere else (: |
41
|
|
|
$this->objectManager->flush(); |
42
|
|
|
|
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function save(TaskExecutionInterface $execution) |
50
|
|
|
{ |
51
|
|
|
$this->objectManager->persist($execution); |
52
|
|
|
|
53
|
|
|
// FIXME move this flush to somewhere else (: |
54
|
|
|
$this->objectManager->flush(); |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime) |
63
|
|
|
{ |
64
|
|
|
return $this->taskExecutionRepository->findByStartTime($task, $scheduleTime); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function findAll($limit = null) |
71
|
|
|
{ |
72
|
|
|
return $this->taskExecutionRepository->findBy([], ['scheduleTime' => 'ASC'], $limit); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function findScheduled() |
79
|
|
|
{ |
80
|
|
|
return $this->taskExecutionRepository->findScheduled(new \DateTime()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|