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