Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ConnectToInstaWp | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
| run | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
30 | |||
| success | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Migration\Steps; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\Migration\Steps\AbstractStep; |
| 6 | use InstaWP\Connect\Helpers\Helper; |
| 7 | |
| 8 | /** |
| 9 | * Connection to InstaWp step. |
| 10 | * |
| 11 | * @package wp-module-migration |
| 12 | */ |
| 13 | class ConnectToInstaWp extends AbstractStep { |
| 14 | /** |
| 15 | * InstaWP Connect plugin API key used for connecting the instaWP plugin |
| 16 | * |
| 17 | * @var $insta_api_key |
| 18 | */ |
| 19 | private $insta_api_key = ''; |
| 20 | |
| 21 | /** |
| 22 | * The current brand/plugin identifier, used when sending the white-label slug to InstaWP. |
| 23 | * Defaults to 'bluehost' if the BRAND_PLUGIN constant is not defined. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | public $brand = ''; |
| 28 | |
| 29 | /** |
| 30 | * Construct. Init basic parameters. |
| 31 | * |
| 32 | * @param string $insta_api_key instawp api key. |
| 33 | */ |
| 34 | public function __construct( $insta_api_key ) { |
| 35 | $this->set_step_slug( 'ConnectToInstaWp' ); |
| 36 | $this->set_max_retries( 2 ); |
| 37 | $this->insta_api_key = $insta_api_key; |
| 38 | if ( defined( 'BRAND_PLUGIN' ) ) { |
| 39 | $this->brand = BRAND_PLUGIN; |
| 40 | } elseif ( |
| 41 | defined( 'NFD_MIGRATION_BRAND_WHITELIST' ) |
| 42 | && is_array( NFD_MIGRATION_BRAND_WHITELIST ) |
| 43 | && ! empty( NFD_MIGRATION_BRAND_WHITELIST ) |
| 44 | ) { |
| 45 | $whitelist = NFD_MIGRATION_BRAND_WHITELIST; |
| 46 | $this->brand = $whitelist[0]; |
| 47 | } else { |
| 48 | $this->brand = 'bluehost'; |
| 49 | } |
| 50 | $this->set_status( $this->statuses['running'] ); |
| 51 | $this->run(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Execute the step. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | protected function run() { |
| 60 | if ( empty( Helper::get_api_key() ) || empty( Helper::get_connect_id() ) ) { |
| 61 | $api_key = Helper::get_api_key( false, $this->insta_api_key ); |
| 62 | $connect_response = Helper::instawp_generate_api_key( |
| 63 | $api_key, |
| 64 | '', |
| 65 | array( |
| 66 | 'e2e_mig_push_request' => true, |
| 67 | 'wlm_slug' => $this->brand, |
| 68 | 'managed' => false, |
| 69 | ) |
| 70 | ); |
| 71 | if ( ! $connect_response ) { |
| 72 | delete_option( 'instawp_api_key' ); |
| 73 | if ( ! $this->retry() ) { |
| 74 | $this->set_response( |
| 75 | array( |
| 76 | 'message' => esc_html__( 'Website could not connect successfully.', 'wp-module-migration' ), |
| 77 | ), |
| 78 | ); |
| 79 | } |
| 80 | } else { |
| 81 | $this->success(); |
| 82 | } |
| 83 | } else { |
| 84 | $this->success(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Set the step as successful and store the API key. |
| 90 | * |
| 91 | * @return void |
| 92 | */ |
| 93 | protected function success() { |
| 94 | parent::success(); |
| 95 | |
| 96 | $this->set_data( 'ApiKey', Helper::get_api_key() ); |
| 97 | } |
| 98 | } |