@@ -33,7 +33,7 @@ class BLC_Scan_CLI_Command extends WP_CLI_Command
3333 public function links ($ args , $ assoc_args )
3434 {
3535 $ is_full_scan = (bool ) \WP_CLI \Utils \get_flag_value ($ assoc_args , 'full ' , false );
36- $ bypass_rest_window = (bool ) \WP_CLI \Utils \get_flag_value ($ assoc_args , 'bypass-rest-window ' , true );
36+ $ bypass_rest_window = (bool ) \WP_CLI \Utils \get_flag_value ($ assoc_args , 'bypass-rest-window ' , false );
3737
3838 $ this ->run_link_scan ($ is_full_scan , $ bypass_rest_window );
3939 }
@@ -157,7 +157,14 @@ private function process_batches(callable $runner, array $initial_task, array $a
157157 return $ pre ;
158158 }
159159
160- $ scheduled_events [] = $ event ;
160+ $ timestamp = isset ($ event ['timestamp ' ]) ? (int ) $ event ['timestamp ' ] : time ();
161+ $ args = isset ($ event ['args ' ]) && is_array ($ event ['args ' ]) ? $ event ['args ' ] : [];
162+
163+ $ scheduled_events [] = [
164+ 'hook ' => (string ) $ event ['hook ' ],
165+ 'timestamp ' => $ timestamp ,
166+ 'args ' => $ args ,
167+ ];
161168
162169 return true ;
163170 };
@@ -200,25 +207,55 @@ private function process_batches(callable $runner, array $initial_task, array $a
200207 break ;
201208 }
202209
210+ $ handoff_events = [];
211+
203212 foreach ($ scheduled_events as $ event ) {
204- $ event_args = isset ($ event ['args ' ]) && is_array ($ event ['args ' ]) ? $ event ['args ' ] : [];
205- $ queue [] = [
206- 'hook ' => (string ) $ event ['hook ' ],
207- 'args ' => $ event_args ,
208- 'delay ' => max (0 , (int ) $ event ['timestamp ' ] - time ()),
209- ];
213+ $ event_args = $ event ['args ' ];
214+
215+ $ scheduled_batch = isset ($ event_args [0 ]) ? (int ) $ event_args [0 ] : null ;
216+ $ current_batch = isset ($ task ['args ' ][0 ]) ? (int ) $ task ['args ' ][0 ] : null ;
217+
218+ $ should_process_sync = true ;
219+ if ($ current_batch !== null && $ scheduled_batch === $ current_batch ) {
220+ $ should_process_sync = false ;
221+ }
222+
223+ if ($ should_process_sync ) {
224+ $ queue [] = [
225+ 'hook ' => $ event ['hook ' ],
226+ 'args ' => $ event_args ,
227+ 'delay ' => max (0 , $ event ['timestamp ' ] - time ()),
228+ ];
229+ continue ;
230+ }
231+
232+ $ handoff_events [] = $ event ;
210233 }
211234
212235 $ scheduled_events = [];
213- }
214- } finally {
215- remove_filter ('pre_schedule_event ' , $ filter , 10 );
216236
217- if (function_exists ('wp_clear_scheduled_hook ' )) {
218- foreach ($ allowed_hooks as $ hook ) {
219- wp_clear_scheduled_hook ($ hook );
237+ if ($ handoff_events !== []) {
238+ foreach ($ handoff_events as $ event ) {
239+ $ timestamp = $ event ['timestamp ' ];
240+ if ($ timestamp <= time ()) {
241+ $ timestamp = time () + 1 ;
242+ }
243+
244+ $ rescheduled = wp_schedule_single_event ($ timestamp , $ event ['hook ' ], $ event ['args ' ]);
245+ if (false === $ rescheduled ) {
246+ \WP_CLI ::warning (sprintf (
247+ "Impossible de reprogrammer le lot différé \"%s \". Il devra être lancé manuellement. " ,
248+ $ event ['hook ' ]
249+ ));
250+ }
251+ }
252+
253+ \WP_CLI ::log ("Des lots ont été différés et seront repris automatiquement par WP-Cron. " );
254+ break ;
220255 }
221256 }
257+ } finally {
258+ remove_filter ('pre_schedule_event ' , $ filter , 10 );
222259 }
223260 }
224261
0 commit comments