1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Econda\Communication\Console; |
9
|
|
|
|
10
|
|
|
use Spryker\Zed\Kernel\Communication\Console\Console; |
11
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @method \SprykerEco\Zed\Econda\Business\EcondaFacade getFacade() |
17
|
|
|
*/ |
18
|
|
|
class EcondaFileExportConsole extends Console |
19
|
|
|
{ |
20
|
|
|
const COMMAND_NAME = 'econda:file:export'; |
21
|
|
|
const COMMAND_DESCRIPTION = 'Export data to files'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return \Symfony\Component\Console\Helper\HelperSet |
25
|
|
|
*/ |
26
|
|
|
public function getHelperSet() |
27
|
|
|
{ |
28
|
|
|
return new HelperSet(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
protected function configure() |
35
|
|
|
{ |
36
|
|
|
$this->setName(self::COMMAND_NAME); |
37
|
|
|
$this->setDescription(self::COMMAND_DESCRIPTION); |
38
|
|
|
|
39
|
|
|
parent::configure(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
44
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
45
|
|
|
* |
46
|
|
|
* @return int|null|void |
47
|
|
|
*/ |
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
49
|
|
|
{ |
50
|
|
|
$exportResults = $this->getFacade()->exportFile($output); |
51
|
|
|
$message = $this->buildNestedSummary($exportResults); |
52
|
|
|
$message = '<info>' . $message . '</info>'; |
53
|
|
|
|
54
|
|
|
$output->write($message); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $resultData |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
protected function buildSummary(array $resultData) |
63
|
|
|
{ |
64
|
|
|
if (empty($resultData)) { |
65
|
|
|
return PHP_EOL . '<fg=yellow>Nothing exported.</fg=yellow>' . PHP_EOL; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$summary = PHP_EOL; |
69
|
|
|
|
70
|
|
|
ksort($resultData); |
71
|
|
|
foreach ($resultData as $type => $result) { |
72
|
|
|
$successCount = $result->getTotalCount() - $result->getFailedCount(); |
73
|
|
|
$summary .= sprintf( |
74
|
|
|
' <fg=green>%s</fg=green><fg=yellow> </fg=yellow><fg=yellow></fg=yellow>' . PHP_EOL . |
75
|
|
|
' <fg=white>Total: %d</fg=white>' . PHP_EOL . |
76
|
|
|
' <fg=white>Processed: %d</fg=white>' . PHP_EOL . |
77
|
|
|
' <fg=white>Succeeded: %s</fg=white>' . PHP_EOL . |
78
|
|
|
' <fg=white>Deleted: %s</fg=white>' . PHP_EOL . |
79
|
|
|
' <fg=white>Failed: %s </fg=white>' . PHP_EOL, |
80
|
|
|
mb_strtoupper($type), |
81
|
|
|
$result->getTotalCount(), |
82
|
|
|
$result->getProcessedCount(), |
83
|
|
|
$successCount > 0 ? '<fg=green>' . $successCount . '</fg=green>' : $successCount, |
84
|
|
|
$result->getDeletedCount() > 0 ? '<fg=yellow>' . $result->getDeletedCount() . '</fg=yellow>' : $result->getDeletedCount(), |
85
|
|
|
$result->getFailedCount() ? '<fg=red>' . $result->getFailedCount() . '</fg=red>' : $result->getFailedCount() |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$summary .= PHP_EOL; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $summary . PHP_EOL; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param array $results |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
protected function buildNestedSummary(array $results) |
100
|
|
|
{ |
101
|
|
|
$summary = ''; |
102
|
|
|
foreach ($results as $localeName => $summaryData) { |
103
|
|
|
$summary .= PHP_EOL; |
104
|
|
|
$summary .= '<fg=yellow>----------------------------------------</fg=yellow>'; |
105
|
|
|
$summary .= PHP_EOL; |
106
|
|
|
$summary .= sprintf('<fg=yellow>Summary:</fg=yellow> <fg=white>%s</fg=white>', $localeName); |
107
|
|
|
$summary .= PHP_EOL; |
108
|
|
|
$summary .= $this->buildSummary($summaryData); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$summary .= PHP_EOL . 'All done.' . PHP_EOL; |
112
|
|
|
|
113
|
|
|
return $summary; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|