Skip to content

fix: support main site export imports#1540

Merged
superdav42 merged 2 commits into
mainfrom
fix/site-export-import-main-single
Jun 25, 2026
Merged

fix: support main site export imports#1540
superdav42 merged 2 commits into
mainfrom
fix/site-export-import-main-single

Conversation

@superdav42

@superdav42 superdav42 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • expose main-site single-site export from Network Admin > Sites row and bulk actions
  • keep "Promote to Main Site" hidden for the main site while preserving subsite promotion
  • scope MU-Migration import search-replace to imported SQL tables so main-site imports do not rewrite existing network rows
  • add regression tests for main-site export actions, bulk export queueing, and imported-table parsing

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/commands/class-mu-migration-import.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/commands/class-mu-migration-import.php tests/WP_Ultimo/Site_Exporter_Test.php
  • Manual: fresh single-site install with only Ultimate Multisite active exposed Tools > Export & Import, exported /tmp/opencode/um-single-site-export.zip, imported into dev multisite as blog ID 60, and verified Single Export Verification page
  • Manual: exported multisite main site to /tmp/opencode/um-main-site-export.zip, reimported after scoped search-replace fix as blog ID 62, verified Main Site Export Verification page, and confirmed existing network site URLs stayed intact

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

Summary by CodeRabbit

  • New Features

    • You can now export the main site from the network “Sites” list, including when exporting multiple sites at once.
    • The main site shows an Export action, while promotion to the main site is available only for subsites.
  • Bug Fixes

    • URL search-and-replace during import is now limited to tables detected in the imported SQL, reducing unintended changes.
    • If no matching tables are detected, the URL update step is safely skipped with a warning.
  • Tests

    • Added regression coverage for row actions, bulk export behavior, and imported SQL table detection.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a5b74e6-3738-4af5-8062-66978ebe4665

📥 Commits

Reviewing files that changed from the base of the PR and between 54a6a3c and c681893.

📒 Files selected for processing (2)
  • inc/site-exporter/mu-migration/includes/commands/class-mu-migration-import.php
  • tests/WP_Ultimo/Site_Exporter_Test.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • inc/site-exporter/mu-migration/includes/commands/class-mu-migration-import.php
  • tests/WP_Ultimo/Site_Exporter_Test.php

📝 Walkthrough

Walkthrough

The PR lets the network Sites list export the main site, keeps promotion limited to subsites, includes the main site in bulk exports, and scopes import search-replace operations to tables detected in the imported SQL file. Tests cover the updated actions, bulk export, and SQL parsing.

Changes

Site Export and Import Scoping

Layer / File(s) Summary
Network Sites row actions
inc/site-exporter/class-site-exporter.php, tests/WP_Ultimo/Site_Exporter_Test.php
add_wp_sites_row_actions() keeps Export available for the main site and only omits Promote to Main Site for the main site; tests cover main-site and subsite row actions.
Bulk export includes the main site
inc/site-exporter/class-site-exporter.php, tests/WP_Ultimo/Site_Exporter_Test.php
handle_wp_sites_bulk_action() no longer skips the main site, and the test cleanup clears pending export transients before the bulk-export regression test checks the queued main-site export.
Imported SQL table scoping
inc/site-exporter/mu-migration/includes/commands/class-mu-migration-import.php, tests/WP_Ultimo/Site_Exporter_Test.php
tables() limits search-replace to tables found in the imported SQL file, get_imported_table_names() parses CREATE TABLE, INSERT INTO, and LOCK TABLES, and tests verify the extracted names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

review-feedback-scanned, status:available

Poem

🐇 I hopped through Sites at morning light,
The main site Export felt just right.
I sniffed the SQL, found tables neat,
And left Promote for subsites sweet.
Hop hop—tests pass in a carrot glow.

🚥 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 is concise and matches the PR’s main change: adding main-site export/import support.
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/site-export-import-main-single

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)

239-246: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the repo’s wu_create_*() fixture helper here.

Line 241 bypasses the test-data setup convention by creating the subsite with the raw factory. Please switch this to the appropriate wu_create_*() helper so the fixture matches the repository’s multisite test setup rules. As per coding guidelines, tests/**/*.php: "Use wu_create_*() helper functions to set up test data."

🤖 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 239 - 246, The multisite
test setup in test_wp_sites_row_actions_include_subsite_export_and_promotion is
bypassing the repository’s fixture convention by using the raw blog factory.
Replace the direct self::factory()->blog->create() call with the appropriate
wu_create_*() helper used for creating subsites in tests, keeping the rest of
the assertions in add_wp_sites_row_actions unchanged.

Source: Coding guidelines

🤖 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/commands/class-mu-migration-import.php`:
- Around line 824-839: The get_imported_table_names helper currently reads the
full SQL dump with file_get_contents(), which can exhaust memory on large
exports and also match table-like tokens inside INSERT data. Refactor
get_imported_table_names to scan the file stream incrementally, similar to
replace_db_prefix(), and extract table names only from statement starts using
the existing CREATE TABLE / INSERT INTO / LOCK TABLES patterns anchored near the
beginning of each statement. Keep the return shape the same and preserve
deduplication via array_unique.

---

Nitpick comments:
In `@tests/WP_Ultimo/Site_Exporter_Test.php`:
- Around line 239-246: The multisite test setup in
test_wp_sites_row_actions_include_subsite_export_and_promotion is bypassing the
repository’s fixture convention by using the raw blog factory. Replace the
direct self::factory()->blog->create() call with the appropriate wu_create_*()
helper used for creating subsites in tests, keeping the rest of the assertions
in add_wp_sites_row_actions unchanged.
🪄 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: 53c9d01f-6de2-47fa-8f3b-c15e1de82747

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca46e2 and 54a6a3c.

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

@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-25T17:15:35Z aidevops_version=3.22.1 opencode_version=1.17.9

@superdav42 superdav42 added the status:available Task is available for claiming label Jun 25, 2026
@superdav42 superdav42 merged commit 99a3c1a into main Jun 25, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • expose main-site single-site export from Network Admin > Sites row and bulk actions
  • keep "Promote to Main Site" hidden for the main site while preserving subsite promotion
  • scope MU-Migration import search-replace to imported SQL tables so main-site imports do not rewrite existing network rows
  • add regression tests for main-site export actions, bulk export queueing, and imported-table parsing

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/commands/class-mu-migration-import.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/commands/class-mu-migration-import.php tests/WP_Ultimo/Site_Exporter_Test.php
  • Manual: fresh single-site install with only Ultimate Multisite active exposed Tools > Export & Import, exported /tmp/opencode/um-single-site-export.zip, imported into dev multisite as blog ID 60, and verified Single Export Verification page
  • Manual: exported multisite main site to /tmp/opencode/um-main-site-export.zip, reimported after scoped search-replace fix as blog ID 62, verified Main Site Export Verification page, and confirmed existing network site URLs stayed intact

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


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

@superdav42 superdav42 added the review-feedback-scanned Merged PR already scanned for quality feedback label Jun 26, 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