Commands
9 months ago
Core
5 days ago
Interfaces
9 months ago
Lib
5 months ago
Platforms
5 days ago
Runner.php
5 days ago
Runner.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types=1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Internal\CLI\Migrator; |
| 6 | |
| 7 | use Automattic\WooCommerce\Internal\CLI\Migrator\Commands\ProductsCommand; |
| 8 | use Automattic\WooCommerce\Internal\CLI\Migrator\Commands\ResetCommand; |
| 9 | use Automattic\WooCommerce\Internal\CLI\Migrator\Commands\SetupCommand; |
| 10 | use Automattic\WooCommerce\Internal\CLI\Migrator\Commands\ListCommand; |
| 11 | use Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify\ShopifyPlatform; |
| 12 | use Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow\WebflowPlatform; |
| 13 | use WP_CLI; |
| 14 | use WC_Product_Factory; |
| 15 | |
| 16 | /** |
| 17 | * The main runner for the migrator. |
| 18 | */ |
| 19 | final class Runner { |
| 20 | |
| 21 | /** |
| 22 | * Register the commands for the migrator. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public static function register_commands(): void { |
| 27 | // Initialize built-in platforms. |
| 28 | self::init_platforms(); |
| 29 | |
| 30 | $container = wc_get_container(); |
| 31 | |
| 32 | WP_CLI::add_command( |
| 33 | 'wc migrate products', |
| 34 | $container->get( ProductsCommand::class ), |
| 35 | array( |
| 36 | 'shortdesc' => 'Migrate products from a source platform to WooCommerce.', |
| 37 | 'longdesc' => 'Migrate products from a source platform to WooCommerce. The migrator will fetch products from the source platform, map them to the WooCommerce product schema, and then import them into WooCommerce.', |
| 38 | ) |
| 39 | ); |
| 40 | |
| 41 | WP_CLI::add_command( |
| 42 | 'wc migrate reset', |
| 43 | $container->get( ResetCommand::class ), |
| 44 | array( |
| 45 | 'shortdesc' => 'Resets (deletes) the credentials for a given platform.', |
| 46 | ) |
| 47 | ); |
| 48 | |
| 49 | WP_CLI::add_command( |
| 50 | 'wc migrate setup', |
| 51 | $container->get( SetupCommand::class ), |
| 52 | array( |
| 53 | 'shortdesc' => 'Interactively sets up the credentials for a given platform.', |
| 54 | ) |
| 55 | ); |
| 56 | |
| 57 | WP_CLI::add_command( |
| 58 | 'wc migrate list', |
| 59 | $container->get( ListCommand::class ), |
| 60 | array( |
| 61 | 'shortdesc' => 'Lists all registered migration platforms.', |
| 62 | ) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Initialize built-in migration platforms. |
| 68 | * |
| 69 | * @return void |
| 70 | */ |
| 71 | private static function init_platforms(): void { |
| 72 | ShopifyPlatform::init(); |
| 73 | WebflowPlatform::init(); |
| 74 | } |
| 75 | } |
| 76 |