Skip to content

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Oct 31, 2025

Refactored Mastodon import logic to consistently use associative arrays instead of stdClass objects, improving compatibility and reliability. Updated Blocks and Mastodon classes, adjusted related docblocks, and added comprehensive PHPUnit tests for the Mastodon import process, including edge cases for public/private posts, hashtags, summaries, duplicates, and filter hooks.

Fixes #2405

Proposed changes:

  • Modified json_decode() to use associative flag, ensuring all decoded JSON is in array format
  • Updated all references to use array syntax ['key'] instead of object syntax ->key
  • Added comprehensive test coverage for the import functionality

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to '..'

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Refactored Mastodon import handling to use consistent array-based data, improving reliability and compatibility across all import scenarios.

Refactored Mastodon import logic to consistently use associative arrays instead of stdClass objects, improving compatibility and reliability. Updated Blocks and Mastodon classes, adjusted related docblocks, and added comprehensive PHPUnit tests for the Mastodon import process, including edge cases for public/private posts, hashtags, summaries, duplicates, and filter hooks.
Copilot AI review requested due to automatic review settings October 31, 2025 12:37
@pfefferle pfefferle self-assigned this Oct 31, 2025
@pfefferle pfefferle requested a review from obenland October 31, 2025 12:37
@github-actions github-actions bot added [Feature] Import [Feature] WP Admin [Focus] Editor Changes to the ActivityPub experience in the block editor [Tests] Includes Tests labels Oct 31, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug in the Mastodon importer where json_decode() was creating stdClass objects instead of arrays, causing fatal errors when the code tried to use array syntax on nested objects. The fix changes json_decode() to use the associative flag (true) to return arrays consistently throughout the import process.

Key Changes:

  • Modified json_decode() to use associative flag, ensuring all decoded JSON is in array format
  • Updated all references to use array syntax ['key'] instead of object syntax ->key
  • Added comprehensive test coverage for the import functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
includes/wp-admin/import/class-mastodon.php Changed json_decode() to return arrays and updated all object property accesses to array syntax
includes/class-blocks.php Updated filter function to accept arrays instead of objects and use null coalescing operator for safer access
tests/phpunit/tests/includes/wp-admin/import/class-test-mastodon.php Added comprehensive test suite covering various import scenarios including the stdClass bug
tests/phpunit/tests/includes/class-test-blocks.php Updated existing tests to use array syntax and added new test cases for the filter function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pfefferle and others added 4 commits October 31, 2025 13:39
Replaces json_encode with wp_json_encode for WordPress compatibility, uses self::factory() for user creation, and wraps Mastodon::import_posts() calls with output buffering to suppress output during tests. Also improves code comments and formatting for clarity.
Enhanced the Mastodon import tests to assert that the expected output messages (such as 'Imported X posts' and 'Skipped posts') are present in the output. This ensures that the import process provides user feedback as intended.
),
),
)
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not thought this through yet, but I wonder if we should create a fixture with a "full" export, including attachments, that we could re-use. Not sure how much sense that makes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but can we have that a different PR?

@pfefferle pfefferle requested a review from obenland November 3, 2025 19:31
@pfefferle pfefferle merged commit e202205 into trunk Nov 3, 2025
12 checks passed
@pfefferle pfefferle deleted the fix/mastodon-importer branch November 3, 2025 22:00
@Jiwoon-Kim
Copy link
Contributor

I’ve been thinking about why post migration is so difficult in ActivityPub, and I believe the biggest reason is the immutability of IDs.
While other properties can be changed, the id must remain constant.

The second issue is visibility — particularly when posts are set to followers-only.
You can migrate your followings, but followers cannot be migrated, which means the visibility scope can change after migration.
The complication deepens with the inReplyTo object, since its visibility should inherit from the parent post — and this dependency can make post-level migration nearly impossible to handle correctly.

The third reason is that what we usually call “migration” is actually actor-level migration, not object-level migration.
A post object may appear to belong to its actor, but in essence, both the actor and the post are independent entities.

And most importantly — we’re not migrating the full set of activities, inbox, and outbox data, right?
That’s why followers can’t be transferred when an account is migrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Import [Feature] WP Admin [Focus] Editor Changes to the ActivityPub experience in the block editor [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mastodon Imports fail with error

5 participants