WordPress / blueprints-library

31 stars 7 forks source link

Make Blueprint steps documentRoot agnostic #38

Open sejas opened 11 months ago

sejas commented 11 months ago

Description

I've found some users setSiteOptions blueprint step on wp-now get some errors due the documentRoot being hardcoded instead of reading the value from

https://github.com/WordPress/wordpress-playground/blob/45233583e635f35c0751b5340dfa07102eabbc46/packages/playground/blueprints/src/lib/steps/site-data.ts#L37

Can we make the

Steps to reproduce

  1. Create a file called blueprint.json with this content
    {
        "landingPage": "/friends/",
        "steps": [
            {
                "step": "setSiteOptions",
                "options": {
                    "permalink_structure": "/%year%/%monthnum%/%day%/%postname%/"
                }
            }
        ]
    }
  2. Run npx @wp-now/wp-now start --blueprint=blueprint.json
  3. See the error:
    
    npx @wp-now/wp-now start --blueprint=blueprint.json                                                                                                                                                                                                                                                    х INT 16m 25s Node 20.8.1 11:18:08
    Starting the server......
    directory: /Users/macbookpro/Downloads/downloads/friends
    mode: plugin
    php: 8.0
    wp: latest
    WordPress latest folder already exists. Skipping download.
    SQLite folder already exists. Skipping download.
    blueprint steps: 1
    PHPResponse {
    headers: {
    'x-powered-by': [ 'PHP/8.0.10-dev' ],
    'content-type': [ 'text/html; charset=UTF-8' ]
    },
    bytes: Uint8Array(516) [
     60,  98, 114,  32,  47,  62,  10,  60,  98,  62,  87,  97,
    114, 110, 105, 110, 103,  60,  47,  98,  62,  58,  32,  32,
    105, 110,  99, 108, 117, 100, 101,  40, 119, 111, 114, 100,
    112, 114, 101, 115, 115,  47, 119, 112,  45, 108, 111,  97,
    100,  46, 112, 104, 112,  41,  58,  32,  70,  97, 105, 108,
    101, 100,  32, 116, 111,  32, 111, 112, 101, 110,  32, 115,
    116, 114, 101,  97, 109,  58,  32,  78, 111,  32, 115, 117,
     99, 104,  32, 102, 105, 108, 101,  32, 111, 114,  32, 100,
    105, 114, 101,  99,
    ... 416 more items
    ],
    errors: 'PHP Warning:  include(wordpress/wp-load.php): Failed to open stream: No such file or directory in php-wasm run script on line 2\n' +
    "PHP Warning:  include(): Failed opening 'wordpress/wp-load.php' for inclusion (include_path='.:') in php-wasm run script on line 2\n" +
    'PHP Fatal error:  Uncaught Error: Call to undefined function update_option() in php-wasm run script:5\n' +
    'Stack trace:\n' +
    '#0 {main}\n' +
    '  thrown in php-wasm run script on line 5\n',
    exitCode: 2,
    httpStatusCode: 200
    }
    Blueprint step completed: setSiteOptions
    /Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@php-wasm/node/index.cjs:17841
      throw reason;
      ^

Error: Failed to run code:
Warning: include(wordpress/wp-load.php): Failed to open stream: No such file or directory in php-wasm run script on line 2

Warning: include(): Failed opening 'wordpress/wp-load.php' for inclusion (include_path='.:') in php-wasm run script on line 2

Fatal error: Uncaught Error: Call to undefined function update_option() in php-wasm run script:5 Stack trace:

0 {main}

thrown in php-wasm run script on line 5
PHP Warning: include(wordpress/wp-load.php): Failed to open stream: No such file or directory in php-wasm run script on line 2 PHP Warning: include(): Failed opening 'wordpress/wp-load.php' for inclusion (include_path='.:') in php-wasm run script on line 2 PHP Fatal error: Uncaught Error: Call to undefined function update_option() in php-wasm run script:5 Stack trace:

0 {main}

thrown in php-wasm run script on line 5

at Q (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:502:27)
at Module.Ce [as setSiteOptions] (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:486:10)
at async o (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:2044:30)
at async Object.run (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:2007:21)
at async yt (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-playground/blueprints/index.js:2079:3)
at async startWPNow (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:596:5)
at async startServer (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:865:42)
at async Object.handler (file:///Users/macbookpro/.npm/_npx/7c65af5c66ec2a7e/node_modules/@wp-now/wp-now/main.js:1037:25)

Node.js v20.8.1



Expected:
3. Observe the WordPress site opening correctly and non errors appear in the console.
sejas commented 11 months ago

A workaround until this is fixed is running php step:

{
    "landingPage": "/friends/",
    "steps": [
        {
            "step": "runPHP",
            "code": "<?php include '/var/www/html/wp-load.php'; update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');"
        }
    ]
}
adamziel commented 11 months ago

cc @reimic – you might want to take a look at this one

reimic commented 11 months ago

Gladly, I am in the process of writing unit tests for all steps. I'll prioritize the site-data steps, of which SetSiteOptionsStep is one.