1 | <?php |
---|
2 | |
---|
3 | use Symfony\Component\Console\Command\Command; |
---|
4 | use Symfony\Component\Console\Input\InputArgument; |
---|
5 | use Symfony\Component\Console\Input\InputInterface; |
---|
6 | use Symfony\Component\Console\Input\InputOption; |
---|
7 | use Symfony\Component\Console\Output\OutputInterface; |
---|
8 | use Symfony\Component\Console\Helper\ProgressHelper; |
---|
9 | |
---|
10 | class SphinxGenererAutocomplete extends Command { |
---|
11 | protected function configure() { |
---|
12 | $this |
---|
13 | ->setName('sphinx:generer_autocomplete') |
---|
14 | ->setDescription('Générer le dictionnaire nécessaire à l’autocomplétion. DOIT être lancée en sudo pour lire les dossiers de Sphinx.') |
---|
15 | ->addOption( |
---|
16 | 'index', |
---|
17 | 'i', |
---|
18 | InputOption::VALUE_OPTIONAL, |
---|
19 | 'Nom de l’index Sphinx dont on veut générer le dictionnaire', |
---|
20 | 'spip' |
---|
21 | ) |
---|
22 | ->addOption( |
---|
23 | 'dossier-data', |
---|
24 | null, |
---|
25 | InputOption::VALUE_OPTIONAL, |
---|
26 | 'Nom de l’index Sphinx dont on veut générer le dictionnaire', |
---|
27 | '/var/lib/sphinxsearch/data/' |
---|
28 | ) |
---|
29 | ; |
---|
30 | } |
---|
31 | |
---|
32 | protected function execute(InputInterface $input, OutputInterface $output) { |
---|
33 | include_spip('inc/flock'); |
---|
34 | include_spip('inc/indexer'); |
---|
35 | |
---|
36 | // On récupère les options |
---|
37 | $index = $input->getOption('index'); |
---|
38 | $dossier_data = $input->getOption('dossier-data'); |
---|
39 | |
---|
40 | // On se fait un dossier temporaire pour enregistrer le dictionnaire complet |
---|
41 | $dossier_tmp = sous_repertoire(_DIR_TMP . 'sphinx/'); |
---|
42 | |
---|
43 | $sphinxql = new \Sphinx\SphinxQL\SphinxQL(SPHINX_SERVER_HOST, SPHINX_SERVER_PORT); |
---|
44 | |
---|
45 | // On fait produire les bons fichiers pour le RT |
---|
46 | $sphinxql->query("FLUSH RAMCHUNK $index"); |
---|
47 | |
---|
48 | // On récupère le chemin du premier fichier SPI trouvé dans le dossier Sphinx |
---|
49 | if ($spis = glob($dossier_data . $index . '.*.spi') and $spi = $spis[0]) { |
---|
50 | if (function_exists('passthru')) { |
---|
51 | passthru("indextool --dumpdict $spi > {$dossier_tmp}{$index}.dict.txt"); |
---|
52 | } |
---|
53 | else { |
---|
54 | $output->writeln('<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>'); |
---|
55 | } |
---|
56 | } |
---|
57 | else { |
---|
58 | $output->writeln("<error>Pas trouvé de fichier data/$index.*.spi</error>"); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|