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