1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\ElasticsearchDataProviderBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
6
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
7
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
8
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasStartedHandling; |
9
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasStartedProviding; |
10
|
|
|
use GBProd\ElasticsearchDataProviderBundle\Event\HasIndexedDocument; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Progress bar for providing |
14
|
|
|
* |
15
|
|
|
* @author gbprod <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ProvidingProgressBar |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var OutputInterface |
21
|
|
|
*/ |
22
|
|
|
private $output; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ProgressBar |
26
|
|
|
*/ |
27
|
|
|
private $progressBar; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param EventDispatcherInterface $dispatcher |
31
|
|
|
* @param OutputInterface $output |
32
|
|
|
*/ |
33
|
1 |
|
public function __construct( |
34
|
|
|
EventDispatcherInterface $dispatcher, |
35
|
|
|
OutputInterface $output |
|
|
|
|
36
|
|
|
) { |
37
|
1 |
|
$dispatcher->addListener( |
38
|
1 |
|
'elasticsearch.has_started_handling', |
39
|
1 |
|
[$this, 'onStartedHandling'] |
40
|
1 |
|
); |
41
|
|
|
|
42
|
1 |
|
$dispatcher->addListener( |
43
|
1 |
|
'elasticsearch.has_started_providing', |
44
|
1 |
|
[$this, 'onStartedProviding'] |
45
|
1 |
|
); |
46
|
|
|
|
47
|
1 |
|
$dispatcher->addListener( |
48
|
1 |
|
'elasticsearch.has_indexed_document', |
49
|
1 |
|
[$this, 'onIndexedDocument'] |
50
|
1 |
|
); |
51
|
1 |
|
} |
52
|
|
|
|
53
|
|
|
public function onStartedHandling(HasStartedHandling $event) |
54
|
|
|
{ |
55
|
|
|
$this->output->writeln(sprintf( |
56
|
|
|
'<info>Start running <comment>%d</comment> providers</info>', |
57
|
|
|
count($event->getEntries()) |
58
|
|
|
)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function onStartedProviding(HasStartedProviding $event) |
62
|
|
|
{ |
63
|
|
|
$this->output->writeln(sprintf( |
64
|
|
|
'<info>Start running <comment>%s</comment> provider</info>', |
65
|
|
|
get_class($event->getEntry()->getProvider()) |
66
|
|
|
)); |
67
|
|
|
|
68
|
|
|
if (null !== $this->progressBar) { |
69
|
|
|
$progressBar->finish(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->progressBar = null; |
73
|
|
|
$count = $event->getEntry()->getProvider()->count(); |
74
|
|
|
if (null !== $count) { |
75
|
|
|
$this->progressBar = new ProgressBar($output, $count); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function onIndexedDocument(HasIndexedDocument $event) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
if ($this->progressBar) { |
82
|
|
|
$this->progressBar->advance(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.