@@ -22,10 +22,6 @@ class Migration {
22
22
* Initialize the class, registering WordPress hooks.
23
23
*/
24
24
public static function init () {
25
- \add_action ( 'activitypub_migrate ' , array ( self ::class, 'async_migration ' ) );
26
- \add_action ( 'activitypub_upgrade ' , array ( self ::class, 'async_upgrade ' ), 10 , 99 );
27
- \add_action ( 'activitypub_update_comment_counts ' , array ( self ::class, 'update_comment_counts ' ), 10 , 2 );
28
-
29
25
self ::maybe_migrate ();
30
26
}
31
27
@@ -136,13 +132,12 @@ public static function maybe_migrate() {
136
132
$ version_from_db = ACTIVITYPUB_PLUGIN_VERSION ;
137
133
}
138
134
139
- // Schedule the async migration.
140
- if ( ! \wp_next_scheduled ( 'activitypub_migrate ' , $ version_from_db ) ) {
141
- \wp_schedule_single_event ( \time (), 'activitypub_migrate ' , array ( $ version_from_db ) );
142
- }
143
135
if ( \version_compare ( $ version_from_db , '0.17.0 ' , '< ' ) ) {
144
136
self ::migrate_from_0_16 ();
145
137
}
138
+ if ( \version_compare ( $ version_from_db , '1.0.0 ' , '< ' ) ) {
139
+ \wp_schedule_single_event ( \time (), 'activitypub_async_batch ' , array ( array ( self ::class, 'migrate_from_0_17 ' ) ) );
140
+ }
146
141
if ( \version_compare ( $ version_from_db , '1.3.0 ' , '< ' ) ) {
147
142
self ::migrate_from_1_2_0 ();
148
143
}
@@ -162,7 +157,7 @@ public static function maybe_migrate() {
162
157
self ::migrate_to_4_1_0 ();
163
158
}
164
159
if ( \version_compare ( $ version_from_db , '4.5.0 ' , '< ' ) ) {
165
- \wp_schedule_single_event ( \time () + MINUTE_IN_SECONDS , 'activitypub_update_comment_counts ' );
160
+ \wp_schedule_single_event ( \time () + MINUTE_IN_SECONDS , 'activitypub_async_batch ' , array ( array ( self ::class, ' update_comment_counts ' ) ) );
166
161
}
167
162
if ( \version_compare ( $ version_from_db , '4.7.1 ' , '< ' ) ) {
168
163
self ::migrate_to_4_7_1 ();
@@ -175,8 +170,8 @@ public static function maybe_migrate() {
175
170
}
176
171
if ( \version_compare ( $ version_from_db , '5.0.0 ' , '< ' ) ) {
177
172
Scheduler::register_schedules ();
178
- \wp_schedule_single_event ( \time (), 'activitypub_upgrade ' , array ( 'create_post_outbox_items ' ) );
179
- \wp_schedule_single_event ( \time () + 15 , 'activitypub_upgrade ' , array ( 'create_comment_outbox_items ' ) );
173
+ \wp_schedule_single_event ( \time (), 'activitypub_async_batch ' , array ( array ( self ::class, 'create_post_outbox_items ' ) ) );
174
+ \wp_schedule_single_event ( \time () + 15 , 'activitypub_async_batch ' , array ( array ( self ::class, 'create_comment_outbox_items ' ) ) );
180
175
add_action ( 'init ' , 'flush_rewrite_rules ' , 20 );
181
176
}
182
177
if ( \version_compare ( $ version_from_db , '5.2.0 ' , '< ' ) ) {
@@ -208,49 +203,6 @@ public static function maybe_migrate() {
208
203
self ::unlock ();
209
204
}
210
205
211
- /**
212
- * Asynchronously migrates the database structure.
213
- *
214
- * @param string $version_from_db The version from which to migrate.
215
- */
216
- public static function async_migration ( $ version_from_db ) {
217
- if ( \version_compare ( $ version_from_db , '1.0.0 ' , '< ' ) ) {
218
- self ::migrate_from_0_17 ();
219
- }
220
- }
221
-
222
- /**
223
- * Asynchronously runs upgrade routines.
224
- *
225
- * @param callable $callback Callable upgrade routine. Must be a method of this class.
226
- * @params mixed ...$args Optional. Parameters that get passed to the callback.
227
- */
228
- public static function async_upgrade ( $ callback ) {
229
- $ args = \func_get_args ();
230
-
231
- // Bail if the existing lock is still valid.
232
- if ( self ::is_locked () ) {
233
- \wp_schedule_single_event ( time () + MINUTE_IN_SECONDS , 'activitypub_upgrade ' , $ args );
234
- return ;
235
- }
236
-
237
- self ::lock ();
238
-
239
- $ callback = array_shift ( $ args ); // Remove $callback from arguments.
240
- $ next = \call_user_func_array ( array ( self ::class, $ callback ), $ args );
241
-
242
- self ::unlock ();
243
-
244
- if ( ! empty ( $ next ) ) {
245
- // Schedule the next run, adding the result to the arguments.
246
- \wp_schedule_single_event (
247
- \time () + 30 ,
248
- 'activitypub_upgrade ' ,
249
- \array_merge ( array ( $ callback ), \array_values ( $ next ) )
250
- );
251
- }
252
- }
253
-
254
206
/**
255
207
* Updates the custom template to use shortcodes instead of the deprecated templates.
256
208
*/
@@ -492,25 +444,11 @@ public static function migrate_to_4_7_2() {
492
444
* @see Comment::pre_wp_update_comment_count_now()
493
445
* @param int $batch_size Optional. Number of posts to process per batch. Default 100.
494
446
* @param int $offset Optional. Number of posts to skip. Default 0.
447
+ * @return array|null Array with batch size and offset if there are more posts to process, null otherwise.
495
448
*/
496
449
public static function update_comment_counts ( $ batch_size = 100 , $ offset = 0 ) {
497
450
global $ wpdb ;
498
451
499
- // Bail if the existing lock is still valid.
500
- if ( self ::is_locked () ) {
501
- \wp_schedule_single_event (
502
- time () + ( 5 * MINUTE_IN_SECONDS ),
503
- 'activitypub_update_comment_counts ' ,
504
- array (
505
- 'batch_size ' => $ batch_size ,
506
- 'offset ' => $ offset ,
507
- )
508
- );
509
- return ;
510
- }
511
-
512
- self ::lock ();
513
-
514
452
Comment::register_comment_types ();
515
453
$ comment_types = Comment::get_comment_type_slugs ();
516
454
$ type_inclusion = "AND comment_type IN (' " . implode ( "',' " , $ comment_types ) . "') " ;
@@ -531,17 +469,10 @@ public static function update_comment_counts( $batch_size = 100, $offset = 0 ) {
531
469
532
470
if ( count ( $ post_ids ) === $ batch_size ) {
533
471
// Schedule next batch.
534
- \wp_schedule_single_event (
535
- time () + MINUTE_IN_SECONDS ,
536
- 'activitypub_update_comment_counts ' ,
537
- array (
538
- 'batch_size ' => $ batch_size ,
539
- 'offset ' => $ offset + $ batch_size ,
540
- )
541
- );
472
+ return array ( $ batch_size , $ offset + $ batch_size );
542
473
}
543
474
544
- self :: unlock () ;
475
+ return null ;
545
476
}
546
477
547
478
/**
0 commit comments