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

Restricting calling of cf service everytime when website is loaded #45

Merged
merged 1 commit into from
Jun 20, 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
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
Loading