Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
86.49% |
32 / 37 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
ProfilesDump | |
86.49% |
32 / 37 |
|
60.00% |
3 / 5 |
13.42 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
execute | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
8 | |||
getAllowedParams | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Api; |
4 | |
5 | use CirrusSearch\Profile\SearchProfileOverride; |
6 | use CirrusSearch\Profile\SearchProfileService; |
7 | use MediaWiki\Api\ApiBase; |
8 | use MediaWiki\Api\ApiMain; |
9 | use Wikimedia\ParamValidator\ParamValidator; |
10 | |
11 | /** |
12 | * Dumps CirrusSearch profiles for easy viewing. |
13 | * |
14 | * This program is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2 of the License, or |
17 | * (at your option) any later version. |
18 | * |
19 | * This program is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License along |
25 | * with this program; if not, write to the Free Software Foundation, Inc., |
26 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
27 | * http://www.gnu.org/copyleft/gpl.html |
28 | */ |
29 | class ProfilesDump extends ApiBase { |
30 | use ApiTrait; |
31 | |
32 | private SearchProfileService $service; |
33 | |
34 | public function __construct( ApiMain $mainModule, string $moduleName, ?SearchProfileService $service = null ) { |
35 | parent::__construct( $mainModule, $moduleName ); |
36 | $this->service = $service ?: $this->getSearchConfig()->getProfileService(); |
37 | } |
38 | |
39 | public function execute() { |
40 | $service = $this->service; |
41 | $verbose = $this->getParameter( 'verbose' ); |
42 | $contexts = []; |
43 | foreach ( $service->listProfileTypes() as $type ) { |
44 | foreach ( $service->listProfileRepositories( $type ) as $repository ) { |
45 | $this->getResult()->addValue( [ 'profiles', $repository->repositoryType(), 'repositories' ], $repository->repositoryName(), |
46 | $verbose ? $repository->listExposedProfiles() : array_keys( $repository->listExposedProfiles() ) ); |
47 | } |
48 | foreach ( $service->listProfileContexts( $type ) as $context => $default ) { |
49 | $this->getResult()->addValue( [ 'profiles', $type, 'contexts', $context ], 'code_default', $default ); |
50 | $this->getResult()->addValue( [ 'profiles', $type, 'contexts', $context ], 'actual_default', |
51 | $service->getProfileName( $type, $context, [] ) ); |
52 | $overriders = $service->listProfileOverrides( $type, $context ); |
53 | usort( $overriders, static function ( SearchProfileOverride $a, SearchProfileOverride $b ) { |
54 | return $a->priority() <=> $b->priority(); |
55 | } ); |
56 | $overriders = array_map( static function ( SearchProfileOverride $o ) { |
57 | return $o->explain(); |
58 | }, $overriders ); |
59 | $this->getResult()->addValue( [ 'profiles', $type, 'contexts', $context ], 'overriders', $overriders ); |
60 | if ( !isset( $contexts[$context] ) ) { |
61 | $contexts[$context] = []; |
62 | } |
63 | $contexts[$context][] = $type; |
64 | } |
65 | } |
66 | |
67 | foreach ( $contexts as $context => $types ) { |
68 | foreach ( $types as $type ) { |
69 | $this->getResult()->addValue( [ 'contexts', $context ], $type, $service->getProfileName( $type, $context, [] ) ); |
70 | } |
71 | } |
72 | } |
73 | |
74 | /** @inheritDoc */ |
75 | public function getAllowedParams() { |
76 | return [ |
77 | 'verbose' => [ |
78 | ParamValidator::PARAM_DEFAULT => false, |
79 | ], |
80 | ]; |
81 | } |
82 | |
83 | /** |
84 | * Mark as internal. This isn't meant to be used by normal api users |
85 | * @return bool |
86 | */ |
87 | public function isInternal() { |
88 | return true; |
89 | } |
90 | |
91 | /** |
92 | * @see ApiBase::getExamplesMessages |
93 | * @return array |
94 | */ |
95 | protected function getExamplesMessages() { |
96 | return [ |
97 | 'action=cirrus-profiles-dump' => |
98 | 'apihelp-cirrus-profiles-dump-example' |
99 | ]; |
100 | } |
101 | |
102 | } |