1 | <?php |
||
20 | class PopulateCommand extends ContainerAwareCommand |
||
21 | { |
||
22 | /** |
||
23 | * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
||
24 | */ |
||
25 | private $dispatcher; |
||
26 | |||
27 | /** |
||
28 | * @var IndexManager |
||
29 | */ |
||
30 | private $indexManager; |
||
31 | |||
32 | /** |
||
33 | * @var ProgressClosureBuilder |
||
34 | */ |
||
35 | private $progressClosureBuilder; |
||
36 | |||
37 | /** |
||
38 | * @var ProviderRegistry |
||
39 | */ |
||
40 | private $providerRegistry; |
||
41 | |||
42 | /** |
||
43 | * @var Resetter |
||
44 | */ |
||
45 | private $resetter; |
||
46 | |||
47 | /** |
||
48 | * @see Symfony\Component\Console\Command\Command::configure() |
||
49 | */ |
||
50 | protected function configure() |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
84 | |||
85 | /** |
||
86 | * {@inheritDoc} |
||
87 | */ |
||
88 | protected function execute(InputInterface $input, OutputInterface $output) |
||
89 | { |
||
90 | $index = $input->getOption('index'); |
||
91 | $type = $input->getOption('type'); |
||
92 | $reset = !$input->getOption('no-reset'); |
||
93 | $options = array( |
||
94 | 'ignore_errors' => $input->getOption('ignore-errors'), |
||
95 | 'offset' => $input->getOption('offset'), |
||
96 | 'sleep' => $input->getOption('sleep') |
||
97 | ); |
||
98 | if ($input->getOption('batch-size')) { |
||
99 | $options['batch_size'] = (int) $input->getOption('batch-size'); |
||
100 | } |
||
101 | |||
102 | if ($input->isInteractive() && $reset && $input->getOption('offset')) { |
||
103 | /** @var DialogHelper $dialog */ |
||
104 | $dialog = $this->getHelperSet()->get('dialog'); |
||
105 | if (!$dialog->askConfirmation($output, '<question>You chose to reset the index and start indexing with an offset. Do you really want to do that?</question>', true)) { |
||
106 | return; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | if (null === $index && null !== $type) { |
||
111 | throw new \InvalidArgumentException('Cannot specify type option without an index.'); |
||
112 | } |
||
113 | |||
114 | if (null !== $index) { |
||
115 | if (null !== $type) { |
||
116 | $this->populateIndexType($output, $index, $type, $reset, $options); |
||
117 | } else { |
||
118 | $this->populateIndex($output, $index, $reset, $options); |
||
119 | } |
||
120 | } else { |
||
121 | $indexes = array_keys($this->indexManager->getAllIndexes()); |
||
122 | |||
123 | foreach ($indexes as $index) { |
||
124 | $this->populateIndex($output, $index, $reset, $options); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Recreates an index, populates its types, and refreshes the index. |
||
131 | * |
||
132 | * @param OutputInterface $output |
||
133 | * @param string $index |
||
134 | * @param boolean $reset |
||
135 | * @param array $options |
||
136 | */ |
||
137 | private function populateIndex(OutputInterface $output, $index, $reset, $options) |
||
156 | |||
157 | /** |
||
158 | * Deletes/remaps an index type, populates it, and refreshes the index. |
||
159 | * |
||
160 | * @param OutputInterface $output |
||
161 | * @param string $index |
||
162 | * @param string $type |
||
163 | * @param boolean $reset |
||
164 | * @param array $options |
||
165 | */ |
||
166 | private function populateIndexType(OutputInterface $output, $index, $type, $reset, $options) |
||
184 | |||
185 | /** |
||
186 | * Refreshes an index. |
||
187 | * |
||
188 | * @param OutputInterface $output |
||
189 | * @param string $index |
||
190 | * @param bool $postPopulate |
||
191 | */ |
||
192 | private function refreshIndex(OutputInterface $output, $index, $postPopulate = true) |
||
201 | } |
||
202 |