Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetInstaWpApiKey
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace NewfoldLabs\WP\Module\Migration\Steps;
4
5use NewfoldLabs\WP\Module\Migration\Steps\AbstractStep;
6use NewfoldLabs\WP\Module\Data\Helpers\Encryption;
7use NewfoldLabs\WP\Module\Migration\Services\UtilityService;
8
9/**
10 * Get InstaWp api key step.
11 *
12 * @package wp-module-migration
13 */
14class GetInstaWpApiKey extends AbstractStep {
15    /**
16     * InstaWP Connect plugin API key used for connecting the instaWP plugin
17     *
18     * @var $insta_api_key
19     */
20    private $insta_api_key = '';
21
22    /**
23     * Encryption instance
24     *
25     * @var NewfoldLabs\WP\Module\Data\Helpers\Encryption instance
26     */
27    protected $encrypter;
28
29    /**
30     * Construct. Init basic parameters.
31     */
32    public function __construct() {
33        $this->set_step_slug( 'GetInstaWpApiKey' );
34        $this->set_max_retries( 2 );
35        $this->encrypter = new Encryption();
36        $this->set_status( $this->statuses['running'] );
37        $this->run();
38    }
39
40    /**
41     * Execute the step.
42     *
43     * @return void
44     */
45    protected function run() {
46        $this->insta_api_key = $this->encrypter->decrypt( get_option( 'newfold_insta_api_key', false ) );
47        if ( ! $this->insta_api_key ) {
48            $this->insta_api_key = UtilityService::get_insta_api_key( BRAND_PLUGIN );
49            if ( $this->insta_api_key ) {
50                $this->set_data( 'insta_api_key', $this->insta_api_key );
51                update_option( 'newfold_insta_api_key', $this->encrypter->encrypt( $this->insta_api_key ) );
52                $this->success();
53            } else {
54                $this->retry();
55                $this->set_response(
56                    array(
57                        'message' => esc_html__( 'Cannot get Api key.', 'wp-module-migration' ),
58                    ),
59                );
60            }
61        } else {
62            $this->set_data( 'insta_api_key', $this->insta_api_key );
63            $this->success();
64        }
65    }
66}