| @@ -7,11 +7,11 @@ | ||
| 7 | 7 | use WP_CLI\ExitException; |
| 8 | 8 | use WP_CLI\Utils; |
| 9 | 9 | use Yoast\WP\SEO\Commands\Command_Interface; |
| 10 | 10 | use Yoast\WP\SEO\Conditionals\MyYoast_Connection_Conditional; |
| 11 | -use Yoast\WP\SEO\General\User_Interface\General_Page_Integration; | |
| 12 | 11 | use Yoast\WP\SEO\Loadable_Interface; |
| 13 | 12 | use Yoast\WP\SEO\Main; |
| 13 | +use Yoast\WP\SEO\MyYoast_Client\Application\Exceptions\Registration_Temporarily_Unavailable_Exception; | |
| 14 | 14 | use Yoast\WP\SEO\MyYoast_Client\Application\MyYoast_Client; |
| 15 | 15 | use Yoast\WP\SEO\MyYoast_Client\Application\MyYoast_Client_Cleanup; |
| 16 | 16 | use Yoast\WP\SEO\MyYoast_Client\Application\Ports\Client_Registration_Interface; |
| 17 | 17 | use Yoast\WP\SEO\MyYoast_Client\Application\Ports\Token_Storage_Interface; |
| @@ -248,10 +248,14 @@ | ||
| 248 | 248 | WP_CLI::log( 'Deregistered existing client.' ); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | try { |
| 252 | - $redirect_uri = \get_admin_url( null, 'admin.php?page=' . General_Page_Integration::PAGE . '&yoast_myyoast_oauth_callback=1' ); | |
| 253 | - $client = $this->myyoast_client->ensure_registered( [ $redirect_uri ] ); | |
| 252 | + $client = $this->myyoast_client->ensure_registered(); | |
| 253 | + } catch ( Registration_Temporarily_Unavailable_Exception $e ) { | |
| 254 | + $retry_after = $e->get_retry_after_seconds(); | |
| 255 | + $retry_hint = ( $retry_after !== null ) ? \sprintf( ' Try again in %d seconds.', $retry_after ) : ' Try again later.'; | |
| 256 | + WP_CLI::error( 'Registration is temporarily unavailable.' . $retry_hint ); | |
| 257 | + return; | |
| 254 | 258 | } catch ( Exception $e ) { |
| 255 | 259 | WP_CLI::error( 'Registration failed: ' . $e->getMessage() ); |
| 256 | 260 | return; |
| 257 | 261 | } |
| @@ -267,9 +271,9 @@ | ||
| 267 | 271 | WP_CLI::success( 'Client registered: ' . $client->get_client_id() ); |
| 268 | 272 | } |
| 269 | 273 | |
| 270 | 274 | /** |
| 271 | - * Verifies the client registration with the server. | |
| 275 | + * Refreshes the client registration status against the server. | |
| 272 | 276 | * |
| 273 | 277 | * Reads the current registration from the authorization server to |
| 274 | 278 | * confirm it is still valid and shows the registration metadata. |
| 275 | 279 | * |
| @@ -285,11 +289,13 @@ | ||
| 285 | 289 | * --- |
| 286 | 290 | * |
| 287 | 291 | * ## EXAMPLES |
| 288 | 292 | * |
| 289 | - * wp yoast auth verify | |
| 290 | - * wp yoast auth verify --format=json | |
| 293 | + * wp yoast auth refresh-status | |
| 294 | + * wp yoast auth refresh-status --format=json | |
| 291 | 295 | * |
| 296 | + * @subcommand refresh-status | |
| 297 | + * | |
| 292 | 298 | * @when after_wp_load |
| 293 | 299 | * |
| 294 | 300 | * @param array<int, string>|null $args The arguments. |
| 295 | 301 | * @param array<string, string>|null $assoc_args The associative arguments. |
| @@ -295,19 +301,19 @@ | ||
| 295 | 301 | * @param array<string, string>|null $assoc_args The associative arguments. |
| 296 | 302 | * |
| 297 | 303 | * @return void |
| 298 | 304 | * |
| 299 | - * @throws ExitException When verification fails. | |
| 305 | + * @throws ExitException When the status refresh fails. | |
| 300 | 306 | */ |
| 301 | - public function verify( $args = null, $assoc_args = null ): void { | |
| 307 | + public function refresh_status( $args = null, $assoc_args = null ): void { | |
| 302 | 308 | if ( ! $this->myyoast_client->is_registered() ) { |
| 303 | 309 | WP_CLI::error( 'Not registered. Run "wp yoast auth register" first.' ); |
| 304 | 310 | } |
| 305 | 311 | |
| 306 | 312 | try { |
| 307 | - $metadata = $this->myyoast_client->verify_registration(); | |
| 313 | + $metadata = $this->myyoast_client->refresh_registration_status(); | |
| 308 | 314 | } catch ( Exception $e ) { |
| 309 | - WP_CLI::error( 'Verification failed: ' . $e->getMessage() ); | |
| 315 | + WP_CLI::error( 'Status refresh failed: ' . $e->getMessage() ); | |
| 310 | 316 | return; |
| 311 | 317 | } |
| 312 | 318 | |
| 313 | 319 | // Redact sensitive fields. |
| @@ -713,13 +719,15 @@ | ||
| 713 | 719 | if ( $code !== null || $state !== null ) { |
| 714 | 720 | WP_CLI::error( 'Both --code and --state are required for code exchange.' ); |
| 715 | 721 | } |
| 716 | 722 | |
| 717 | - // Phase 1: generate the authorization URL. | |
| 718 | - $redirect_uri = \get_admin_url( null, 'admin.php?page=' . General_Page_Integration::PAGE . '&yoast_myyoast_oauth_callback=1' ); | |
| 723 | + // Phase 1: generate the authorization URL. Registration is a prerequisite. | |
| 724 | + if ( ! $this->myyoast_client->is_registered() ) { | |
| 725 | + WP_CLI::error( 'Not registered. Run "wp yoast auth register" first.' ); | |
| 726 | + } | |
| 719 | 727 | |
| 720 | 728 | try { |
| 721 | - $url = $this->myyoast_client->get_authorization_url( $user_id, $redirect_uri, $scopes, $resource_indicator ); | |
| 729 | + $url = $this->myyoast_client->get_authorization_url( $user_id, $scopes, $resource_indicator ); | |
| 722 | 730 | } catch ( Exception $e ) { |
| 723 | 731 | WP_CLI::error( 'Failed to generate authorization URL: ' . $e->getMessage() ); |
| 724 | 732 | return; |
| 725 | 733 | } |