Automattic\WooCommerce\Internal\CLI\Migrator\Core

ProductsController::create_new_sessionprivateWC 1.0

Create a new import session.

Method of the class: ProductsController{}

No Hooks.

Returns

ImportSession|null. New session instance or null on error.

Usage

// private - for code of main (parent) class only
$result = $this->create_new_session( $parsed_args ): ?ImportSession;
$parsed_args(array) (required)
Parsed command arguments.

ProductsController::create_new_session() code WC 10.8.1

private function create_new_session( array $parsed_args ): ?ImportSession {
	try {
		$session = ImportSession::create(
			array(
				'data_source' => $parsed_args['platform'],
				'file_name'   => sprintf(
					'%s Migration - %s',
					ucfirst( $parsed_args['platform'] ),
					current_time( 'mysql' )
				),
			)
		);

		$session->set_original_arguments( $parsed_args );

		return $session;

	} catch ( Exception $e ) {
		WP_CLI::error( sprintf( 'Failed to create migration session: %s', $e->getMessage() ) );
		return null;
	}
}