1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pouzor\MongoDBBundle\Command; |
4
|
|
|
|
5
|
|
|
use MongoDB\Client; |
6
|
|
|
use MongoDB\Collection; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
13
|
|
|
use Symfony\Component\Yaml\Yaml; |
14
|
|
|
|
15
|
|
|
class BuildIndexesCommand extends ContainerAwareCommand |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
private $manager; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
1 |
|
protected function configure() |
24
|
|
|
{ |
25
|
1 |
|
$this |
26
|
1 |
|
->setName('mongo:indexes:build') |
27
|
1 |
|
->addOption('collection', 'c', InputOption::VALUE_OPTIONAL, 'Build indexes just for this collection') |
28
|
1 |
|
->addOption('rebuild', 'r', InputOption::VALUE_NONE, 'Drop and create indexes') |
29
|
1 |
|
->setDescription('Build indexes in a mongo database'); |
30
|
1 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
1 |
|
$style = new SymfonyStyle($input, $output); |
38
|
|
|
|
39
|
1 |
|
$rebuild = $input->getOption('rebuild'); |
40
|
1 |
|
$collection = $input->getOption('collection'); |
41
|
|
|
|
42
|
1 |
|
$callback = function ($name) use ($style) { |
43
|
1 |
|
$style->comment(sprintf('%s : Ok', $name)); |
44
|
1 |
|
}; |
45
|
|
|
|
46
|
1 |
|
if ($collection) { |
47
|
|
|
$this->manager->getRepository($collection)->buildIndexes($callback); |
48
|
|
|
} else { |
49
|
1 |
|
$this->manager->buildIndexes($rebuild, $callback); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function setManager($manager) { |
55
|
|
|
|
56
|
1 |
|
$this->manager = $manager; |
57
|
|
|
} |
58
|
|
|
} |