1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pheanstalk\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Pheanstalk\Structure\JobInstance; |
7
|
|
|
use Pheanstalk\Structure\TaskInstance; |
8
|
|
|
use Pheanstalk\Structure\Workflow; |
9
|
|
|
use Pheanstalk\Structure\WorkflowInstance; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The 'GetWorkflow' command. |
13
|
|
|
* |
14
|
|
|
* Retrieve a workflow by its id, if there is no workflow for the id given in the construct, returns false |
15
|
|
|
* |
16
|
|
|
* @author Valentin Corre |
17
|
|
|
* @package Pheanstalk |
18
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
19
|
|
|
*/ |
20
|
|
|
class GetWorkflowInstancesDetailCommand extends GetWorkflowInstancesCommand |
21
|
|
|
{ |
22
|
|
|
/** @var WorkflowInstance $workflowInstance */ |
23
|
|
|
private $workflowInstance; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* GetWorkflowCommand constructor. |
27
|
|
|
* |
28
|
|
|
* @param Workflow $workflow |
29
|
|
|
*/ |
30
|
3 |
|
public function __construct(WorkflowInstance $workflowInstance) |
31
|
|
|
{ |
32
|
3 |
|
$this->workflowInstance = $workflowInstance; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
3 |
|
public function getGroup(): string |
39
|
|
|
{ |
40
|
3 |
|
return 'instance'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
3 |
|
public function getAction(): string |
47
|
|
|
{ |
48
|
3 |
|
return 'query'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
3 |
|
public function getFilters(): array |
55
|
|
|
{ |
56
|
|
|
$filters = [ |
57
|
3 |
|
'id' => $this->workflowInstance->getId(), |
58
|
|
|
]; |
59
|
|
|
|
60
|
3 |
|
return $filters; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
3 |
|
public function getResponseParser() |
67
|
|
|
{ |
68
|
3 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
3 |
|
public function parseResponse($responseLine, $responseData) |
75
|
|
|
{ |
76
|
3 |
|
$subjobs = $responseData['workflow']['subjobs']; |
77
|
3 |
|
$jobInstances = new ArrayCollection([]); |
78
|
3 |
|
foreach ($subjobs as $subjob) { |
79
|
3 |
|
$taskInstances = new ArrayCollection([]); |
80
|
3 |
|
foreach ($subjob['tasks'] as $tasks) { |
81
|
3 |
|
$task = $tasks['@attributes']; |
82
|
|
|
|
83
|
3 |
|
if (isset($task['execution_time'])) { |
84
|
3 |
|
$task['execution_time'] = new \DateTime($task['execution_time']); |
85
|
|
|
} |
86
|
3 |
|
foreach ($task as $key => $val) { |
87
|
3 |
|
if (ctype_digit($val)) { |
88
|
3 |
|
$task[$key] = (int) $task[$key]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
3 |
|
$taskInstances[] = new TaskInstance($task); |
92
|
|
|
} |
93
|
3 |
|
$jobInstances[] = new JobInstance($taskInstances); |
94
|
|
|
} |
95
|
3 |
|
$this->workflowInstance->setJobInstances($jobInstances); |
96
|
|
|
|
97
|
3 |
|
return $this->workflowInstance; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|