Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
InstallActivateInstaWp
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
72
1<?php
2
3namespace NewfoldLabs\WP\Module\Migration\Steps;
4
5use NewfoldLabs\WP\Module\Migration\Steps\AbstractStep;
6use InstaWP\Connect\Helpers\Installer;
7
8/**
9 * Install and activate InstaWp step.
10 *
11 * @package wp-module-migration
12 */
13class InstallActivateInstaWp extends AbstractStep {
14
15    /**
16     * InstaWP Connect plugin slug used for installing the instaWP plugin once
17     *
18     * @var $connect_plugin_slug
19     */
20    private $connect_plugin_slug = 'instawp-connect';
21
22    /**
23     * Construct. Init basic parameters.
24     */
25    public function __construct() {
26        $this->set_step_slug( 'InstallInstaWp' );
27        $this->set_max_retries( 2 );
28        $this->set_status( $this->statuses['running'] );
29        $this->run();
30    }
31
32    /**
33     * Execute the step.
34     *
35     * @return void
36     */
37    protected function run() {
38        if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'get_mu_plugins' ) ) {
39            require_once ABSPATH . 'wp-admin/includes/plugin.php';
40        }
41        // Install and activate the plugin
42        if ( ! is_plugin_active( sprintf( '%1$s/%1$s.php', $this->connect_plugin_slug ) ) ) {
43            $params    = array(
44                array(
45                    'slug'     => 'instawp-connect',
46                    'type'     => 'plugin',
47                    'activate' => true,
48                ),
49            );
50            $installer = new Installer( $params );
51            $response  = $installer->start();
52
53            if ( $response[0]['success'] && function_exists( 'instawp' ) ) {
54                $this->success();
55            } else {
56                $this->retry();
57                $message = $response[0]['message'] ? $response[0]['message'] : __( 'Failed to install and activate the plugin', 'wp-module-migration' );
58                $this->set_response( array( 'message' => $message ) );
59            }
60        } else {
61            $this->success();
62        }
63
64        $plugin_data = get_plugin_data( sprintf( WP_PLUGIN_DIR . '/%1$s/%1$s.php', $this->connect_plugin_slug ) );
65        if ( ! empty( $plugin_data['Version'] ) ) {
66            $this->set_data( 'version', $plugin_data['Version'] );
67        }
68    }
69}