diff --git a/activitypub.php b/activitypub.php index 41c01dd..7523bcc 100644 --- a/activitypub.php +++ b/activitypub.php @@ -35,7 +35,6 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/class-http.php'; require_once \dirname( __FILE__ ) . '/includes/class-signature.php'; require_once \dirname( __FILE__ ) . '/includes/class-webfinger.php'; - require_once \dirname( __FILE__ ) . '/includes/class-migration.php'; require_once \dirname( __FILE__ ) . '/includes/peer/class-followers.php'; require_once \dirname( __FILE__ ) . '/includes/functions.php'; @@ -43,6 +42,9 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/model/class-post.php'; require_once \dirname( __FILE__ ) . '/includes/model/class-follower.php'; + require_once \dirname( __FILE__ ) . '/includes/class-migration.php'; + Migration::init(); + require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php'; Activity_Dispatcher::init(); diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index e71ac19..422240d 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -61,6 +61,9 @@ class Activity_Dispatcher { * @return void */ public static function send_activity( Post $activitypub_post, $activity_type ) { + // check if a migration is needed before sending new posts + \Activitypub\Migration::maybe_migrate(); + // get latest version of post $user_id = $activitypub_post->get_post_author(); diff --git a/includes/class-admin.php b/includes/class-admin.php index c8c5813..c66c0f0 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -13,6 +13,7 @@ class Admin { public static function init() { \add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); \add_action( 'admin_init', array( self::class, 'register_settings' ) ); + \add_action( 'admin_init', array( self::class, 'schedule_migration' ) ); \add_action( 'show_user_profile', array( self::class, 'add_profile' ) ); \add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) ); } @@ -144,6 +145,12 @@ class Admin { ); } + public static function schedule_migration() { + if ( ! \wp_next_scheduled( 'activitypub_schedule_migration' ) ) { + \wp_schedule_single_event( \time(), 'activitypub_schedule_migration' ); + } + } + public static function add_settings_help_tab() { require_once \dirname( __FILE__ ) . '/help.php'; } diff --git a/includes/class-migration.php b/includes/class-migration.php index f3aac10..953ab6f 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -9,6 +9,10 @@ class Migration { */ private static $target_version = '1.0.0'; + public static function init() { + \add_action( 'activitypub_schedule_migration', array( self::class, 'maybe_migrate' ) ); + } + public static function get_target_version() { return self::$target_version; }