|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace As3\Bundle\ModlrBundle\Command\Schema; |
|
4
|
|
|
|
|
5
|
|
|
use As3\Bundle\ModlrBundle\Schema\Manager; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Utilizes the Schema Manager to create or update indices |
|
14
|
|
|
* |
|
15
|
|
|
* @author Josh Worden <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class Create extends Command |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var Manager |
|
21
|
|
|
*/ |
|
22
|
|
|
private $manager; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Manager $manager |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(Manager $manager) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
$this->manager = $manager; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function configure() |
|
39
|
|
|
{ |
|
40
|
|
|
$this |
|
41
|
|
|
->setName('as3:modlr:schema:create') |
|
42
|
|
|
->setDescription('Creates model indices.') |
|
43
|
|
|
->addArgument('type', InputArgument::OPTIONAL, 'Specify the model type to create for.') |
|
44
|
|
|
; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
51
|
|
|
{ |
|
52
|
|
|
$type = $input->getArgument('type') ?: null; |
|
53
|
|
|
$types = (null === $type) ? 'all types' : sprintf('model type "%s"', $type); |
|
54
|
|
|
|
|
55
|
|
|
$count = count($this->manager->getIndices($type)); |
|
56
|
|
|
$output->writeln(sprintf('Creating <info>%s</info> %s for <info>%s</info>',$count, $count == 1 ? 'index' : 'indices', $types)); |
|
57
|
|
|
|
|
58
|
|
|
foreach ($this->manager->getIndices($type) as $index) { |
|
59
|
|
|
$output->writeln(sprintf(' Creating index <info>%s</info> for model <info>%s</info>', $index['name'], $index['model_type'])); |
|
60
|
|
|
$this->manager->createIndex($index); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$output->writeln('<info>Done!</info>'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|