Skip to content

fix: load site exporter in web requests#1541

Merged
superdav42 merged 2 commits into
mainfrom
fix/web-export-wp-cli-polyfill
Jun 25, 2026
Merged

fix: load site exporter in web requests#1541
superdav42 merged 2 commits into
mainfrom
fix/web-export-wp-cli-polyfill

Conversation

@superdav42

@superdav42 superdav42 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • follow-up to fix: support main site export imports #1540 for the web/AJAX export fatal reported after merge
  • load a minimal WP-CLI polyfill before bundled MU-Migration command classes when WP_CLI_Command / WP_CLI are unavailable
  • keep the CLI-only mu-migration info command loaded only during real WP-CLI requests
  • add an isolated-process regression test proving MU-Migration export classes load without WP-CLI runtime classes

Verification

  • vendor/bin/phpunit --filter 'Site_Exporter_Test|Site_Exporter_Round_Trip_Test|Site_Exporter_Import_Move_Test'
  • vendor/bin/phpcs inc/site-exporter/class-site-exporter.php inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php tests/WP_Ultimo/Site_Exporter_Test.php
  • vendor/bin/phpstan analyse inc/site-exporter/class-site-exporter.php inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php tests/WP_Ultimo/Site_Exporter_Test.php

Notes

The merged #1540 commit is in main, but the web/AJAX fatal fix was pushed afterward and did not land in main. This PR contains only that follow-up fix on top of current main.


aidevops.sh v3.22.1 plugin for OpenCode v1.17.9 with gpt-5.5

Summary by CodeRabbit

  • Bug Fixes
    • Improved site import/export behavior in non-WP-CLI (web/AJAX) contexts by adding lightweight WP-CLI compatibility stubs so export commands load reliably.
    • Added safer handling for runtime failures during site import, including clearing the pending-import marker and failing gracefully.
  • Tests
    • Added a regression test to confirm MU-Migration export commands load correctly outside a WP-CLI session.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e6565b10-7fc6-44e2-893d-79b3e12f956c

📥 Commits

Reviewing files that changed from the base of the PR and between 40a01ef and c8bdde9.

📒 Files selected for processing (2)
  • inc/site-exporter/class-site-exporter.php
  • tests/WP_Ultimo/Site_Exporter_Test.php

📝 Walkthrough

Walkthrough

The site exporter now catches MU-Migration runtime exceptions during import, loads a WP-CLI polyfill when CLI classes are absent, and adds a subprocess test for loading the export command stack without WP-CLI.

Changes

MU-CLI fallback loading

Layer / File(s) Summary
Import runtime failure handling
inc/site-exporter/class-site-exporter.php
handle_site_import() catches \RuntimeException from MU-Migration import execution, clears the pending-import transient, logs the exception message, and returns false.
Conditional loading and regression check
inc/site-exporter/class-site-exporter.php, inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php, tests/WP_Ultimo/Site_Exporter_Test.php
load_dependencies() conditionally requires the WP-CLI polyfill, always loads the MU-Migration helper and command support files, and only requires class-mu-migration.php when WP_CLI is defined; the new polyfill defines WP_CLI_Command, WP_CLI, and WP_CLI\Utils\make_progress_bar(), and a subprocess test checks that ExportCommand loads without WP-CLI runtime classes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

origin:interactive

Poem

A bunny found a CLI trail,
With polyfills tucked in the pail.
When WP-CLI's away,
The export still hops today,
And tests make the loading feel hale.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: enabling the site exporter to load during web requests instead of only under WP-CLI.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/web-export-wp-cli-polyfill

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/WP_Ultimo/Site_Exporter_Test.php (1)

312-325: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Guard the subprocess test against disabled shell_exec/empty PHP_BINARY.

In hardened CI/runtime environments shell_exec can be disabled (or PHP_BINARY empty), in which case $output is null and the test fails for an environmental reason rather than a real regression. A skip guard makes intent clear. (The OpenGrep/ast-grep command-injection hints here are false positives — both PHP_BINARY and $script are passed through escapeshellarg().)

🧪 Proposed skip guard
 	public function test_mu_migration_export_commands_load_without_wp_cli_runtime(): void {
+
+		if (! function_exists('shell_exec') || '' === PHP_BINARY) {
+			$this->markTestSkipped('shell_exec or PHP_BINARY is not available in this environment');
+		}
 
 		$repo_root = dirname(__DIR__, 2);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Site_Exporter_Test.php` around lines 312 - 325, The
subprocess regression test in
test_mu_migration_export_commands_load_without_wp_cli_runtime should be skipped
when the environment cannot run it, such as when shell_exec is disabled or
PHP_BINARY is unavailable. Add an early guard before building the shell command,
and use the test case’s skip mechanism so the assertion only runs when the
spawned PHP process can actually execute. Keep the existing shell_exec call and
assertions in place for the valid path, using the same test method and related
MU_Migration command class references to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php`:
- Around line 90-93: Wrap the site import execution in explicit error handling
because WP_CLI::error() in the polyfill throws a RuntimeException during
web/AJAX imports. Update handle_site_import() to catch that exception around the
$command->all([$file_name], $args) call and handle the failure gracefully
instead of letting it bubble into a fatal, and review the invalid-input paths
that still call WP_CLI::error() so the import flow in class-site-exporter stays
safe in non-CLI runs.

---

Nitpick comments:
In `@tests/WP_Ultimo/Site_Exporter_Test.php`:
- Around line 312-325: The subprocess regression test in
test_mu_migration_export_commands_load_without_wp_cli_runtime should be skipped
when the environment cannot run it, such as when shell_exec is disabled or
PHP_BINARY is unavailable. Add an early guard before building the shell command,
and use the test case’s skip mechanism so the assertion only runs when the
spawned PHP process can actually execute. Keep the existing shell_exec call and
assertions in place for the valid path, using the same test method and related
MU_Migration command class references to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f178c4c6-602b-4574-aafe-c1b4aa81deee

📥 Commits

Reviewing files that changed from the base of the PR and between 99a3c1a and 40a01ef.

📒 Files selected for processing (3)
  • inc/site-exporter/class-site-exporter.php
  • inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php
  • tests/WP_Ultimo/Site_Exporter_Test.php

Comment thread inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php
@superdav42 superdav42 merged commit acba35f into main Jun 25, 2026
10 of 11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • follow-up to fix: support main site export imports #1540 for the web/AJAX export fatal reported after merge
  • load a minimal WP-CLI polyfill before bundled MU-Migration command classes when WP_CLI_Command / WP_CLI are unavailable
  • keep the CLI-only mu-migration info command loaded only during real WP-CLI requests
  • add an isolated-process regression test proving MU-Migration export classes load without WP-CLI runtime classes

Verification

  • vendor/bin/phpunit --filter 'Site_Exporter_Test|Site_Exporter_Round_Trip_Test|Site_Exporter_Import_Move_Test'
  • vendor/bin/phpcs inc/site-exporter/class-site-exporter.php inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php tests/WP_Ultimo/Site_Exporter_Test.php
  • vendor/bin/phpstan analyse inc/site-exporter/class-site-exporter.php inc/site-exporter/mu-migration/includes/wp-cli-polyfill.php tests/WP_Ultimo/Site_Exporter_Test.php

Notes

The merged #1540 commit is in main, but the web/AJAX fatal fix was pushed afterward and did not land in main. This PR contains only that follow-up fix on top of current main.


aidevops.sh v3.22.1 plugin for OpenCode v1.17.9 with gpt-5.5


Merged via PR #1541 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42

Copy link
Copy Markdown
Collaborator Author

CLAIM_RELEASED reason=worker_complete runner=superdav42 ts=2026-06-25T21:07:14Z aidevops_version=3.22.1 opencode_version=1.17.9

@superdav42 superdav42 added status:available Task is available for claiming review-feedback-scanned Merged PR already scanned for quality feedback labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback status:available Task is available for claiming

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant