Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SetClientTierName | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\OAuthRateLimiter; |
4 | |
5 | use Maintenance; |
6 | use MediaWiki\Extension\OAuth\Repository\ClientRepository; |
7 | use MediaWiki\MediaWikiServices; |
8 | |
9 | $IP = getenv( 'MW_INSTALL_PATH' ); |
10 | if ( $IP === false ) { |
11 | $IP = __DIR__ . '/../../..'; |
12 | } |
13 | require_once "$IP/maintenance/Maintenance.php"; |
14 | |
15 | /** |
16 | * Example: |
17 | * |
18 | * setClientTierName.php |
19 | * --client=8b8d1cb5a0d62029dd0051a9e |
20 | * --tier="Tier 1" |
21 | * |
22 | * @ingroup Maintenance |
23 | */ |
24 | class SetClientTierName extends Maintenance { |
25 | |
26 | public function __construct() { |
27 | parent::__construct(); |
28 | $this->addDescription( "Add/Update tier name for a client" ); |
29 | $this->addOption( 'client', 'Client id of the user', true, true ); |
30 | $this->addOption( 'tier', 'Tier name to add to database', true, true ); |
31 | |
32 | $this->requireExtension( 'OAuthRateLimiter' ); |
33 | } |
34 | |
35 | public function execute() { |
36 | global $wgOAuthRateLimiterTierConfig; |
37 | |
38 | $clientID = $this->getOption( 'client' ); |
39 | $tierName = $this->getOption( 'tier' ); |
40 | |
41 | if ( !array_key_exists( $tierName, $wgOAuthRateLimiterTierConfig ) ) { |
42 | $this->fatalError( "$tierName must be set in wgOAuthRateLimiterTierConfig" ); |
43 | } |
44 | |
45 | $services = MediaWikiServices::getInstance(); |
46 | |
47 | // Check if $clientID is valid |
48 | $clientRepository = new ClientRepository(); |
49 | $res = $clientRepository->getClientEntity( $clientID ); |
50 | |
51 | if ( $res ) { |
52 | $clientTierStore = $services->getService( 'OAuthRateLimiterClientTierStore' ); |
53 | $bool = $clientTierStore->setClientTierName( $clientID, $tierName ); |
54 | |
55 | if ( $bool ) { |
56 | $this->output( "Successfully added tier $tierName for $clientID. \n" ); |
57 | } else { |
58 | $this->output( "Error adding $tierName for $clientID. \n" ); |
59 | } |
60 | } else { |
61 | $this->fatalError( "$clientID is not a valid client id" ); |
62 | } |
63 | } |
64 | } |
65 | |
66 | $maintClass = SetClientTierName::class; |
67 | require_once RUN_MAINTENANCE_IF_MAIN; |