|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) fduch <[email protected]> |
|
9
|
|
|
* @date 01.08.16 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Entity\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\ORM\EntityRepository; |
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Entity\ScheduledJob; |
|
16
|
|
|
use JMS\JobQueueBundle\Entity\Job; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* ScheduledJobRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
class ScheduledJobRepository extends EntityRepository |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Finds ScheduledJob by subject identity and workflow transition that can be rescheduled (is able to be started now) |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $workflowName workflow name |
|
27
|
|
|
* @param string $transitionName transition name |
|
28
|
|
|
* @param string $subjectClass subject class |
|
29
|
|
|
* @param string $subjectId subject id |
|
30
|
|
|
* |
|
31
|
|
|
* @return ScheduledJob|null |
|
32
|
|
|
*/ |
|
33
|
|
|
public function findScheduledJobToReschedule($workflowName, $transitionName, $subjectClass, $subjectId) |
|
34
|
|
|
{ |
|
35
|
|
|
// fetching scheduled job that was not started before - it can be rescheduled |
|
36
|
|
|
$queryString = <<<'QUERY' |
|
37
|
|
|
SELECT sj FROM WorkflowExtensionsBundle:ScheduledJob sj |
|
38
|
|
|
JOIN sj.job j |
|
39
|
|
|
WHERE |
|
40
|
|
|
sj.workflow = :workflow AND |
|
41
|
|
|
sj.transition = :transition AND |
|
42
|
|
|
sj.subjectClass = :subjectClass AND |
|
43
|
|
|
sj.subjectId = :subjectId AND |
|
44
|
|
|
j.state in (:stateNew, :statePending) |
|
45
|
|
|
QUERY; |
|
46
|
|
|
|
|
47
|
|
|
$scheduledJobToReschedule = |
|
48
|
|
|
$this->_em |
|
49
|
|
|
->createQuery($queryString) |
|
50
|
|
|
->setParameters([ |
|
51
|
|
|
'workflow' => $workflowName, |
|
52
|
|
|
'transition' => $transitionName, |
|
53
|
|
|
'subjectClass' => $subjectClass, |
|
54
|
|
|
'subjectId' => $subjectId, |
|
55
|
|
|
'stateNew' => Job::STATE_NEW, |
|
56
|
|
|
'statePending' => Job::STATE_PENDING |
|
57
|
|
|
]) |
|
58
|
|
|
// since there is unique index on transition, workflow, subjectClass, subjectId fields we can select here |
|
59
|
|
|
// 0 or 1 job entity |
|
60
|
|
|
->getOneOrNullResult() |
|
61
|
|
|
; |
|
62
|
|
|
|
|
63
|
|
|
return $scheduledJobToReschedule; |
|
64
|
|
|
} |
|
65
|
|
|
} |