From 292ffacf06b1b61fdc5122a8ce62d0531b6d69d1 Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Wed, 17 Jul 2024 15:47:00 +0530 Subject: [PATCH 1/3] added mfe_migration key --- includes/Migration.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/includes/Migration.php b/includes/Migration.php index 918ebd6..8b8daf5 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -33,6 +33,15 @@ class Migration { 'NewfoldLabs\\WP\\Module\\Migration\\RestApi\\MigrateController', ); + /** + * Option settings + * + * @var array + */ + protected $options = array( + 'nfd_migration_mfe_initiated' => 'boolean' + ); + /** * Migration constructor. * @@ -62,6 +71,7 @@ public function register_routes() { $rest_api = new $controller(); $rest_api->register_routes(); } + self::register_settings(); } /** @@ -72,6 +82,7 @@ public function register_routes() { public function on_update_nfd_migrate_site( $option ) { $this->insta_service = new InstaMigrateService(); $this->insta_service->install_instawp_connect(); + update_option( 'nfd_migration_mfe_initiated', true ); return $option; } @@ -87,4 +98,22 @@ public function on_update_instawp_last_migration_details( $new_option ) { } return $new_option; } + + /** + * Register settings. + */ + public function register_settings() { + foreach ( $this->options as $option => $type ) { + \register_setting( + 'general', + $option, + array( + 'show_in_rest' => true, + 'type' => $type, + 'description' => __( 'NFD migration Options', 'wp-module-migration' ), + ) + ); + } + + } } From 9b89e7dbfdc4775f29bbaaa9593922d52108d39c Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Wed, 17 Jul 2024 18:24:42 +0530 Subject: [PATCH 2/3] updating the way of returning the success --- includes/Migration.php | 3 +-- includes/RestApi/MigrateController.php | 5 ++++- includes/Services/InstaMigrateService.php | 4 +--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/Migration.php b/includes/Migration.php index 8b8daf5..d49f6f6 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -39,7 +39,7 @@ class Migration { * @var array */ protected $options = array( - 'nfd_migration_mfe_initiated' => 'boolean' + 'nfd_migrate_site' => 'boolean' ); /** @@ -82,7 +82,6 @@ public function register_routes() { public function on_update_nfd_migrate_site( $option ) { $this->insta_service = new InstaMigrateService(); $this->insta_service->install_instawp_connect(); - update_option( 'nfd_migration_mfe_initiated', true ); return $option; } diff --git a/includes/RestApi/MigrateController.php b/includes/RestApi/MigrateController.php index 2521ab4..77d04b5 100644 --- a/includes/RestApi/MigrateController.php +++ b/includes/RestApi/MigrateController.php @@ -51,7 +51,10 @@ public function connect_instawp() { $insta_service = new InstaMigrateService(); $response = $insta_service->install_instawp_connect(); - return $response; + if( is_wp_error( $response ) ){ + return $response; + } + return wp_send_json_success( $response ); } /** diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index e03a236..b23f060 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -76,12 +76,10 @@ public function install_instawp_connect() { return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) ); } - return wp_send_json_success( - array( + return array( 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), 'response' => true, 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), - ) ); } From 3ed504e5d3802b317b8efbae3f525c9af97126b5 Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Wed, 17 Jul 2024 18:35:46 +0530 Subject: [PATCH 3/3] linting fixes --- includes/Migration.php | 3 +-- includes/RestApi/MigrateController.php | 6 +++--- includes/Services/InstaMigrateService.php | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/includes/Migration.php b/includes/Migration.php index d49f6f6..2484617 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -39,7 +39,7 @@ class Migration { * @var array */ protected $options = array( - 'nfd_migrate_site' => 'boolean' + 'nfd_migrate_site' => 'boolean', ); /** @@ -113,6 +113,5 @@ public function register_settings() { ) ); } - } } diff --git a/includes/RestApi/MigrateController.php b/includes/RestApi/MigrateController.php index 77d04b5..ada9bd5 100644 --- a/includes/RestApi/MigrateController.php +++ b/includes/RestApi/MigrateController.php @@ -51,9 +51,9 @@ public function connect_instawp() { $insta_service = new InstaMigrateService(); $response = $insta_service->install_instawp_connect(); - if( is_wp_error( $response ) ){ - return $response; - } + if ( is_wp_error( $response ) ) { + return $response; + } return wp_send_json_success( $response ); } diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index b23f060..c0b6690 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -77,9 +77,9 @@ public function install_instawp_connect() { } return array( - 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), - 'response' => true, - 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), + 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), + 'response' => true, + 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), ); }