WC_CLI_Tool_Command

Hooks up our system status tools to the CLI.

Defined (1)

The class is defined in the following location(s).

/includes/cli/class-wc-cli-tool-command.php  
  1. class WC_CLI_Tool_Command { 
  2.  
  3. /** 
  4. * Registers just a 'list' and 'run' command to the WC CLI 
  5. * since we only want to enable certain actions on the system status 
  6. * tools endpoints. 
  7. */ 
  8. public static function register_commands() { 
  9. global $wp_rest_server; 
  10.  
  11. $request = new WP_REST_Request( 'OPTIONS', '/wc/v1/system_status/tools' ); 
  12. $response = $wp_rest_server->dispatch( $request ); 
  13. $response_data = $response->get_data(); 
  14. if ( empty( $response_data ) ) { 
  15. return; 
  16.  
  17. $parent = "wc tool"; 
  18. $supported_commands = array( 'list', 'run' ); 
  19. foreach ( $supported_commands as $command ) { 
  20. $synopsis = array(); 
  21. if ( 'run' === $command ) { 
  22. $synopsis[] = array( 
  23. 'name' => 'id',  
  24. 'type' => 'positional',  
  25. 'description' => __( 'The id for the resource.', 'woocommerce' ),  
  26. 'optional' => false,  
  27. ); 
  28. $method = 'update_item'; 
  29. $route = '/wc/v1/system_status/tools/(?P<id>[\w-]+)'; 
  30. } elseif ( 'list' === $command ) { 
  31. $synopsis[] = array( 
  32. 'name' => 'fields',  
  33. 'type' => 'assoc',  
  34. 'description' => __( 'Limit response to specific fields. Defaults to all fields.', 'woocommerce' ),  
  35. 'optional' => true,  
  36. ); 
  37. $synopsis[] = array( 
  38. 'name' => 'field',  
  39. 'type' => 'assoc',  
  40. 'description' => __( 'Get the value of an individual field.', 'woocommerce' ),  
  41. 'optional' => true,  
  42. ); 
  43. $synopsis[] = array( 
  44. 'name' => 'format',  
  45. 'type' => 'assoc',  
  46. 'description' => __( 'Render response in a particular format.', 'woocommerce' ),  
  47. 'optional' => true,  
  48. 'default' => 'table',  
  49. 'options' => array( 
  50. 'table',  
  51. 'json',  
  52. 'csv',  
  53. 'ids',  
  54. 'yaml',  
  55. 'count',  
  56. 'headers',  
  57. 'body',  
  58. 'envelope',  
  59. ),  
  60. ); 
  61. $method = 'list_items'; 
  62. $route = '/wc/v1/system_status/tools'; 
  63.  
  64. $before_invoke = null; 
  65. if ( empty( $command_args['when'] ) && WP_CLI::get_config( 'debug' ) ) { 
  66. $before_invoke = function() { 
  67. if ( ! defined( 'SAVEQUERIES' ) ) { 
  68. define( 'SAVEQUERIES', true ); 
  69. }; 
  70.  
  71. $rest_command = new WC_CLI_REST_Command( 'system_status_tool', $route, $response_data['schema'] ); 
  72.  
  73. WP_CLI::add_command( "{$parent} {$command}", array( $rest_command, $method ), array( 
  74. 'synopsis' => $synopsis,  
  75. 'when' => ! empty( $command_args['when'] ) ? $command_args['when'] : '',  
  76. 'before_invoke' => $before_invoke,  
  77. ) ); 
  78.