Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Dump
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 onView
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
12
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 requiresWrite
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 requiresUnblock
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace CirrusSearch;
4
5use FormlessAction;
6use MediaWiki\MediaWikiServices;
7
8/**
9 * action=cirrusDump handler.  Dumps contents of Elasticsearch indexes for the
10 * page.
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 Dump extends FormlessAction {
28    public function onView() {
29        // Disable regular results
30        $this->getOutput()->disable();
31
32        $response = $this->getRequest()->response();
33        $response->header( 'Content-type: application/json; charset=UTF-8' );
34
35        $config = MediaWikiServices::getInstance()
36            ->getConfigFactory()
37            ->makeConfig( 'CirrusSearch' );
38        /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */
39        $conn = new Connection( $config );
40        /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */
41        $searcher = new Searcher( $conn, 0, 0, $config, [], $this->getUser() );
42
43        /** @phan-suppress-next-line PhanUndeclaredMethod Phan doesn't know $config is a SearchConfig */
44        $docId = $config->makeId( $this->getTitle()->getArticleID() );
45        $esSources = $searcher->get( [ $docId ], true );
46        if ( !$esSources->isOK() ) {
47            // Exception has been logged
48            echo '{}';
49            return null;
50        }
51        $esSources = $esSources->getValue();
52
53        $result = [];
54        foreach ( $esSources as $esSource ) {
55            $result[] = [
56                '_index' => $esSource->getIndex(),
57                '_type' => $esSource->getType(),
58                '_id' => $esSource->getId(),
59                '_version' => $esSource->getVersion(),
60                '_source' => $esSource->getData(),
61            ];
62        }
63        echo json_encode( $result );
64        return null;
65    }
66
67    /**
68     * @return string
69     */
70    public function getName() {
71        return 'cirrusdump';
72    }
73
74    /**
75     * @return bool
76     */
77    public function requiresWrite() {
78        return false;
79    }
80
81    /**
82     * @return bool
83     */
84    public function requiresUnblock() {
85        return false;
86    }
87}