Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
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 / 26
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 / 23
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 MediaWiki\Actions\FormlessAction;
6use MediaWiki\MediaWikiServices;
7
8/**
9 * action=cirrusDump handler.  Dumps contents of Elasticsearch indexes for the
10 * page.
11 *
12 * @license GPL-2.0-or-later
13 */
14class Dump extends FormlessAction {
15    /** @inheritDoc */
16    public function onView() {
17        // Disable regular results
18        $this->getOutput()->disable();
19
20        $response = $this->getRequest()->response();
21        $response->header( 'Content-type: application/json; charset=UTF-8' );
22
23        $config = MediaWikiServices::getInstance()
24            ->getConfigFactory()
25            ->makeConfig( CirrusSearch::NAME );
26        /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */
27        $conn = new Connection( $config );
28        /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */
29        $searcher = new Searcher( $conn, 0, 0, $config, [], $this->getUser() );
30
31        /** @phan-suppress-next-line PhanUndeclaredMethod Phan doesn't know $config is a SearchConfig */
32        $docId = $config->makeId( $this->getTitle()->getArticleID() );
33        $esSources = $searcher->get( [ $docId ], true );
34        if ( !$esSources->isOK() ) {
35            // echo for consistency with below
36            echo '{"error": "exception has been logged"}';
37            return null;
38        }
39
40        $result = [];
41        foreach ( $esSources->getValue() as $esResult ) {
42            $result[] = [
43                '_index' => $esResult->getIndex(),
44                '_id' => $esResult->getId(),
45                '_version' => $esResult->getVersion(),
46                '_source' => $esResult->getData(),
47            ];
48        }
49        // Echoing raw json to avoid any mangling that would prevent providing
50        // the resulting structures to elasticsearch.
51        echo json_encode( $result );
52        return null;
53    }
54
55    /**
56     * @return string
57     */
58    public function getName() {
59        return 'cirrusdump';
60    }
61
62    /**
63     * @return bool
64     */
65    public function requiresWrite() {
66        return false;
67    }
68
69    /**
70     * @return bool
71     */
72    public function requiresUnblock() {
73        return false;
74    }
75}