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