Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
ThemeInstallTask | |
0.00% |
0 / 19 |
|
0.00% |
0 / 8 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
get_slug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_activate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_priority | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_retries | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
increment_retries | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
to_array | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | namespace NewfoldLabs\WP\Module\Installer\Tasks; |
3 | |
4 | use NewfoldLabs\WP\Module\Installer\Services\ThemeInstaller; |
5 | |
6 | /** |
7 | * Task for installing a Theme. |
8 | */ |
9 | class ThemeInstallTask extends Task { |
10 | |
11 | /** |
12 | * Theme Slug. |
13 | * |
14 | * @var string |
15 | */ |
16 | private $slug; |
17 | |
18 | /** |
19 | * Theme 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 | * ThemeInstallTask constructor |
41 | * |
42 | * @param string $slug The slug for the Theme. Ref: includes/Data/Themes.php for the slugs. |
43 | * @param boolean $activate A value of true activates the theme. |
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 Theme. |
56 | * |
57 | * @return string |
58 | */ |
59 | public function get_slug() { |
60 | return $this->slug; |
61 | } |
62 | |
63 | /** |
64 | * Retrieves Theme 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 Theme using the ThemeInstaller Service. |
101 | * |
102 | * @return \WP_REST_Response|WP_Error |
103 | */ |
104 | public function execute() { |
105 | return ThemeInstaller::install( |
106 | $this->get_slug(), |
107 | $this->get_activate() |
108 | ); |
109 | } |
110 | |
111 | /** |
112 | * Convert the ThemeInstallTask into an associative array. |
113 | * |
114 | * @return array |
115 | */ |
116 | public function to_array() { |
117 | return array( |
118 | 'slug' => $this->slug, |
119 | 'activate' => $this->activate, |
120 | 'priority' => $this->priority, |
121 | 'retries' => $this->retries, |
122 | ); |
123 | } |
124 | } |