Completed
Pull Request — master (#15)
by Wachter
07:51
created

TaskExecutionRepository::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 1
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\DoctrineStorage;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Task\Execution\TaskExecutionInterface;
16
use Task\Execution\TaskExecutionRepositoryInterface;
17
use Task\TaskBundle\Entity\TaskExecutionRepository as ORMTaskExecutionRepository;
18
use Task\TaskInterface;
19
20
/**
21
 * Task-execution storage using doctrine.
22
 */
23
class TaskExecutionRepository implements TaskExecutionRepositoryInterface
24
{
25
    /**
26
     * @var ObjectManager
27
     */
28
    private $objectManager;
29
30
    /**
31
     * @var ORMTaskExecutionRepository
32
     */
33
    private $taskExecutionRepository;
34
35
    /**
36
     * @param ObjectManager $objectManager
37
     * @param ORMTaskExecutionRepository $taskExecutionRepository
38
     */
39
    public function __construct(ObjectManager $objectManager, ORMTaskExecutionRepository $taskExecutionRepository)
40
    {
41
        $this->objectManager = $objectManager;
42
        $this->taskExecutionRepository = $taskExecutionRepository;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function store(TaskExecutionInterface $execution)
49
    {
50
        $this->objectManager->persist($execution);
51
52
        // FIXME move this flush to somewhere else (:
53
        $this->objectManager->flush();
54
55
        return $this;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function save(TaskExecutionInterface $execution)
62
    {
63
        $this->objectManager->persist($execution);
64
65
        // FIXME move this flush to somewhere else (:
66
        $this->objectManager->flush();
67
68
        return $this;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function findByStartTime(TaskInterface $task, \DateTime $scheduleTime)
75
    {
76
        return $this->taskExecutionRepository->findByScheduledTime($task, $scheduleTime);
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function findAll($limit = null)
83
    {
84
        return $this->taskExecutionRepository->findBy([], ['scheduleTime' => 'ASC'], $limit);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function findScheduled()
91
    {
92
        return $this->taskExecutionRepository->findScheduled(new \DateTime());
93
    }
94
}
95