Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
MappingDump
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace CirrusSearch\Api;
4
5use CirrusSearch\Connection;
6use CirrusSearch\SearchConfig;
7use MediaWiki\Api\ApiBase;
8
9/**
10 * Dumps CirrusSearch mappings for easy viewing.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
26 */
27class MappingDump extends ApiBase {
28    use ApiTrait;
29
30    public function execute() {
31        $conn = $this->getCirrusConnection();
32        $indexPrefix = $this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME );
33        foreach ( $conn->getAllIndexSuffixes( null ) as $index ) {
34            $mapping = $conn->getIndex( $indexPrefix, $index )->getMapping();
35            $this->getResult()->addValue( null, $index, $mapping );
36        }
37        if ( $this->getSearchConfig()->isCompletionSuggesterEnabled() ) {
38            $index = $conn->getIndex( $indexPrefix, Connection::TITLE_SUGGEST_INDEX_SUFFIX );
39            if ( $index->exists() ) {
40                $mapping = $index->getMapping();
41                $this->getResult()->addValue( null, Connection::TITLE_SUGGEST_INDEX_SUFFIX, $mapping );
42            }
43        }
44    }
45
46    /** @inheritDoc */
47    public function getAllowedParams() {
48        return [];
49    }
50
51    /**
52     * Mark as internal. This isn't meant to be used by normal api users
53     * @return bool
54     */
55    public function isInternal() {
56        return true;
57    }
58
59    /**
60     * @see ApiBase::getExamplesMessages
61     * @return array
62     */
63    protected function getExamplesMessages() {
64        return [
65            'action=cirrus-mapping-dump' =>
66                'apihelp-cirrus-mapping-dump-example'
67        ];
68    }
69
70}