From fb76e8f106e8cf2933a0f9b2115e937f2a7619eb Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 17 Oct 2024 10:09:48 +0200 Subject: [PATCH] call migration! --- activitypub.php | 2 +- includes/class-migration.php | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/activitypub.php b/activitypub.php index c8af4833..dd690e52 100644 --- a/activitypub.php +++ b/activitypub.php @@ -22,7 +22,7 @@ use WP_CLI; require_once __DIR__ . '/includes/compat.php'; require_once __DIR__ . '/includes/functions.php'; -\define( 'ACTIVITYPUB_PLUGIN_VERSION', '3.3.3' ); +\define( 'ACTIVITYPUB_PLUGIN_VERSION', '4.0.0' ); /** * Initialize the plugin constants. diff --git a/includes/class-migration.php b/includes/class-migration.php index d112fd7c..101d7868 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -87,7 +87,7 @@ class Migration { * @return bool True if the database structure is up to date, false otherwise. */ public static function is_latest_version() { - return (bool) version_compare( + return (bool) \version_compare( self::get_version(), self::get_target_version(), '==' @@ -120,23 +120,34 @@ class Migration { if ( ! \wp_next_scheduled( 'activitypub_migrate', $version_from_db ) ) { \wp_schedule_single_event( \time(), 'activitypub_migrate', array( $version_from_db ) ); } - if ( version_compare( $version_from_db, '0.17.0', '<' ) ) { + if ( \version_compare( $version_from_db, '0.17.0', '<' ) ) { self::migrate_from_0_16(); } - if ( version_compare( $version_from_db, '1.3.0', '<' ) ) { + if ( \version_compare( $version_from_db, '1.3.0', '<' ) ) { self::migrate_from_1_2_0(); } - if ( version_compare( $version_from_db, '2.1.0', '<' ) ) { + if ( \version_compare( $version_from_db, '2.1.0', '<' ) ) { self::migrate_from_2_0_0(); } - if ( version_compare( $version_from_db, '2.3.0', '<' ) ) { + if ( \version_compare( $version_from_db, '2.3.0', '<' ) ) { self::migrate_from_2_2_0(); } - if ( version_compare( $version_from_db, '3.0.0', '<' ) ) { + if ( \version_compare( $version_from_db, '3.0.0', '<' ) ) { self::migrate_from_2_6_0(); } + if ( \version_compare( $version_from_db, '4.0.0', '<' ) ) { + self::migrate_to_4_0_0(); + } - update_option( 'activitypub_db_version', self::get_target_version() ); + /** + * Fires when the system has to be migrated. + * + * @param string $version_from_db The version from which to migrate. + * @param string $target_version The target version to migrate to. + */ + \do_action( 'activitypub_migrate', $version_from_db, self::get_target_version() ); + + \update_option( 'activitypub_db_version', self::get_target_version() ); self::unlock(); } @@ -147,7 +158,7 @@ class Migration { * @param string $version_from_db The version from which to migrate. */ public static function async_migration( $version_from_db ) { - if ( version_compare( $version_from_db, '1.0.0', '<' ) ) { + if ( \version_compare( $version_from_db, '1.0.0', '<' ) ) { self::migrate_from_0_17(); } } @@ -265,7 +276,7 @@ class Migration { /** * Update actor-mode settings. */ - private static function migrate_from_4_0_0() { + private static function migrate_to_4_0_0() { $blog_profile = \get_option( 'activitypub_enable_blog_user', false ); $author_profiles = \get_option( 'activitypub_enable_users', false );