Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginInstallTask
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 8
72
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
 get_slug
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_activate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_priority
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_retries
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 increment_retries
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 to_array
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2namespace NewfoldLabs\WP\Module\Installer\Tasks;
3
4use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;
5
6/**
7 * Task for installing a Plugin.
8 */
9class PluginInstallTask extends Task {
10
11    /**
12     * Plugin Slug.
13     *
14     * @var string
15     */
16    private $slug;
17
18    /**
19     * Plugin Activation Status.
20     *
21     * @var boolean
22     */
23    private $activate;
24
25    /**
26     * Task Priority.
27     *
28     * @var int
29     */
30    private $priority;
31
32    /**
33     * Task Installation Retries Count.
34     *
35     * @var int
36     */
37    private $retries;
38
39    /**
40     * PluginInstallTask constructor
41     *
42     * @param string  $slug The slug for the Plugin. Ref: includes/Data/Plugins.php for the slugs.
43     * @param boolean $activate A value of true activates the plugin.
44     * @param int     $priority Priority of the task, higher the number higher the priority.
45     * @param int     $retries The number of times the Task has been retried
46     */
47    public function __construct( $slug, $activate, $priority = 0, $retries = 0 ) {
48        $this->slug     = $slug;
49        $this->activate = $activate;
50        $this->priority = $priority;
51        $this->retries  = $retries;
52    }
53
54    /**
55     * Retrieves Slug for the Plugin.
56     *
57     * @return string
58     */
59    public function get_slug() {
60        return $this->slug;
61    }
62
63    /**
64     * Retrieves Plugin Activation Status.
65     *
66     * @return boolean
67     */
68    public function get_activate() {
69        return $this->activate;
70    }
71
72    /**
73     * Retrieves Task Priority.
74     *
75     * @return int
76     */
77    public function get_priority() {
78        return $this->priority;
79    }
80
81    /**
82     * Retrieves Task Installation retry count.
83     *
84     * @return string
85     */
86    public function get_retries() {
87        return $this->retries;
88    }
89
90    /**
91     * Increments retry count.
92     *
93     * @return void
94     */
95    public function increment_retries() {
96        ++$this->retries;
97    }
98
99    /**
100     * Installs the Plugin using the PluginInstaller Service.
101     *
102     * @return \WP_REST_Response|WP_Error
103     */
104    public function execute() {
105        return PluginInstaller::install( $this->get_slug(), $this->get_activate() );
106    }
107
108    /**
109     * Convert the PluginInstallTask into an associative array.
110     *
111     * @return array
112     */
113    public function to_array() {
114        return array(
115            'slug'     => $this->slug,
116            'activate' => $this->activate,
117            'priority' => $this->priority,
118            'retries'  => $this->retries,
119        );
120    }
121}