-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathOptimizeCommand.php
More file actions
67 lines (51 loc) · 1.73 KB
/
Copy pathOptimizeCommand.php
File metadata and controls
67 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
* This file is part of the MassiveSearchBundle
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Massive\Bundle\SearchBundle\Command;
use Massive\Bundle\SearchBundle\Search\AdapterInterface;
use Massive\Bundle\SearchBundle\Search\OptimizeableAdapterInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @final
*/
class OptimizeCommand extends Command
{
protected static $defaultName = 'massive:search:optimize';
/**
* @var AdapterInterface
*/
private $adapter;
public function __construct(AdapterInterface $adapter)
{
parent::__construct(self::$defaultName);
$this->adapter = $adapter;
}
public function configure()
{
$this->setDescription('Optimize all search indices. Affects only indices that are managed with the zend_lucene adapter at the moment.');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
if (!$this->adapter instanceof OptimizeableAdapterInterface) {
$output->writeln(\sprintf('Adapter "%s" does not support index optimization.', \get_class($this->adapter)));
return 0;
}
$output->writeln('Optimize indexes:');
$output->writeln('');
foreach ($this->adapter->listIndexes() as $indexName) {
$output->writeln(' - ' . $indexName);
$this->adapter->optimize($indexName);
}
$output->writeln('');
$output->writeln('<info>All indeces optimized!</info>');
return 0;
}
}