Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PluginsController | |
0.00% |
0 / 52 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
register_routes | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
2 | |||
initialize | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
get_site_features | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
activate_init_plugins | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | namespace NewfoldLabs\WP\Module\Onboarding\RestApi; |
3 | |
4 | use NewfoldLabs\WP\Module\Onboarding\Permissions; |
5 | use NewfoldLabs\WP\Module\Onboarding\Data\SiteFeatures; |
6 | use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller; |
7 | use NewfoldLabs\WP\Module\Onboarding\Services\PluginService; |
8 | |
9 | /** |
10 | * Class PluginsController |
11 | */ |
12 | class PluginsController { |
13 | /** |
14 | * The namespace of this controller's route. |
15 | * |
16 | * @var string |
17 | */ |
18 | protected $namespace = 'newfold-onboarding/v1'; |
19 | |
20 | /** |
21 | * The base of this controller's route. |
22 | * |
23 | * @var string |
24 | */ |
25 | protected $rest_base = '/plugins'; |
26 | |
27 | /** |
28 | * Registers rest routes for PluginsController class. |
29 | * |
30 | * @return void |
31 | */ |
32 | public function register_routes() { |
33 | |
34 | \register_rest_route( |
35 | $this->namespace, |
36 | $this->rest_base . '/initialize', |
37 | array( |
38 | array( |
39 | 'methods' => \WP_REST_Server::CREATABLE, |
40 | 'callback' => array( $this, 'initialize' ), |
41 | 'permission_callback' => array( PluginInstaller::class, 'check_install_permissions' ), |
42 | ), |
43 | ) |
44 | ); |
45 | |
46 | \register_rest_route( |
47 | $this->namespace, |
48 | $this->rest_base . '/initialize/activate', |
49 | array( |
50 | array( |
51 | 'methods' => \WP_REST_Server::CREATABLE, |
52 | 'callback' => array( $this, 'activate_init_plugins' ), |
53 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
54 | ), |
55 | ) |
56 | ); |
57 | |
58 | \register_rest_route( |
59 | $this->namespace, |
60 | $this->rest_base . '/site-features', |
61 | array( |
62 | array( |
63 | 'methods' => \WP_REST_Server::READABLE, |
64 | 'callback' => array( $this, 'get_site_features' ), |
65 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
66 | ), |
67 | ) |
68 | ); |
69 | } |
70 | |
71 | /** |
72 | * Queue in the initial list of plugins to be installed. |
73 | * |
74 | * @return \WP_REST_Response |
75 | */ |
76 | public function initialize() { |
77 | |
78 | if ( PluginService::initialize() ) { |
79 | return new \WP_REST_Response( |
80 | array(), |
81 | 202 |
82 | ); |
83 | } |
84 | |
85 | return new \WP_REST_Response( |
86 | array(), |
87 | 500 |
88 | ); |
89 | } |
90 | |
91 | /** |
92 | * Retrieves all the site features. |
93 | * |
94 | * @return array|\WP_Error |
95 | */ |
96 | public function get_site_features() { |
97 | return SiteFeatures::get_with_selections(); |
98 | } |
99 | |
100 | /** |
101 | * Activate the initial set of installed plugins. |
102 | * |
103 | * @return \WP_REST_Response |
104 | */ |
105 | public function activate_init_plugins() { |
106 | if ( PluginService::activate_init_plugins() ) { |
107 | return new \WP_REST_Response( |
108 | array(), |
109 | 202 |
110 | ); |
111 | } |
112 | |
113 | return new \WP_REST_Response( |
114 | array(), |
115 | 500 |
116 | ); |
117 | } |
118 | } |