Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the show MIgration key on completed status #6

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 );
},
Expand Down
14 changes: 14 additions & 0 deletions includes/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand All @@ -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;
}
}
6 changes: 4 additions & 2 deletions includes/Services/UtilityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading