Skip to content

Commit

Permalink
Merge pull request #45 from newfold-labs/fix/fetching_key_everytime
Browse files Browse the repository at this point in the history
Restricting calling of cf service everytime when website is loaded
  • Loading branch information
circlecube authored Jun 20, 2024
2 parents be8804c + b2a8ff8 commit a0b5df7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions includes/Listeners/Wonder_Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ 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() );
} elseif ( 'failed' === $value_updated ) {
$this->push( 'migration_failed', array() );
}
}

return $new_option;
}
}
11 changes: 7 additions & 4 deletions includes/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}

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

/**
Expand Down

0 comments on commit a0b5df7

Please sign in to comment.