@@ -64,11 +64,11 @@ class Invalidation_Service {
6464 private $ invalidation_batch ;
6565
6666 /**
67- * Log invalidation parameters flag
67+ * Debug logger service.
6868 *
69- * @var boolean
69+ * @var WP\Debug_Logger
7070 */
71- private $ log_invalidation_params ;
71+ private $ debug_logger ;
7272
7373 /**
7474 * Initialize the service, register WordPress hooks, and optionally inject dependencies.
@@ -88,8 +88,9 @@ function __construct( ...$args ) {
8888 $ this ->option_service = new WP \Options_Service ();
8989 $ this ->invalidation_batch = new AWS \Invalidation_Batch_Service ();
9090 $ this ->transient_service = new WP \Transient_Service ();
91- $ this ->cf_service = new AWS \CloudFront_Service ();
9291 $ this ->notice = new WP \Admin_Notice ();
92+ $ this ->debug_logger = null ;
93+ $ this ->cf_service = null ;
9394
9495 if ( $ args && ! empty ( $ args ) ) {
9596 foreach ( $ args as $ key => $ value ) {
@@ -105,9 +106,17 @@ function __construct( ...$args ) {
105106 $ this ->cf_service = $ value ;
106107 } elseif ( $ value instanceof WP \Admin_Notice ) {
107108 $ this ->notice = $ value ;
109+ } elseif ( $ value instanceof WP \Debug_Logger ) {
110+ $ this ->debug_logger = $ value ;
108111 }
109112 }
110113 }
114+ if ( ! $ this ->debug_logger ) {
115+ $ this ->debug_logger = new WP \Debug_Logger ();
116+ }
117+ if ( ! $ this ->cf_service ) {
118+ $ this ->cf_service = new AWS \CloudFront_Service ( $ this ->debug_logger );
119+ }
111120 $ this ->hook_service ->add_action (
112121 'transition_post_status ' ,
113122 array (
@@ -140,7 +149,6 @@ function __construct( ...$args ) {
140149 'handle_invalidation_details_ajax ' ,
141150 )
142151 );
143- $ this ->log_invalidation_params = $ this ->hook_service ->apply_filters ( 'c3_log_invalidation_params ' , $ this ->get_debug_setting ( Constants::DEBUG_LOG_INVALIDATION_PARAMS ) );
144152 }
145153
146154 /**
@@ -196,34 +204,24 @@ public function invalidate_manually() {
196204 * @return boolean If true, cron has been scheduled.
197205 */
198206 public function register_cron_event ( $ query ) {
199- if ( $ this ->log_invalidation_params ) {
200- error_log ( '===== C3 CRON Job registration [START] === ' );
201- }
207+ $ this ->debug_logger ->log_cron_registration_start ();
202208 if ( ! isset ( $ query ['Paths ' ] ) || ! isset ( $ query ['Paths ' ]['Items ' ] ) || $ query ['Paths ' ]['Items ' ][0 ] === '/* ' ) {
203- if ( $ this ->log_invalidation_params ) {
204- error_log ( '===== C3 CRON Job registration [SKIP | NO ITEM] === ' );
205- }
209+ $ this ->debug_logger ->log_cron_registration_skip ( '===== C3 CRON Job registration [SKIP | NO ITEM] === ' );
206210 return false ;
207211 }
208212 if ( $ this ->hook_service ->apply_filters ( 'c3_disabled_cron_retry ' , false ) ) {
209- if ( $ this ->log_invalidation_params ) {
210- error_log ( '===== C3 CRON Job registration [SKIP | DISABLED] === ' );
211- }
213+ $ this ->debug_logger ->log_cron_registration_skip ( '===== C3 CRON Job registration [SKIP | DISABLED] === ' );
212214 return false ;
213215 }
214216 $ query = $ this ->transient_service ->save_invalidation_query ( $ query );
215217
216218 $ interval_minutes = $ this ->hook_service ->apply_filters ( 'c3_invalidation_cron_interval ' , 1 );
217219 $ time = time () + MINUTE_IN_SECONDS * $ interval_minutes ;
218- if ( $ this ->log_invalidation_params ) {
219- error_log ( print_r ( $ query , true ) );
220- }
220+ $ this ->debug_logger ->log_invalidation_params ( '' , array ( $ query ) );
221221
222222 $ result = wp_schedule_single_event ( $ time , 'c3_cron_invalidation ' );
223223
224- if ( $ this ->log_invalidation_params ) {
225- error_log ( '===== C3 CRON Job registration [COMPLETE] === ' );
226- }
224+ $ this ->debug_logger ->log_cron_registration_complete ();
227225 return $ result ;
228226 }
229227
@@ -272,10 +270,10 @@ public function invalidate_by_query( $query, $force = false ) {
272270 return $ query ;
273271 }
274272
275- if ( $ this ->hook_service -> apply_filters ( ' c3_log_invalidation_params ' , $ this -> get_debug_setting ( Constants:: DEBUG_LOG_INVALIDATION_PARAMS ) ) ) {
276- error_log ( ' C3 Invalidation Started - Query: ' . print_r ( $ query , true ) );
277- error_log ( ' C3 Invalidation Started - Force: ' . ( $ force ? ' true ' : ' false ' ) );
278- }
273+ $ this ->debug_logger -> log_invalidation_request ( array (
274+ ' query ' => $ query ,
275+ ' force ' => $ force,
276+ ) );
279277
280278 if ( $ this ->transient_service ->should_regist_cron_job () && false === $ force ) {
281279 /**
@@ -494,15 +492,4 @@ public function invalidate_attachment_cache( $attachment_id ) {
494492 return $ this ->invalidate_by_query ( $ query );
495493 }
496494
497- /**
498- * Get debug setting value
499- *
500- * @param string $setting_key Debug setting key.
501- * @return boolean Debug setting value.
502- */
503- private function get_debug_setting ( $ setting_key ) {
504- $ debug_options = get_option ( Constants::DEBUG_OPTION_NAME , array () );
505- $ value = isset ( $ debug_options [ $ setting_key ] ) ? $ debug_options [ $ setting_key ] : false ;
506- return $ value ;
507- }
508495}
0 commit comments