Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
list_all
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 configure
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\console\command\searchindex;
15
16use phpbb\config\config;
17use phpbb\console\command\command;
18use phpbb\di\service_collection;
19use phpbb\language\language;
20use phpbb\user;
21use Symfony\Component\Console\Command\Command as symfony_command;
22use Symfony\Component\Console\Input\InputInterface;
23use Symfony\Component\Console\Output\OutputInterface;
24use Symfony\Component\Console\Style\SymfonyStyle;
25
26class list_all extends command
27{
28    /** @var config */
29    protected $config;
30
31    /** @var language */
32    protected $language;
33
34    /** @var service_collection */
35    protected $search_backend_collection;
36
37    /**
38     * Construct method
39     *
40     * @param config                    $config
41     * @param language                    $language
42     * @param service_collection        $search_backend_collection
43     * @param user                        $user
44     */
45    public function __construct(config $config, language $language, service_collection $search_backend_collection, user $user)
46    {
47        $this->config = $config;
48        $this->language = $language;
49        $this->search_backend_collection = $search_backend_collection;
50
51        parent::__construct($user);
52    }
53
54    /**
55     * Sets the command name and description
56     *
57     * @return void
58     */
59    protected function configure()
60    {
61        $this->setName('searchindex:list')
62            ->setDescription($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_LIST'));
63    }
64
65    /**
66     * Executes the command searchindex:list
67     *
68     * List all search backends.
69     *
70     * @param InputInterface  $input  The input stream used to get the options
71     * @param OutputInterface $output The output stream, used to print messages
72     *
73     * @return int 0 if all is well, 1 if any errors occurred
74     */
75    protected function execute(InputInterface $input, OutputInterface $output): int
76    {
77        $io = new SymfonyStyle($input, $output);
78
79        $search_backends = [];
80        foreach ($this->search_backend_collection as $search_backend)
81        {
82            $name = $search_backend->get_type();
83            $active = ($name === $this->config['search_type']) ? '(<comment>' . $this->language->lang('ACTIVE') . '</comment>) ' : '';
84            $search_backends[] = '<info>' . $name . '</info> ' . $active .  $search_backend->get_name();
85
86            if ($name === $this->config['search_type'] && !$search_backend->index_created())
87            {
88                $io->error($this->language->lang('CLI_SEARCHINDEX_ACTIVE_NOT_INDEXED'));
89            }
90        }
91
92        $io->listing($search_backends);
93
94        return symfony_command::SUCCESS;
95    }
96}