-
Notifications
You must be signed in to change notification settings - Fork 83
Refactor Mastodon import to use arrays, add tests #2412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
There was a problem hiding this 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.
tests/phpunit/tests/includes/wp-admin/import/class-test-mastodon.php
Outdated
Show resolved
Hide resolved
…on.php Co-authored-by: Copilot <[email protected]>
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.
| ), | ||
| ), | ||
| ) | ||
| ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Co-authored-by: Konstantin Obenland <[email protected]>
|
I’ve been thinking about why post migration is so difficult in ActivityPub, and I believe the biggest reason is the immutability of IDs. The second issue is visibility — particularly when posts are set to followers-only. The third reason is that what we usually call “migration” is actually actor-level migration, not object-level migration. And most importantly — we’re not migrating the full set of activities, inbox, and outbox data, right? |
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:
json_decode()to use associative flag, ensuring all decoded JSON is in array format['key']instead of object syntax->keyOther information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Refactored Mastodon import handling to use consistent array-based data, improving reliability and compatibility across all import scenarios.