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