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