Skip to content

Fix Windows blueprint import cleanup#280

Open
bcotrim wants to merge 2 commits into
WordPress:trunkfrom
bcotrim:fix-windows-blueprint-import-cleanup
Open

Fix Windows blueprint import cleanup#280
bcotrim wants to merge 2 commits into
WordPress:trunkfrom
bcotrim:fix-windows-blueprint-import-cleanup

Conversation

@bcotrim
Copy link
Copy Markdown

@bcotrim bcotrim commented May 18, 2026

Summary

This fixes Windows failures when running blueprints.phar against an existing Studio site using native PHP.

There are two related issues:

  1. WXR imports append PHP code to scripts/import-content.php, but that script already starts PHP and does not close it. Adding another <?php/?> wrapper can make the generated import subprocess script invalid.
  2. Temporary workspace cleanup can fail on Windows after blueprint execution, likely because files/directories are still briefly held by subprocesses. That cleanup failure should not mask an otherwise successful blueprint run.

Changes

  • Remove the extra PHP opening/closing tags around the appended run_content_import([...]) call.
  • Catch FilesystemException during final temporary workspace cleanup so a cleanup failure does not fail successful blueprint execution.

Testing Instructions

Tested on Windows using PHP 8.4 and a Studio-created SQLite site.

  1. Create a site in Studio.

  2. Quit Studio.

  3. Ensure the SQLite integration is available at:

    C:\Users\<user>\Studio\<site>\wp-content\plugins\sqlite-database-integration

    If Studio only has it under mu-plugins, create a junction/symlink from plugins to mu-plugins.

  4. If the Studio site's wp-config.php does not define DB_NAME, temporarily add:

    define( 'DB_NAME', 'wordpress' );
  5. Download and extract a blueprint bundle that imports WXR content, for example:

    http://blueprintlibrary.wordpress.com/?blueprint=829
    
  6. As a control, run the latest GitHub blueprints.phar against the site:

    $env:OUTPUT_FILE = "$env:TEMP\blueprints-control-output.jsonl"
    
    php "C:\Users\<user>\Downloads\blueprints.phar" exec "C:\Users\<user>\Downloads\organization-koinonia\blueprint.json" `
      --mode=apply-to-existing-site `
      --site-path="C:\Users\<user>\Studio\<site>" `
      --site-url=http://localhost:<port> `
      --db-engine=sqlite
    
    Get-Content $env:OUTPUT_FILE
    Remove-Item Env:\OUTPUT_FILE

    Before this patch, the run failed with:

    {"type":"error","message":"Failed to remove directory: C:/Users/.../AppData/Local/Temp/wp-blueprints-runtime-..."}
  7. Build the patched PHAR:

    composer build-blueprints-phar
  8. Run the same blueprint with the patched PHAR:

    $env:OUTPUT_FILE = "$env:TEMP\blueprints-pr280-output.jsonl"
    
    php dist\blueprints.phar exec "C:\Users\<user>\Downloads\organization-koinonia\blueprint.json" `
      --mode=apply-to-existing-site `
      --site-path="C:\Users\<user>\Studio\<site>" `
      --site-url=http://localhost:<port> `
      --db-engine=sqlite
    
    Get-Content $env:OUTPUT_FILE
    Remove-Item Env:\OUTPUT_FILE
  9. Confirm the output contains:

    {"type":"completion","message":"Blueprint successfully executed."}
  10. Restore wp-config.php if DB_NAME was added only for this test.

@bcotrim bcotrim marked this pull request as ready for review May 18, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant