schedule migration because it takes quite some time

This commit is contained in:
Matthias Pfefferle 2023-04-28 09:54:09 +02:00
parent fb3d6d2634
commit 5ef41dea02
4 changed files with 17 additions and 1 deletions

View file

@ -35,7 +35,6 @@ function init() {
require_once \dirname( __FILE__ ) . '/includes/class-http.php'; require_once \dirname( __FILE__ ) . '/includes/class-http.php';
require_once \dirname( __FILE__ ) . '/includes/class-signature.php'; require_once \dirname( __FILE__ ) . '/includes/class-signature.php';
require_once \dirname( __FILE__ ) . '/includes/class-webfinger.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/peer/class-followers.php';
require_once \dirname( __FILE__ ) . '/includes/functions.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-post.php';
require_once \dirname( __FILE__ ) . '/includes/model/class-follower.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'; require_once \dirname( __FILE__ ) . '/includes/class-activity-dispatcher.php';
Activity_Dispatcher::init(); Activity_Dispatcher::init();

View file

@ -61,6 +61,9 @@ class Activity_Dispatcher {
* @return void * @return void
*/ */
public static function send_activity( Post $activitypub_post, $activity_type ) { 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 // get latest version of post
$user_id = $activitypub_post->get_post_author(); $user_id = $activitypub_post->get_post_author();

View file

@ -13,6 +13,7 @@ class Admin {
public static function init() { public static function init() {
\add_action( 'admin_menu', array( self::class, 'admin_menu' ) ); \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, 'register_settings' ) );
\add_action( 'admin_init', array( self::class, 'schedule_migration' ) );
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) ); \add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
\add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) ); \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() { public static function add_settings_help_tab() {
require_once \dirname( __FILE__ ) . '/help.php'; require_once \dirname( __FILE__ ) . '/help.php';
} }

View file

@ -9,6 +9,10 @@ class Migration {
*/ */
private static $target_version = '1.0.0'; 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() { public static function get_target_version() {
return self::$target_version; return self::$target_version;
} }