|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use eZ\Publish\Core\Search\Common\Indexer; |
|
16
|
|
|
use RuntimeException; |
|
17
|
|
|
|
|
18
|
|
|
class ReindexCommand extends ContainerAwareCommand |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \eZ\Publish\Core\Search\Common\Indexer |
|
22
|
|
|
*/ |
|
23
|
|
|
private $searchIndexer; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Initialize objects required by {@see execute()}. |
|
27
|
|
|
* |
|
28
|
|
|
* @param InputInterface $input |
|
29
|
|
|
* @param OutputInterface $output |
|
30
|
|
|
*/ |
|
31
|
|
|
public function initialize(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::initialize($input, $output); |
|
34
|
|
|
$this->searchIndexer = $this->getContainer()->get('ezpublish.spi.search.indexer'); |
|
35
|
|
|
if (!$this->searchIndexer instanceof Indexer) { |
|
36
|
|
|
throw new RuntimeException( |
|
37
|
|
|
sprintf('Expected to find Search Engine Indexer but found "%s" instead', get_parent_class($this->searchIndexer)) |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function configure() |
|
46
|
|
|
{ |
|
47
|
|
|
$this |
|
48
|
|
|
->setName('ezplatform:reindex') |
|
49
|
|
|
->setDescription('Recreate search engine index') |
|
50
|
|
|
->addOption('iteration-count', 'c', InputOption::VALUE_OPTIONAL, 'Number of objects to be indexed in a single iteration', 20) |
|
51
|
|
|
->addOption('no-commit', null, InputOption::VALUE_NONE, 'Do not commit after each iteration') |
|
52
|
|
|
->setHelp( |
|
53
|
|
|
<<<EOT |
|
54
|
|
|
The command <info>%command.name%</info> indexes current configured database in configured search engine index. |
|
55
|
|
|
EOT |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
63
|
|
|
{ |
|
64
|
|
|
$iterationCount = $input->getOption('iteration-count'); |
|
65
|
|
|
$noCommit = $input->getOption('no-commit'); |
|
66
|
|
|
|
|
67
|
|
|
if (!is_numeric($iterationCount) || (int)$iterationCount < 1) { |
|
68
|
|
|
throw new RuntimeException("'--iteration-count' option should be > 0, got '{$iterationCount}'"); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$this->searchIndexer->createSearchIndex($output, intval($iterationCount), empty($noCommit)); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|