diff --git a/bootstrap.php b/bootstrap.php index 50f51dc..fd2877c 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -3,6 +3,7 @@ use NewfoldLabs\WP\Module\Migration\Migration; use NewfoldLabs\WP\Module\Migration\Services\UtilityService; use NewfoldLabs\WP\ModuleLoader\Container; +use function NewfoldLabs\WP\Context\getContext; use function NewfoldLabs\WP\ModuleLoader\register; @@ -24,12 +25,15 @@ function () { if ( ! defined( 'NFD_MIGRATION_MODULE_VERSION' ) ) { define( 'NFD_MIGRATION_MODULE_VERSION', '1.0.0' ); } - + $brand = $container->plugin()->id; + if ( 'atomic' === getContext( 'platform' ) ) { + $brand = 'bh-cloud'; + } defined( 'NFD_PROXY_ACCESS_WORKER' ) || define( 'NFD_PROXY_ACCESS_WORKER', 'https://hiive.cloud/workers/migration-token-proxy' ); - $response = UtilityService::get_insta_api_key(); + $response = UtilityService::get_insta_api_key( $brand ); defined( 'INSTAWP_API_KEY' ) || define( 'INSTAWP_API_KEY', $response ); defined( 'INSTAWP_API_DOMAIN' ) || define( 'INSTAWP_API_DOMAIN', 'https://app.instawp.io' ); - defined( 'INSTAWP_MIGRATE_ENDPOINT' ) || define( 'INSTAWP_MIGRATE_ENDPOINT', 'migrate/bluehost' ); + defined( 'INSTAWP_MIGRATE_ENDPOINT' ) || define( 'INSTAWP_MIGRATE_ENDPOINT', 'migrate/' . $brand ); new Migration( $container ); }, diff --git a/includes/Migration.php b/includes/Migration.php index dfe0caa..d9df076 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -43,6 +43,7 @@ public function __construct( Container $container ) { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_action( 'pre_update_option_nfd_migrate_site', array( $this, 'on_update_nfd_migrate_site' ) ); + add_action( 'pre_update_option_instawp_last_migration_details', array( $this, 'on_update_instawp_last_migration_details' ), 10, 1 ); } /** @@ -61,4 +62,17 @@ public function register_routes() { public function on_update_nfd_migrate_site() { $response = $this->insta_service->install_instawp_connect(); } + + /** + * Updates showMigrationSteps option based on instawp_last_migration_details + * + * @param array $new_option status of migration + */ + public function on_update_instawp_last_migration_details( $new_option ) { + $value_updated = $new_option['status']; + if ( 'completed' === $value_updated ) { + update_option( 'showMigrationSteps', true ); + } + return $new_option; + } } diff --git a/includes/Services/UtilityService.php b/includes/Services/UtilityService.php index 8e7bfcc..17d907f 100644 --- a/includes/Services/UtilityService.php +++ b/includes/Services/UtilityService.php @@ -7,9 +7,11 @@ class UtilityService { /** * Get the api key from worker + * + * @param string $brand name of the brand */ - public static function get_insta_api_key() { - $insta_cf_worker = NFD_PROXY_ACCESS_WORKER . '/get/token?access_token=BH_MIGRATION_API_KEY'; + public static function get_insta_api_key( $brand ) { + $insta_cf_worker = NFD_PROXY_ACCESS_WORKER . '/get/token?brand=' . $brand; $insta_cf_data = wp_remote_get( $insta_cf_worker, array(