FlushLogs.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\API\Endpoints\Logs; |
| 4 | |
| 5 | use WP_REST_Request; |
| 6 | use WP_REST_Response; |
| 7 | use Give\Log\LogRepository; |
| 8 | |
| 9 | /** |
| 10 | * Class FlushLogs |
| 11 | * @package Give\API\Endpoints\Logs |
| 12 | * |
| 13 | * @since 2.10.0 |
| 14 | */ |
| 15 | class FlushLogs extends Endpoint { |
| 16 | |
| 17 | /** @var string */ |
| 18 | protected $endpoint = 'logs/flush-logs'; |
| 19 | |
| 20 | /** |
| 21 | * @var LogRepository |
| 22 | */ |
| 23 | private $logRepository; |
| 24 | |
| 25 | /** |
| 26 | * GetLogs constructor. |
| 27 | * |
| 28 | * @param LogRepository $repository |
| 29 | */ |
| 30 | public function __construct( LogRepository $repository ) { |
| 31 | $this->logRepository = $repository; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @inheritDoc |
| 36 | */ |
| 37 | public function registerRoute() { |
| 38 | register_rest_route( |
| 39 | 'give-api/v2', |
| 40 | $this->endpoint, |
| 41 | [ |
| 42 | [ |
| 43 | 'methods' => 'DELETE', |
| 44 | 'callback' => [ $this, 'handleRequest' ], |
| 45 | 'permission_callback' => [ $this, 'permissionsCheck' ], |
| 46 | 'args' => [], |
| 47 | ], |
| 48 | 'schema' => [ $this, 'getSchema' ], |
| 49 | ] |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return array |
| 55 | */ |
| 56 | public function getSchema() { |
| 57 | return [ |
| 58 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 59 | 'title' => 'logs', |
| 60 | 'type' => 'object', |
| 61 | 'properties' => [], |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @param WP_REST_Request $request |
| 67 | * |
| 68 | * @return WP_REST_Response |
| 69 | */ |
| 70 | public function handleRequest( WP_REST_Request $request ) { |
| 71 | $this->logRepository->flushLogs(); |
| 72 | |
| 73 | return new WP_REST_Response( [ 'status' => true ] ); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |