class-adbc-automation-endpoints.php
3 months ago
class-adbc-common-endpoints.php
4 months ago
class-adbc-cron-jobs-endpoints.php
3 months ago
class-adbc-general-cleanup-endpoints.php
3 months ago
class-adbc-info-endpoints.php
3 months ago
class-adbc-logs-endpoints.php
3 months ago
class-adbc-options-endpoints.php
3 months ago
class-adbc-post-types-endpoints.php
3 months ago
class-adbc-posts-meta-endpoints.php
3 months ago
class-adbc-settings-endpoints.php
3 months ago
class-adbc-tables-endpoints.php
3 months ago
class-adbc-transients-endpoints.php
3 months ago
class-adbc-users-meta-endpoints.php
3 months ago
class-adbc-logs-endpoints.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | /** |
| 8 | * ADBC Logs Endpoints. |
| 9 | * |
| 10 | * This class provides the endpoints (controllers) for the logs routes. |
| 11 | */ |
| 12 | class ADBC_Logs_Endpoints { |
| 13 | |
| 14 | /** |
| 15 | * Get logs content. |
| 16 | * |
| 17 | * @param WP_REST_Request $log_object Log type to get its content ('debug' or 'wp-debug'). |
| 18 | * @return WP_REST_Response The logs content. |
| 19 | */ |
| 20 | public static function get_logs_content( WP_REST_Request $log_object ) { |
| 21 | |
| 22 | try { |
| 23 | |
| 24 | $log_type = $log_object->get_param( 'log_type' ); |
| 25 | $sanitized_log_type = sanitize_key( $log_type ); |
| 26 | |
| 27 | if ( $sanitized_log_type !== 'debug' && $sanitized_log_type !== 'wp-debug' ) |
| 28 | return ADBC_Rest::error( "Invalid log file type.", ADBC_Rest::BAD_REQUEST ); |
| 29 | |
| 30 | $log_content = ADBC_Logging::get_log_content( $sanitized_log_type ); |
| 31 | |
| 32 | if ( $log_content['success'] === false ) |
| 33 | return ADBC_Rest::error( $log_content['message'], ADBC_Rest::INTERNAL_SERVER_ERROR ); |
| 34 | |
| 35 | return ADBC_Rest::success( "", [ 'content' => $log_content['content'] ] ); |
| 36 | |
| 37 | } catch (Exception $e) { |
| 38 | |
| 39 | return ADBC_Rest::error_for_uncaught_exception( __METHOD__, $e ); |
| 40 | |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Clear log file content. |
| 46 | * |
| 47 | * @return WP_REST_Response Response. |
| 48 | */ |
| 49 | public static function clear_logs_content() { |
| 50 | |
| 51 | try { |
| 52 | |
| 53 | $cleared = ADBC_Logging::clear_log(); |
| 54 | |
| 55 | if ( $cleared === false ) |
| 56 | return ADBC_Rest::error( |
| 57 | __( 'Cannot clear the log file content.', 'advanced-database-cleaner' ), ADBC_Rest::INTERNAL_SERVER_ERROR, |
| 58 | 0, |
| 59 | [ |
| 60 | 'message_links' => [ |
| 61 | [ |
| 62 | 'text' => __( 'Check the logs', 'advanced-database-cleaner' ), |
| 63 | 'tab_id' => 'info_and_logs', |
| 64 | 'sub_tab_id' => 'debug', |
| 65 | ], |
| 66 | ], |
| 67 | ] |
| 68 | ); |
| 69 | |
| 70 | return ADBC_Rest::success( "" ); |
| 71 | |
| 72 | } catch (Exception $e) { |
| 73 | |
| 74 | return ADBC_Rest::error_for_uncaught_exception( __METHOD__, $e ); |
| 75 | |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | } |