1 | <?php |
||
2 | |||
3 | namespace Kaliop\eZWorkflowEngineBundle\Command; |
||
4 | |||
5 | use Kaliop\eZMigrationBundle\API\Value\Migration; |
||
6 | use Symfony\Component\Console\Helper\Table; |
||
7 | use Symfony\Component\Console\Input\InputInterface; |
||
8 | use Symfony\Component\Console\Input\InputOption; |
||
9 | use Symfony\Component\Console\Output\OutputInterface; |
||
10 | |||
11 | /** |
||
12 | * Command to display the defined workflows. |
||
13 | * |
||
14 | * @todo add a 'summary' option |
||
15 | */ |
||
16 | class StatusCommand extends AbstractCommand |
||
17 | { |
||
18 | protected function configure() |
||
19 | { |
||
20 | $this->setName('kaliop:workflows:status') |
||
21 | ->addOption('summary', null, InputOption::VALUE_NONE, "Only print summary information") |
||
22 | ->setDescription('List the currently executing or already executed workflows') |
||
23 | ; |
||
24 | } |
||
25 | |||
26 | public function execute(InputInterface $input, OutputInterface $output) |
||
27 | { |
||
28 | $workflowService = $this->getWorkflowService(); |
||
29 | |||
30 | $workflows = $workflowService->getWorkflows(); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | |||
32 | if (!count($workflows)) { |
||
33 | $output->writeln('<info>No workflows found</info>'); |
||
34 | return 0; |
||
35 | } |
||
36 | |||
37 | $summary = array( |
||
38 | Migration::STATUS_TODO => array('To do', 0), |
||
39 | Migration::STATUS_STARTED => array('Started', 0), |
||
40 | Migration::STATUS_DONE => array('Done', 0), |
||
41 | Migration::STATUS_SUSPENDED => array('Suspended', 0), |
||
42 | Migration::STATUS_FAILED => array('Failed', 0), |
||
43 | Migration::STATUS_SKIPPED => array('Skipped', 0), |
||
44 | Migration::STATUS_PARTIALLY_DONE => array('Partially done', 0), |
||
45 | ); |
||
46 | |||
47 | $i = 1; |
||
48 | foreach ($workflows as $workflow) { |
||
49 | |||
50 | if (!isset($summary[$workflow->status])) { |
||
51 | $summary[$workflow->status] = array($workflow->status, 0); |
||
52 | } |
||
53 | $summary[$workflow->status][1]++; |
||
54 | if ($input->getOption('summary')) { |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | switch ($workflow->status) { |
||
59 | case Migration::STATUS_DONE: |
||
60 | $status = '<info>executed</info>'; |
||
61 | break; |
||
62 | case Migration::STATUS_STARTED: |
||
63 | $status = '<comment>execution started</comment>'; |
||
64 | break; |
||
65 | case Migration::STATUS_TODO: |
||
66 | // bold to-migrate! |
||
67 | $status = '<error>not executed</error>'; |
||
68 | break; |
||
69 | case Migration::STATUS_SKIPPED: |
||
70 | $status = '<comment>skipped</comment>'; |
||
71 | break; |
||
72 | case Migration::STATUS_PARTIALLY_DONE: |
||
73 | $status = '<comment>partially executed</comment>'; |
||
74 | break; |
||
75 | case Migration::STATUS_SUSPENDED: |
||
76 | $status = '<comment>suspended</comment>'; |
||
77 | break; |
||
78 | case Migration::STATUS_FAILED: |
||
79 | $status = '<error>failed</error>'; |
||
80 | break; |
||
81 | } |
||
82 | |||
83 | switch ($workflow->status) { |
||
84 | case Migration::STATUS_FAILED: |
||
85 | $name = '<error>' . $workflow->name . '</error>'; |
||
86 | break; |
||
87 | default: |
||
88 | $name = $workflow->name; |
||
89 | } |
||
90 | |||
91 | $data[] = array( |
||
92 | $i++, |
||
93 | $name, |
||
94 | $workflow->signalName, |
||
95 | $status, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
96 | $workflow->executionDate != null ? date("Y-m-d H:i:s", $workflow->executionDate) : '', |
||
97 | $workflow->executionError, |
||
98 | ); |
||
99 | |||
100 | } |
||
101 | |||
102 | if ($input->getOption('summary')) { |
||
103 | $output->writeln("\n <info>==</info> Workflows Summary\n"); |
||
104 | // do not print info about the not yet supported case |
||
105 | unset($summary[Migration::STATUS_PARTIALLY_DONE]); |
||
106 | $data = $summary; |
||
107 | $headers = array('Status', 'Count'); |
||
108 | } else { |
||
109 | $headers = array('#', 'Workflow', 'Signal', 'Status', 'Executed on', 'Notes'); |
||
110 | } |
||
111 | |||
112 | $table = new Table($output); |
||
113 | $table |
||
114 | ->setHeaders($headers) |
||
115 | ->setRows($data); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
116 | $table->render(); |
||
117 | |||
118 | return 0; |
||
119 | } |
||
120 | } |
||
121 |