Skip to content

Commit d3cf57f

Browse files
authored
Upgrades: Delete orphaned extra fields (#1566)
1 parent 1dbcc8e commit d3cf57f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Upgrade routine that removes any erroneously created extra field entries.

includes/class-migration.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ public static function maybe_migrate() {
188188
\wp_schedule_single_event( \time(), 'activitypub_upgrade', array( 'update_comment_author_emails' ) );
189189
\add_action( 'init', 'flush_rewrite_rules', 20 );
190190
}
191+
if ( \version_compare( $version_from_db, 'unreleased', '<' ) ) {
192+
self::delete_mastodon_api_orphaned_extra_fields();
193+
}
191194

192195
/*
193196
* Add new update routines above this comment. ^
@@ -897,4 +900,27 @@ public static function migrate_actor_mode() {
897900
\update_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
898901
}
899902
}
903+
904+
/**
905+
* Deletes user extra fields where the author is the blog user.
906+
*
907+
* These extra fields were created when the Enable Mastodon Apps integration passed
908+
* an author_url instead of a user_id to the mastodon_api_account filter. This caused
909+
* Extra_Fields::default_actor_extra_fields() to run but fail to cache the fact it ran
910+
* for non-existent users. The result is a number of user extra fields with no author.
911+
*
912+
* @ticket https://github.com/Automattic/wordpress-activitypub/pull/1554
913+
*/
914+
public static function delete_mastodon_api_orphaned_extra_fields() {
915+
global $wpdb;
916+
917+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
918+
$wpdb->delete(
919+
$wpdb->posts,
920+
array(
921+
'post_type' => Extra_Fields::USER_POST_TYPE,
922+
'post_author' => Actors::BLOG_USER_ID,
923+
)
924+
);
925+
}
900926
}

0 commit comments

Comments
 (0)