1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pheanstalk\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Pheanstalk\Structure\Job; |
7
|
|
|
use Pheanstalk\Structure\Task; |
8
|
|
|
use Pheanstalk\Structure\Workflow; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The 'GetWorkflow' command. |
12
|
|
|
* |
13
|
|
|
* Retrieve a workflow by its id, if there is no workflow for the id given in the construct, returns false |
14
|
|
|
* |
15
|
|
|
* @author Valentin Corre |
16
|
|
|
* @package Pheanstalk |
17
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
18
|
|
|
*/ |
19
|
|
|
class GetWorkflowCommand extends AbstractCommand implements \Pheanstalk\ResponseParser |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** @var Workflow $workflow */ |
23
|
|
|
private $workflow; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* GetWorkflowCommand constructor. |
27
|
|
|
* |
28
|
|
|
* @param Workflow $workflow |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Workflow $workflow) |
31
|
|
|
{ |
32
|
|
|
$this->workflow = $workflow; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
|
|
public function getGroup(): string |
39
|
|
|
{ |
40
|
|
|
return 'workflow'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function getAction(): string |
47
|
|
|
{ |
48
|
|
|
return 'get'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function getFilters(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
'id' => $this->workflow->getId() |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritDoc |
63
|
|
|
*/ |
64
|
|
|
public function getResponseParser() |
65
|
|
|
{ |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
|
|
public function parseResponse($responseLine, $responseData) |
73
|
|
|
{ |
74
|
|
|
$workflow = $responseData['workflow']; |
75
|
|
|
$jobs = $workflow['workflow']['subjobs']; |
76
|
|
|
$workflow = $workflow['@attributes'] ?? $workflow; |
|
|
|
|
77
|
|
|
$jobObjects = []; |
78
|
|
|
foreach ($jobs as $job) { |
79
|
|
|
$taskObjects = []; |
80
|
|
|
foreach ($job['tasks'] as $task) { |
81
|
|
|
$task = $task['@attributes']; |
82
|
|
|
$taskObjects[] = new Task($task['path'], $task['queue'], $task['use-agent'], $task['user'], $task['host'], $task['output-method'], $task['parameters-mode']); |
83
|
|
|
} |
84
|
|
|
$jobObjects[] = new Job(new ArrayCollection($taskObjects)); |
85
|
|
|
} |
86
|
|
|
$this->workflow->setJobs(new ArrayCollection($jobObjects)); |
87
|
|
|
|
88
|
|
|
return $this->workflow; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|