From b2a8ff86f156855291781fb3964af5ee214819d1 Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Thu, 20 Jun 2024 10:53:54 +0530 Subject: [PATCH] avoiding calling of cf service everytime --- includes/Listeners/Wonder_Start.php | 5 +++-- includes/Migration.php | 11 +++++++---- includes/Services/InstaMigrateService.php | 9 +++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/includes/Listeners/Wonder_Start.php b/includes/Listeners/Wonder_Start.php index 181d55a..50ca6a7 100644 --- a/includes/Listeners/Wonder_Start.php +++ b/includes/Listeners/Wonder_Start.php @@ -20,9 +20,10 @@ public function register_hooks() { * Triggers events * * @param array $new_option status of migration + * @param array $old_value previous status of migration */ public function on_update_instawp_last_migration_details( $new_option, $old_value ) { - if( $old_value != $new_option ){ + if ( $old_value !== $new_option ) { $value_updated = $new_option['status']; if ( 'completed' === $value_updated ) { $this->push( 'migration_completed', array() ); @@ -30,7 +31,7 @@ public function on_update_instawp_last_migration_details( $new_option, $old_valu $this->push( 'migration_failed', array() ); } } - + return $new_option; } } diff --git a/includes/Migration.php b/includes/Migration.php index 893b5ca..4af8fb3 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -39,8 +39,7 @@ class Migration { * @param Container $container Container loaded from the brand plugin. */ public function __construct( Container $container ) { - $this->container = $container; - $this->insta_service = new InstaMigrateService(); + $this->container = $container; add_filter( 'newfold_data_listeners', @@ -67,9 +66,13 @@ public function register_routes() { /** * Triggers on instawp connect installation + * + * @param boolean $option status of migration */ - public function on_update_nfd_migrate_site() { - $response = $this->insta_service->install_instawp_connect(); + public function on_update_nfd_migrate_site( $option ) { + $this->insta_service = new InstaMigrateService(); + $this->insta_service->install_instawp_connect(); + return $option; } /** diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index 00227bf..e03a236 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -4,6 +4,7 @@ use InstaWP\Connect\Helpers\Helper; use InstaWP\Connect\Helpers\Installer; use NewfoldLabs\WP\Module\Migration\Services\UtilityService; +use NewfoldLabs\WP\Module\Data\Helpers\Encryption; /** * Class InstaMigrateService @@ -27,8 +28,12 @@ class InstaMigrateService { * Set required api keys for insta to initiate the migration */ public function __construct() { - // comment this out so we don't hammer the key service anymore - // $this->insta_api_key = UtilityService::get_insta_api_key( BRAND_PLUGIN ); + $encrypt = new Encryption(); + $this->insta_api_key = $encrypt->decrypt( get_option( 'newfold_insta_api_key', false ) ); + if ( ! $this->insta_api_key ) { + $this->insta_api_key = UtilityService::get_insta_api_key( BRAND_PLUGIN ); + update_option( 'newfold_insta_api_key', $encrypt->encrypt( $this->insta_api_key ) ); + } } /**