Skip to content

Import requires sed binary — fails in web/AJAX context for database prefix replacement #1013

Description

@superdav42

Bug

The mu-migration ImportCommand::tables() method (line 292-293) requires sed to be installed for database prefix replacement:

// Terminates the script if sed is not installed.
$this->check_for_sed_presence(true);

And replace_db_prefix() (line 685-715) uses sed via WP_CLI::launch():

$full_command = "sed '$sed_command' -i $filename";
$sed_result = \WP_CLI::launch($full_command, false, false);

However, in the web/AJAX context (non-CLI):

  1. WP_CLI::launch() is not available — the polyfill in helpers.php covers db tables, db export, db import, and search-replace, but NOT sed operations
  2. The check_for_sed_presence() method calls WP_CLI::launch('echo "wp_" | sed ...') which will crash in web context
  3. Even if sed is available on the system, the web user (www-data) may not have the same PATH

This means database prefix replacement during import is completely broken in web context.

Impact

Admin UI imports (which run in web/AJAX context) will crash when importing a site that has a different database prefix from the target site — which is the normal case for cross-network migrations.

Suggested Fix

Replace the sed dependency with a pure PHP string replacement using str_replace() or preg_replace() on the SQL file content. The replace_db_prefix() method does simple string substitution that doesn't require sed at all.

Files to modify

  • EDIT: inc/site-exporter/mu-migration/includes/commands/class-mu-migration-import.php:685-715 — replace sed calls with PHP str_replace
  • EDIT: inc/site-exporter/mu-migration/includes/commands/class-mu-migration-import.php:292-293 — remove sed presence check for web context

Severity

High — database imports from different prefix sources fail in web context.


aidevops.sh v3.13.11 plugin for OpenCode v1.3.17 with claude-opus-4-6 spent 8m and 17,664 tokens on this as a headless worker.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingorigin:workerAuto-created by pulse labelless backfill (t2112)status:in-progressWorker actively running

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions