Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update themeunittestdata.wordpress.xml with CORS-accessible images #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dd32
Copy link
Member

@dd32 dd32 commented May 2, 2024

This PR attempts to replace the image URLs in the WXR with a variant that will be importable into Playground.

This has been untested as-is. This is provided such that others can give it a try. The WXR url to be used would be this:

https://raw.githubusercontent.com/WordPress/theme-test-data/try/cors-accessible-images/themeunittestdata.wordpress.xml

See #82 (comment) for the idea behind this.

See #82

@flexseth
Copy link

flexseth commented May 2, 2024

Tested and received the following error, using wp-now (same on playground.wordpress.net)

Uncaught Error: Call to undefined function wp_generate_attachment_metadata()
mode: playground
php: 8.0
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
blueprint steps: 2
Blueprint step completed: login
Blueprint step completed: installPlugin
PHP.run() output was: {
  stdout: '<br />\n' +
    '<b>Fatal error</b>:  Uncaught Error: Call to undefined function wp_generate_attachment_metadata() in /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php:1067\n' +
    'Stack trace:\n' +
    "#0 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(861): **WXR_Importer-&gt;process_attachment**(Array, Array, 'https://i0.wp.c...')\n" +
    '#1 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(383): **WXR_Importer-&gt;process_post**(Array, Array, Array, Array)\n' +
    "#2 php-wasm run script(17): WXR_Importer-&gt;import('/tmp/import.wxr')\n" +
    '#3 {main}\n' +
    '  thrown in <b>/var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php</b> on line <b>1067</b><br />\n',
  stderr: 'PHP Fatal error:  Uncaught Error: Call to undefined function wp_generate_attachment_metadata() in /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php:1067\n' +
    'Stack trace:\n' +
    "#0 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(861): WXR_Importer->process_attachment(Array, Array, 'https://i0.wp.c...')\n" +
    '#1 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(383): WXR_Importer->process_post(Array, Array, Array, Array)\n' +
    "#2 php-wasm run script(17): WXR_Importer->import('/tmp/import.wxr')\n" +
    '#3 {main}\n' +
    '  thrown in /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php on line 1067\n'
}

possible culprits
WXR_Importer->process_attachment
WXR_Importer->process_post

Error: PHP.run() failed with exit code 255 and the following output: PHP Fatal error:  Uncaught Error: Call to undefined function wp_generate_attachment_metadata() in /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php:1067
Stack trace:
#0 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(861): WXR_Importer->process_attachment(Array, Array, 'https://i0.wp.c...')
#1 /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php(383): WXR_Importer->process_post(Array, Array, Array, Array)
#2 php-wasm run script(17): WXR_Importer->import('/tmp/import.wxr')
#3 {main}
  thrown in /var/www/html/wp-content/plugins/WordPress-Importer-master/class-wxr-importer.php on line 1067

    at _NodePHP.run (/Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@php-wasm/node/index.cjs:72937:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.importWxr (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:912:3)
    at async o (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:9413:30)
    at async Object.run (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:9340:23)
    at async runBlueprintSteps (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:9448:3)
    at async startWPNow (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:663:5)
    at async startServer (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:981:42)
    at async Object.handler (file:///Users/seth/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:1167:25) {

blueprint

{
    "$schema": "https://playground.wordpress.net/blueprint-schema.json",
    "preferredVersions": {
      "php": "8.2",
      "wp": "6.5"
    },
    "phpExtensionBundles": [
      "kitchen-sink"
    ],
    "features": {
      "networking": true
    },
    "steps": [
      {
        "step": "login",
        "username": "admin",
        "password": "password"
      },
      {
        "step": "importWxr",
            "file": {
                "resource": "url",
                "url": "https://raw.githubusercontent.com/WordPress/theme-test-data/try/cors-accessible-images/themeunittestdata.wordpress.xml"
            }
      }
    ]
  }

Playground URL
https://playground.wordpress.net/?php=8.0&wp=6.4&storage=none&networking=yes&import-content=https://raw.githubusercontent.com/WordPress/theme-test-data/try/cors-accessible-images/themeunittestdata.wordpress.xml

@dd32
Copy link
Member Author

dd32 commented May 3, 2024

Tested and received the following error, using wp-now (same on playground.wordpress.net)

Uncaught Error: Call to undefined function wp_generate_attachment_metadata()

That's unrelated to this PR, that's either an Importer or Playground issue. I suspect the Importer isn't including the wp-admin related files, as it expects to be run within wp-admin only, and partly the fault of playground for not running the import in the context of wp-admin.

The fact you got to that point of the process suggets the image fetch worked though, so the PR is probably good, the above error not withstanding.

@flexseth
Copy link

flexseth commented May 3, 2024

Ok, I tested it in another local dev environment.

For some reason it wasn't able to import the following posts, errors below

Failed to import Media “St. Louis Blues”
Failed to import Media “2014-slider-mobile-behavior”

2024/05/03 15:48:59 [warn] 20232#0: *24 a client request body is buffered to a temporary file 

.....client_body_temp/0000000001, 
client: ::1, 
server: ........, 
request: "POST /wp-login.php HTTP/1.1", 
host: "..........", 
referrer: "http://......../wp-login.php?redirect_to=http%3A%2F%2F..........%2Fwp-admin%2F&reauth=1"

2024/05/03 15:50:33 [warn] 20232#0: 
*221 a client request body is buffered to a temporary file ......., 
client: ::1, 
server: .........,
request: "POST /wp-admin/admin.php?import=wordpress&step=1&_wpnonce=......... HTTP/1.1", 
host: "..........", 
referrer: "http://............/wp-admin/import.php?import=wordpress"

otherwise the import seems to work as expected across domains

Copy link

@flexseth flexseth left a comment

Choose a reason for hiding this comment

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

other than two posts not importing, this appears to solve the cross-origin domain issue

posts in question

  • Note: There are errors when attempting to import to Playground, but these appear to be related to the way the WordPress importer is loading in Playground

@dd32
Copy link
Member Author

dd32 commented May 31, 2024

This PR isn't going to be viable.

While it's a quick fix for images, it doesn't work for the dozen .mov files included.

I feel the correct option is to include the files in the repo instead.

@dd32 dd32 force-pushed the try/cors-accessible-images branch from 8a3d77b to 883e56b Compare May 31, 2024 04:49
@dd32
Copy link
Member Author

dd32 commented May 31, 2024

I've converted this to pull from github instead, which works 100%.

The problem now is that Playground times out during import of attachments, as it times out waiting on PHP. Similar to what happens to most end-users during a WXR Import :)

Before merging this would need sed -i 's#try/cors-accessible-images#master#g' themeunittestdata.wordpress.xml run on the file to reflect the new location of the branch files.

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.

2 participants