ListCommand.php
10 months ago
ProductsCommand.php
9 months ago
ResetCommand.php
9 months ago
SetupCommand.php
9 months ago
ResetCommand.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types=1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Internal\CLI\Migrator\Commands; |
| 6 | |
| 7 | use Automattic\WooCommerce\Internal\CLI\Migrator\Core\CredentialManager; |
| 8 | use Automattic\WooCommerce\Internal\CLI\Migrator\Core\PlatformRegistry; |
| 9 | use WP_CLI; |
| 10 | |
| 11 | /** |
| 12 | * The command for resetting platform credentials. |
| 13 | */ |
| 14 | class ResetCommand { |
| 15 | |
| 16 | /** |
| 17 | * The credential manager. |
| 18 | * |
| 19 | * @var CredentialManager |
| 20 | */ |
| 21 | private CredentialManager $credential_manager; |
| 22 | |
| 23 | /** |
| 24 | * The platform registry. |
| 25 | * |
| 26 | * @var PlatformRegistry |
| 27 | */ |
| 28 | private PlatformRegistry $platform_registry; |
| 29 | |
| 30 | /** |
| 31 | * Initialize the command with its dependencies. |
| 32 | * |
| 33 | * @param CredentialManager $credential_manager The credential manager. |
| 34 | * @param PlatformRegistry $platform_registry The platform registry. |
| 35 | * |
| 36 | * @internal |
| 37 | */ |
| 38 | final public function init( CredentialManager $credential_manager, PlatformRegistry $platform_registry ): void { |
| 39 | $this->credential_manager = $credential_manager; |
| 40 | $this->platform_registry = $platform_registry; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Resets (deletes) the credentials for a given platform. |
| 45 | * |
| 46 | * ## OPTIONS |
| 47 | * |
| 48 | * [--platform=<platform>] |
| 49 | * : The platform to reset credentials for. Defaults to 'shopify'. |
| 50 | * |
| 51 | * ## EXAMPLES |
| 52 | * |
| 53 | * wp wc migrate reset |
| 54 | * |
| 55 | * @param array $args Positional arguments. |
| 56 | * @param array $assoc_args Associative arguments. |
| 57 | */ |
| 58 | public function __invoke( array $args, array $assoc_args ) { |
| 59 | // Resolve and validate the platform. |
| 60 | $platform = $this->platform_registry->resolve_platform( $assoc_args ); |
| 61 | $platform_display_name = $this->platform_registry->get_platform_display_name( $platform ); |
| 62 | |
| 63 | if ( ! $this->credential_manager->has_credentials( $platform ) ) { |
| 64 | WP_CLI::warning( "No credentials found for '{$platform_display_name}' to reset." ); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | $this->credential_manager->delete_credentials( $platform ); |
| 69 | |
| 70 | WP_CLI::success( "Credentials for the '{$platform_display_name}' platform have been cleared." ); |
| 71 | } |
| 72 | } |
| 73 |