From 7ab359574ba5a36d94c59e495194fa1932d84a3d Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Mon, 19 Aug 2024 16:27:34 +0530 Subject: [PATCH] changes --- includes/Services/InstaMigrateService.php | 12 ++++++-- includes/import-tools-changes.js | 35 +++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index c0b6690..a2a97bb 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -24,6 +24,8 @@ class InstaMigrateService { * @var $insta_api_key */ private $insta_api_key = ''; + + private $count = 0; /** * Set required api keys for insta to initiate the migration */ @@ -57,7 +59,7 @@ public function install_instawp_connect() { } // Connect the website with InstaWP server - if ( empty( Helper::get_api_key() ) ) { + if ( empty( Helper::get_api_key() ) || empty( Helper::get_connect_id() ) ) { $api_key = Helper::get_api_key( false, $this->insta_api_key ); $connect_response = Helper::instawp_generate_api_key( $api_key ); @@ -73,7 +75,13 @@ public function install_instawp_connect() { if ( function_exists( 'instawp' ) ) { // Check if there is a connect ID if ( empty( Helper::get_connect_id() ) ) { - return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) ); + if( $count < 2 ) { + $count++; + delete_option( 'instawp_api_options' ); + self::install_instawp_connect(); + } else { + return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) ); + } } return array( diff --git a/includes/import-tools-changes.js b/includes/import-tools-changes.js index 42ef3b1..d3a2b12 100644 --- a/includes/import-tools-changes.js +++ b/includes/import-tools-changes.js @@ -50,10 +50,41 @@ document.getElementById("wpbody-content").appendChild(node) window.open(res?.data?.redirect_url, "_self") } // else{ - // alert("please try again in sometime. Thanks!") + // document.getElementsByClassName("wrap")[0]; + // // alert("please try again in sometime. Thanks!") // } }) .catch(err => console.error(err)) }); - \ No newline at end of file + + + let params = new URLSearchParams(document.location.search); + let canMigrateSite = params.get("migrate"); + +if(canMigrateSite === "true"){ + console.log("helloo") + document.getElementById("migration-progress-modal").style.display = "flex"; + + fetch( + nfdplugin.restApiUrl + "/newfold-migration/v1/migrate/connect&_locale=user", + { + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json', + 'X-WP-Nonce': nfdplugin.restApiNonce, + }, + } + ) + .then((response) => response.json()) + .then(res => { + document.getElementById("migration-progress-modal").style.display = "none"; + if(res?.success){ + window.open(res?.data?.redirect_url, "_self") + } + // else{ + // document.getElementsByClassName("wrap")[0]; + // // alert("please try again in sometime. Thanks!") + // } + }) +} \ No newline at end of file