• Using WP-CFM to distribute default settings to distributed sites. Changed the configuration file location via add_filter('wpcfm_config_dir', <function>), and changed file type to yaml via add_filter('wpcfm_config_format', <function>). Attempting to use wpcli commands to diff. Both wp config push <bundle> and wp config pull <bundle> work correctly. If I do wp config diff <bundle> and the values in the db are identical to the values in the config file, then I get the expected Warning: Both versions are identical. However, if the configuration file is changed and I attempt to do wp config diff <bundle> I receive the error

    
    PHP Warning:  Invalid argument supplied for foreach() in /app/web/wp-content/mu-plugins/wp-cfm/includes/class-wp-cli.php on line 92
    PHP Warning:  Invalid argument supplied for foreach() in /app/web/wp-content/mu-plugins/wp-cfm/includes/class-wp-cli.php on line 100
    

    If I debug the contents of $compare at those lines, it contains a linefeed separated string of my configuration values, not an array of values as expected.

    SAMPLE:

    
    cache_control_attachment_max_age: \'10800\'
    cache_control_attachment_staleerror: \'10800\'
    cache_control_attachment_stalereval: \'10800\'
    cache_control_attachment_s_maxage: \'5400\'
    

    Running Diff in the web gui returns the expected differences.

    WordPress is version 5.2.1.
    WP-CFM is version 1.5.1.
    PHP is version 7.2.19

    Running WP-CFM as a must-use plugin.

    Any ideas on why this is breaking?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Paul Gilzow

    (@gilzow)

    I’ll also mention that the yaml file passes a yaml lint check. I also put the config file type back to json, converted the yaml data to json and created a json bundle. The exact same scenario as described above happens. Everything works correctly until the data in the config differs from the db and I run a diff from the CLI.

    Thread Starter Paul Gilzow

    (@gilzow)

    tangentially related, if I spin up a site where the bundle file is present, but no db entry has been created yet and do a diff from the CLI, I also get a WARNING for class-readwrite.php

    PHP Warning: Invalid argument supplied for foreach() in /app/web/wp-content/mu-plugins/wp-cfm/includes/class-readwrite.php on line 261

    In looking at the code, line 259 is going to retrieve the options for wpcfm_settings. Since it isn’t set yet, get_option() is going to return a boolean false. a json_decode() on a boolean false at line 260 is going to return NULL. Hence the error at 261.

    Doing
    wp config bundles shows the bundle and notes it is not in the DB. Is there a way to retrieve just the In DB column+value for a bundle? If so, I could just check that before attempting a diff. I had just assumed running a diff when the values aren’t in the db would say there’s a diff and then I could pull the bundle into the db.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wpcli diff returning invalid argument supplied for foreach’ is closed to new replies.