|
1
|
|
|
<?php namespace Cerbero\Workflow\Console\Commands; |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
4
|
|
|
|
|
5
|
|
|
class UpdateWorkflowCommand extends WorkflowGeneratorCommand { |
|
6
|
|
|
|
|
7
|
|
|
use AttachesPipesTrait, DeleteIfForcedTrait; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The console command name. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $name = 'workflow:update'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The console command description. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $description = 'Update an existing workflow'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Andrea Marco Sartori |
|
25
|
|
|
* @var string $type Type of class to generate. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $type = 'Pipe'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Execute the console command. |
|
31
|
|
|
* |
|
32
|
|
|
* @return mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
public function fire() |
|
35
|
|
|
{ |
|
36
|
|
|
$name = $this->getWorkflowName(); |
|
37
|
|
|
|
|
38
|
|
|
if( ! $this->pipelines->exists($name)) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->error("The workflow [$name] does not exist."); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->generatePipes(); |
|
44
|
|
|
|
|
45
|
|
|
$this->deleteDetachedIfForced(); |
|
46
|
|
|
|
|
47
|
|
|
$this->updateWorkflow($name); |
|
48
|
|
|
|
|
49
|
|
|
$this->info('Workflow updated successfully.'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Delete the detached pipes if force is set. |
|
54
|
|
|
* |
|
55
|
|
|
* @author Andrea Marco Sartori |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function deleteDetachedIfForced() |
|
59
|
|
|
{ |
|
60
|
|
|
$detachments = $this->getNamespacedPipesByOption('detach'); |
|
61
|
|
|
|
|
62
|
|
|
$this->deleteIfForced($detachments); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Update the given workflow. |
|
67
|
|
|
* |
|
68
|
|
|
* @author Andrea Marco Sartori |
|
69
|
|
|
* @param string $workflow |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function updateWorkflow($workflow) |
|
73
|
|
|
{ |
|
74
|
|
|
$attachments = $this->getNamespacedPipesByOption('attach'); |
|
75
|
|
|
|
|
76
|
|
|
$detachments = $this->getNamespacedPipesByOption('detach'); |
|
77
|
|
|
|
|
78
|
|
|
$this->pipelines->update($workflow, $attachments, $detachments); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the console command options. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getOptions() |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
['attach', '-a', InputOption::VALUE_OPTIONAL, 'The pipes to attach to the workflow.', null], |
|
90
|
|
|
['detach', '-d', InputOption::VALUE_OPTIONAL, 'The pipes to detach from the workflow.', null], |
|
91
|
|
|
['force', '-f', InputOption::VALUE_NONE, 'Delete the files of detached pipes.'], |
|
92
|
|
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|