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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / cli / class-wc-cli-runner.php
woocommerce / includes / cli Last commit date
class-wc-cli-rest-command.php 8 years ago class-wc-cli-runner.php 8 years ago class-wc-cli-tool-command.php 8 years ago class-wc-cli-update-command.php 7 years ago
class-wc-cli-runner.php
262 lines
1 <?php
2 /**
3 * WP_CLI_Runner class file.
4 *
5 * @package WooCommerce\CLI
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * WC API to WC CLI Bridge.
14 *
15 * Hooks into the REST API, figures out which endpoints come from WC,
16 * and registers them as CLI commands.
17 *
18 * Forked from wp-cli/restful (by Daniel Bachhuber, released under the MIT license https://opensource.org/licenses/MIT).
19 * https://github.com/wp-cli/restful
20 *
21 * @version 3.0.0
22 * @package WooCommerce
23 */
24 class WC_CLI_Runner {
25 /**
26 * Endpoints to disable (meaning they will not be available as CLI commands).
27 * Some of these can either be done via WP already, or are offered with
28 * some other changes (like tools).
29 *
30 * @var array
31 */
32 private static $disabled_endpoints = array(
33 'settings',
34 'settings/(?P<group_id>[\w-]+)',
35 'settings/(?P<group_id>[\w-]+)/batch',
36 'settings/(?P<group_id>[\w-]+)/(?P<id>[\w-]+)',
37 'system_status',
38 'system_status/tools',
39 'system_status/tools/(?P<id>[\w-]+)',
40 'reports',
41 'reports/sales',
42 'reports/top_sellers',
43 );
44
45 /**
46 * The version of the REST API we should target to
47 * generate commands.
48 *
49 * @var string
50 */
51 private static $target_rest_version = 'v2';
52
53 /**
54 * Register's all endpoints as commands once WP and WC have all loaded.
55 */
56 public static function after_wp_load() {
57 global $wp_rest_server;
58 $wp_rest_server = new WP_REST_Server();
59 do_action( 'rest_api_init', $wp_rest_server );
60
61 $request = new WP_REST_Request( 'GET', '/' );
62 $request->set_param( 'context', 'help' );
63 $response = $wp_rest_server->dispatch( $request );
64 $response_data = $response->get_data();
65 if ( empty( $response_data ) ) {
66 return;
67 }
68
69 // Loop through all of our endpoints and register any valid WC endpoints.
70 foreach ( $response_data['routes'] as $route => $route_data ) {
71 // Only register endpoints for WC and our target version.
72 if ( substr( $route, 0, 4 + strlen( self::$target_rest_version ) ) !== '/wc/' . self::$target_rest_version ) {
73 continue;
74 }
75
76 // Only register endpoints with schemas.
77 if ( empty( $route_data['schema']['title'] ) ) {
78 /* translators: %s: Route to a given WC-API endpoint */
79 WP_CLI::debug( sprintf( __( 'No schema title found for %s, skipping REST command registration.', 'woocommerce' ), $route ), 'wc' );
80 continue;
81 }
82 // Ignore batch endpoints.
83 if ( 'batch' === $route_data['schema']['title'] ) {
84 continue;
85 }
86 // Disable specific endpoints.
87 $route_pieces = explode( '/', $route );
88 $endpoint_piece = str_replace( '/wc/' . $route_pieces[2] . '/', '', $route );
89 if ( in_array( $endpoint_piece, self::$disabled_endpoints, true ) ) {
90 continue;
91 }
92
93 self::register_route_commands( new WC_CLI_REST_Command( $route_data['schema']['title'], $route, $route_data['schema'] ), $route, $route_data );
94 }
95 }
96
97 /**
98 * Generates command information and tells WP CLI about all
99 * commands available from a route.
100 *
101 * @param string $rest_command WC-API command.
102 * @param string $route Path to route endpoint.
103 * @param array $route_data Command data.
104 * @param array $command_args WP-CLI command arguments.
105 */
106 private static function register_route_commands( $rest_command, $route, $route_data, $command_args = array() ) {
107 // Define IDs that we are looking for in the routes (in addition to id)
108 // so that we can pass it to the rest command, and use it here to generate documentation.
109 $supported_ids = array(
110 'product_id' => __( 'Product ID.', 'woocommerce' ),
111 'customer_id' => __( 'Customer ID.', 'woocommerce' ),
112 'order_id' => __( 'Order ID.', 'woocommerce' ),
113 'refund_id' => __( 'Refund ID.', 'woocommerce' ),
114 'attribute_id' => __( 'Attribute ID.', 'woocommerce' ),
115 'zone_id' => __( 'Zone ID.', 'woocommerce' ),
116 'id' => __( 'ID.', 'woocommerce' ),
117 );
118 $rest_command->set_supported_ids( $supported_ids );
119 $positional_args = array_keys( $supported_ids );
120
121 $parent = "wc {$route_data['schema']['title']}";
122 $supported_commands = array();
123
124 // Get a list of supported commands for each route.
125 foreach ( $route_data['endpoints'] as $endpoint ) {
126 preg_match_all( '#\([^\)]+\)#', $route, $matches );
127 $resource_id = ! empty( $matches[0] ) ? array_pop( $matches[0] ) : null;
128 $trimmed_route = rtrim( $route );
129 $is_singular = substr( $trimmed_route, - strlen( $resource_id ) ) === $resource_id;
130
131 // List a collection.
132 if ( array( 'GET' ) === $endpoint['methods'] && ! $is_singular ) {
133 $supported_commands['list'] = ! empty( $endpoint['args'] ) ? $endpoint['args'] : array();
134 }
135 // Create a specific resource.
136 if ( array( 'POST' ) === $endpoint['methods'] && ! $is_singular ) {
137 $supported_commands['create'] = ! empty( $endpoint['args'] ) ? $endpoint['args'] : array();
138 }
139 // Get a specific resource.
140 if ( array( 'GET' ) === $endpoint['methods'] && $is_singular ) {
141 $supported_commands['get'] = ! empty( $endpoint['args'] ) ? $endpoint['args'] : array();
142 }
143 // Update a specific resource.
144 if ( in_array( 'POST', $endpoint['methods'], true ) && $is_singular ) {
145 $supported_commands['update'] = ! empty( $endpoint['args'] ) ? $endpoint['args'] : array();
146 }
147 // Delete a specific resource.
148 if ( array( 'DELETE' ) === $endpoint['methods'] && $is_singular ) {
149 $supported_commands['delete'] = ! empty( $endpoint['args'] ) ? $endpoint['args'] : array();
150 }
151 }
152
153 foreach ( $supported_commands as $command => $endpoint_args ) {
154 $synopsis = array();
155 $arg_regs = array();
156 $ids = array();
157
158 foreach ( $supported_ids as $id_name => $id_desc ) {
159 if ( strpos( $route, '<' . $id_name . '>' ) !== false ) {
160 $synopsis[] = array(
161 'name' => $id_name,
162 'type' => 'positional',
163 'description' => $id_desc,
164 'optional' => false,
165 );
166 $ids[] = $id_name;
167 }
168 }
169 if ( in_array( $command, array( 'delete', 'get', 'update' ), true ) && ! in_array( 'id', $ids, true ) ) {
170 $synopsis[] = array(
171 'name' => 'id',
172 'type' => 'positional',
173 'description' => __( 'The id for the resource.', 'woocommerce' ),
174 'optional' => false,
175 );
176 }
177
178 foreach ( $endpoint_args as $name => $args ) {
179 if ( ! in_array( $name, $positional_args, true ) || strpos( $route, '<' . $id_name . '>' ) === false ) {
180 $arg_regs[] = array(
181 'name' => $name,
182 'type' => 'assoc',
183 'description' => ! empty( $args['description'] ) ? $args['description'] : '',
184 'optional' => empty( $args['required'] ),
185 );
186 }
187 }
188
189 foreach ( $arg_regs as $arg_reg ) {
190 $synopsis[] = $arg_reg;
191 }
192
193 if ( in_array( $command, array( 'list', 'get' ), true ) ) {
194 $synopsis[] = array(
195 'name' => 'fields',
196 'type' => 'assoc',
197 'description' => __( 'Limit response to specific fields. Defaults to all fields.', 'woocommerce' ),
198 'optional' => true,
199 );
200 $synopsis[] = array(
201 'name' => 'field',
202 'type' => 'assoc',
203 'description' => __( 'Get the value of an individual field.', 'woocommerce' ),
204 'optional' => true,
205 );
206 $synopsis[] = array(
207 'name' => 'format',
208 'type' => 'assoc',
209 'description' => __( 'Render response in a particular format.', 'woocommerce' ),
210 'optional' => true,
211 'default' => 'table',
212 'options' => array(
213 'table',
214 'json',
215 'csv',
216 'ids',
217 'yaml',
218 'count',
219 'headers',
220 'body',
221 'envelope',
222 ),
223 );
224 }
225
226 if ( in_array( $command, array( 'create', 'update', 'delete' ), true ) ) {
227 $synopsis[] = array(
228 'name' => 'porcelain',
229 'type' => 'flag',
230 'description' => __( 'Output just the id when the operation is successful.', 'woocommerce' ),
231 'optional' => true,
232 );
233 }
234
235 $methods = array(
236 'list' => 'list_items',
237 'create' => 'create_item',
238 'delete' => 'delete_item',
239 'get' => 'get_item',
240 'update' => 'update_item',
241 );
242
243 $before_invoke = null;
244 if ( empty( $command_args['when'] ) && \WP_CLI::get_config( 'debug' ) ) {
245 $before_invoke = function() {
246 wc_maybe_define_constant( 'SAVEQUERIES', true );
247 };
248 }
249
250 WP_CLI::add_command(
251 "{$parent} {$command}",
252 array( $rest_command, $methods[ $command ] ),
253 array(
254 'synopsis' => $synopsis,
255 'when' => ! empty( $command_args['when'] ) ? $command_args['when'] : '',
256 'before_invoke' => $before_invoke,
257 )
258 );
259 }
260 }
261 }
262