|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pheanstalk\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Pheanstalk\Exception; |
|
6
|
|
|
use Pheanstalk\Response; |
|
7
|
|
|
use Pheanstalk\Structure\TimeSchedule; |
|
8
|
|
|
use Pheanstalk\Structure\Workflow; |
|
9
|
|
|
use Pheanstalk\XmlResponseParser; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The 'CreateSchedule' command. |
|
13
|
|
|
* |
|
14
|
|
|
* Inserts a new workflow_schedule into the client. |
|
15
|
|
|
* |
|
16
|
|
|
* |
|
17
|
|
|
* @author Valentin Corre |
|
18
|
|
|
* @package Pheanstalk |
|
19
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
|
20
|
|
|
*/ |
|
21
|
|
|
class CreateScheduleCommand extends AbstractCommand implements \Pheanstalk\ResponseParser |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
const FAILURE_TYPE_CONTINUE = "CONTINUE"; |
|
25
|
|
|
const FAILURE_TYPE_SUSPEND = "SUSPEND"; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Workflow $workflow */ |
|
28
|
|
|
private $workflow; |
|
29
|
|
|
|
|
30
|
|
|
private $schedule; |
|
31
|
|
|
|
|
32
|
|
|
private $onFailure; |
|
33
|
|
|
|
|
34
|
|
|
/** @var bool $active */ |
|
35
|
|
|
private $active; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string|null $comment */ |
|
38
|
|
|
private $comment; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* CreateScheduleCommand constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param Workflow $workflow |
|
44
|
|
|
* @param TimeSchedule $schedule |
|
45
|
|
|
* @param string $onFailure |
|
46
|
|
|
* @param bool $active |
|
47
|
|
|
* @param string|null $comment |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct(Workflow $workflow, TimeSchedule $schedule, $onFailure = self::FAILURE_TYPE_CONTINUE, $active = true, $comment = null) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->workflow = $workflow; |
|
52
|
|
|
$this->schedule = $schedule; |
|
53
|
|
|
$this->onFailure = $onFailure ?? self::FAILURE_TYPE_CONTINUE; |
|
54
|
|
|
$this->active = $active ?? true ; |
|
55
|
|
|
$this->comment = $comment ?? $this->workflow->getComment(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @inheritDoc |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getGroup(): string |
|
62
|
|
|
{ |
|
63
|
|
|
return 'workflow_schedule'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @inheritDoc |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getAction(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return 'create'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @inheritDoc |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getFilters(): array |
|
78
|
|
|
{ |
|
79
|
|
|
return[ |
|
80
|
|
|
'workflow_id' => $this->workflow->getId(), |
|
81
|
|
|
'schedule' => $this->schedule->__toString(), |
|
82
|
|
|
"onfailure" => $this->onFailure, |
|
83
|
|
|
'active' => $this->active, |
|
84
|
|
|
'comment' => $this->comment, |
|
85
|
|
|
'node' => "any" |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @inheritDoc |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getResponseParser() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritDoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function parseResponse($responseLine, $responseData) |
|
101
|
|
|
{ |
|
102
|
|
|
return (int) $responseData['@attributes']['schedule-id']; |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: