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

Code restructure #65

Closed
wants to merge 6 commits into from
Closed
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
46 changes: 13 additions & 33 deletions includes/Services/InstaMigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class InstaMigrateService {
/**
* Retry count
*
* @var $count
* @var int $count
*/
private $count = 0;

Expand Down Expand Up @@ -65,42 +65,22 @@ public function install_instawp_connect() {
}

// Connect the website with InstaWP server
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 );
if ( empty( Helper::get_connect_id() ) ) {
$connect_response = Helper::instawp_generate_api_key( $this->insta_api_key );

if ( ! $connect_response ) {
return new \WP_Error(
'Bad request',
esc_html__( 'Website could not connect successfully.' ),
array( 'status' => 400 )
);
}
}
// Ready to start the migration
if ( function_exists( 'instawp' ) ) {
// Check if there is a connect ID
if ( empty( Helper::get_connect_id() ) ) {
if ( $count < 2 ) {
$count++;
delete_option( 'instawp_api_options' );
if ( empty( Helper::get_connect_id() ) && $this->count < 3 ) {
++$this->count;
delete_option( 'instawp_api_options' ); // delete the connection to plugin and website
sleep( 1 );
self::install_instawp_connect();
} else {
return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) );
}
} else {
return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) );
}

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() ),
);
}

return new \WP_Error(
'Bad request',
esc_html__( 'Migration might be finished.' ),
array( 'status' => 400 )
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() ),
);
}
}
Loading