Skip to content

Conversation

@obenland
Copy link
Member

@obenland obenland commented Dec 3, 2025

Fixes https://wordpress.org/support/topic/import-mastodon-beta/page/2/#post-18741275

Proposed changes:

  • Handle Mastodon archive exports that wrap all files in a root folder (e.g., archive-name/outbox.json instead of outbox.json at root level).
  • Use $wp_filesystem->exists() instead of dirlist() for checking outbox.json existence (more efficient).
  • Use $wp_filesystem->get_contents() instead of file_get_contents() for consistency with the rest of the codebase and to remove phpcs ignore comment.

Other information:

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

Testing instructions:

  1. Export your archive from Mastodon (Preferences > Import and Export > Request your archive).
  2. Go to Tools > Import > Mastodon.
  3. Upload a Mastodon archive ZIP that has files nested in a root folder.
  4. Verify the import proceeds without "The archive does not contain an Outbox file" error.

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

Fix Mastodon import for archives with nested root folder.

Copilot AI review requested due to automatic review settings December 3, 2025 20:23
@obenland obenland self-assigned this Dec 3, 2025
@obenland obenland requested a review from a team December 3, 2025 20:23
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 an issue where Mastodon archive imports fail when the archive contains a nested root folder structure. The fix detects and handles archives where files are wrapped in a single root directory (e.g., archive-name/outbox.json) instead of being at the root level.

Key Changes:

  • Added maybe_unwrap_archive() method to detect and handle nested archive structures
  • Replaced dirlist() check with $wp_filesystem->exists() for better performance
  • Replaced file_get_contents() with $wp_filesystem->get_contents() for consistency

Reviewed changes

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

File Description
includes/wp-admin/import/class-mastodon.php Added archive unwrapping logic and improved file system operations for consistency
.github/changelog/2581-from-description Added changelog entry documenting the bug fix

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

obenland and others added 2 commits December 3, 2025 14:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pfefferle
Copy link
Member

Is it possible to somehow test this with a unittest?

@obenland
Copy link
Member Author

obenland commented Dec 4, 2025

Is it possible to somehow test this with a unittest?

It is! Fixed in b17eede.

@obenland obenland merged commit a115aad into trunk Dec 4, 2025
10 checks passed
@obenland obenland deleted the fix/mastodon-import-nested-archive branch December 4, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants