1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pheanstalk\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Pheanstalk\ResponseParser; |
7
|
|
|
use Pheanstalk\Structure\Job; |
8
|
|
|
use Pheanstalk\Structure\Task; |
9
|
|
|
use Pheanstalk\Structure\Workflow; |
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 GetWorkflowCommand extends AbstractCommand implements ResponseParser |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** @var Workflow $workflow */ |
24
|
|
|
private $workflow; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* GetWorkflowCommand constructor. |
28
|
|
|
* |
29
|
|
|
* @param Workflow $workflow |
30
|
|
|
*/ |
31
|
7 |
|
public function __construct(Workflow $workflow) |
32
|
|
|
{ |
33
|
7 |
|
$this->workflow = $workflow; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritDoc |
38
|
|
|
*/ |
39
|
7 |
|
public function getGroup(): string |
40
|
|
|
{ |
41
|
7 |
|
return 'workflow'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritDoc |
46
|
|
|
*/ |
47
|
7 |
|
public function getAction(): string |
48
|
|
|
{ |
49
|
7 |
|
return 'get'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
7 |
|
public function getFilters(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
7 |
|
'id' => $this->workflow->getId() |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @inheritDoc |
64
|
|
|
*/ |
65
|
7 |
|
public function getResponseParser() |
66
|
|
|
{ |
67
|
7 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritDoc |
72
|
|
|
*/ |
73
|
7 |
|
public function parseResponse($responseLine, $responseData) |
74
|
|
|
{ |
75
|
7 |
|
$workflow = $responseData['workflow']; |
76
|
7 |
|
$jobs = $workflow['workflow']['subjobs']; |
77
|
7 |
|
$workflow = $workflow['@attributes'] ?? $workflow; |
|
|
|
|
78
|
7 |
|
$jobObjects = []; |
79
|
7 |
|
foreach ($jobs as $job) { |
80
|
7 |
|
$taskObjects = []; |
81
|
7 |
|
foreach ($job['tasks'] as $task) { |
82
|
7 |
|
$task = $task['@attributes']; |
83
|
7 |
|
$taskObjects[] = new Task($task['path'], $task['queue'], $task['use-agent'], $task['user'], $task['host'], $task['output-method'], $task['parameters-mode']); |
84
|
|
|
} |
85
|
7 |
|
$jobObjects[] = new Job(new ArrayCollection($taskObjects)); |
86
|
|
|
} |
87
|
7 |
|
$this->workflow->setJobs(new ArrayCollection($jobObjects)); |
88
|
|
|
|
89
|
7 |
|
return $this->workflow; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|