Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| validate_input | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| delete | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| result | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * API endpoint /sites/%s/delete-backup-helper-script |
| 4 | * This API endpoint deletes a Jetpack Backup Helper Script |
| 5 | * |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Backup\V0005\Helper_Script_Manager; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 0 ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * API endpoint /sites/%s/delete-backup-helper-script |
| 17 | * This API endpoint deletes a Jetpack Backup Helper Script |
| 18 | * |
| 19 | * @phan-constructor-used-for-side-effects |
| 20 | */ |
| 21 | class Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 22 | /** |
| 23 | * This endpoint is only accessible from Jetpack Backup; it requires no further capabilities. |
| 24 | * |
| 25 | * @var array |
| 26 | */ |
| 27 | protected $needed_capabilities = array(); |
| 28 | |
| 29 | /** |
| 30 | * Method to call when running this endpoint (delete) |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $action = 'delete'; |
| 35 | |
| 36 | /** |
| 37 | * Local path to the Helper Script to delete. |
| 38 | * |
| 39 | * @var string|null |
| 40 | */ |
| 41 | protected $script_path = null; |
| 42 | |
| 43 | /** |
| 44 | * An array with 'success' => true if the specified file has been successfully deleted, or an instance of WP_Error. |
| 45 | * |
| 46 | * @var array|WP_Error |
| 47 | */ |
| 48 | protected $result; |
| 49 | |
| 50 | /** |
| 51 | * Checks that the input args look like a valid Helper Script path. |
| 52 | * |
| 53 | * @param null $object Unused. |
| 54 | * @return bool|WP_Error a WP_Error object or true if the input seems ok. |
| 55 | */ |
| 56 | protected function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 57 | $args = $this->input(); |
| 58 | |
| 59 | if ( ! isset( $args['path'] ) ) { |
| 60 | return new WP_Error( 'invalid_args', __( 'You must specify a helper script path', 'jetpack' ), 400 ); |
| 61 | } |
| 62 | |
| 63 | $this->script_path = $args['path']; |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Deletes the specified Helper Script. |
| 69 | */ |
| 70 | protected function delete() { |
| 71 | $delete_result = Helper_Script_Manager::delete_helper_script( $this->script_path ); |
| 72 | Helper_Script_Manager::cleanup_expired_helper_scripts(); |
| 73 | |
| 74 | if ( is_wp_error( $delete_result ) ) { |
| 75 | $this->result = $delete_result; |
| 76 | } else { |
| 77 | $this->result = array( 'success' => true ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the success or failure of the deletion operation |
| 83 | * |
| 84 | * @return array An array containing one key; 'success', which specifies whether the operation was successful. |
| 85 | */ |
| 86 | protected function result() { |
| 87 | return $this->result; |
| 88 | } |
| 89 | } |