wp-cli icon indicating copy to clipboard operation
wp-cli copied to clipboard

core check-update: Warning: Invalid argument supplied for foreach()

Open moses-moore-spafax opened this issue 10 years ago • 8 comments

I don't remember seeing this warning message before updating wp-cli to v0.25.0

# sudo -u mach -- php-cli /usr/local/bin/wp-cli core check-update
Warning: Invalid argument supplied for foreach() in phar:///usr/local/bin/wp-cli/php/commands/core.php on line 1389
Success: WordPress is at the latest version.

Steps to reproduce: see above. Expected: no "Warning:" message. Witnessed: warning about invalid arguments Environment:

# sudo -u mach -- php-cli /usr/local/bin/wp-cli --info
PHP binary: /usr/local/bin/php
PHP version:    5.6.27
php.ini used:   /usr/local/lib/php.ini
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 0.25.0
# sudo -u mach php-cli /usr/local/bin/wp-cli core version
4.6.1

More info: looking in commands/core.php:1389 I can see foreach ( $from_api->updates as $offer ) and before that $from_api = get_site_transient( 'update_core' );

# sudo -u mach php-cli /usr/local/bin/wp-cli transient type
Transients are saved to the wp_options table.
# sudo -u mach php-cli /usr/local/bin/wp-cli transient get update_core
Warning: Transient with key "update_core" is not set.

moses-moore-spafax avatar Oct 26 '16 18:10 moses-moore-spafax

The existing logic is:

wp_version_check();
$from_api = get_site_transient( 'update_core' );
if ( ! $from_api ) {
    return array();
}

$compare_version = str_replace( '-src', '', $GLOBALS['wp_version'] );

$updates = array(
    'major'      => false,
    'minor'      => false,
    );
foreach ( $from_api->updates as $offer ) {

I suppose we could check for if ( empty( $from_api->updates ) ) instead.

Any ideas how you ended up with a truthy but non-object value in the update_core transient?

danielbachhuber avatar Oct 26 '16 18:10 danielbachhuber

I don't remember seeing this warning message before updating wp-cli to v0.25.0

Which WP-CLI version were you running previously?

danielbachhuber avatar Oct 26 '16 18:10 danielbachhuber

which version

v0.24.1 I just downgraded, re-ran the command and got the same warning. I must be misremembering.

truthy but non-object in update_core transient?

No idea. "wp transient type" says I the transients are saved to the wp_options table, so I should be able to find it in there, right?

[mistakes deleted]

mysql mach_wp <<<"select * from wp_options where option_name like '%update_core%';"
option_id   
    970218  
option_name 
    _site_transient_update_core 
option_value    
    O:8:"stdClass":4:{s:7:"updates";a:1:{i:0;O:8:"stdClass":10:{s:8:"response";s:6:"latest";s:8:"download";s:59:"https://downloads.wordpress.org/release/wordpress-4.6.1.zip";s:6:"locale";s:5:"en_US";s:8:"packages";O:8:"stdClass":5:{s:4:"full";s:59:"https://downloads.wordpress.org/release/wordpress-4.6.1.zip";s:10:"no_content";s:70:"https://downloads.wordpress.org/release/wordpress-4.6.1-no-content.zip";s:11:"new_bundled";s:71:"https://downloads.wordpress.org/release/wordpress-4.6.1-new-bundled.zip";s:7:"partial";b:0;s:8:"rollback";b:0;}s:7:"current";s:5:"4.6.1";s:7:"version";s:5:"4.6.1";s:11:"php_version";s:5:"5.2.4";s:13:"mysql_version";s:3:"5.0";s:11:"new_bundled";s:3:"4.4";s:15:"partial_version";s:0:"";}}s:12:"last_checked";i:1476472540;s:15:"version_checked";s:5:"4.6.1";s:12:"translations";a:0:{}}    
autoload
    yes

moses-moore-spafax avatar Oct 26 '16 18:10 moses-moore-spafax

Edited the last comment for markdown typos and a dumb update_core/core_update mistake.

moses-moore-spafax avatar Oct 26 '16 19:10 moses-moore-spafax

I just copied the site & db over to another staging machine where I have four other wordpress sites, and php 5.5.9. Updated wp-cli and I still get the "foreach()" warning with the mach site, but not the other four sites. The mach site functions well, nothing broken as a website. and wp core update reports "Success: WordPress is up to date." with no warnings. This is bizarre, and I'm thinking the mach site is a fluke. Is there a way to reset transients, or force wordpress to wipe and remake the update_core transient?

moses-moore-spafax avatar Oct 26 '16 19:10 moses-moore-spafax

Is there a way to reset transients, or force wordpress to wipe and remake the update_core transient?

wp transient delete --all.

force wordpress to wipe and remake the update_core transient?

wp core check-update does this when it runs actually.

danielbachhuber avatar Oct 26 '16 19:10 danielbachhuber

weird.

# sudo -u mach php-cli /usr/local/bin/wp-cli transient delete --all
Success: 25 transients deleted from the database.
# sudo -u mach php-cli /usr/local/bin/wp-cli core check-update
Warning: Invalid argument supplied for foreach() in phar:///usr/local/bin/wp-cli/php/commands/core.php on line 1389
Success: WordPress is at the latest version.

same on the staging server clone, 'cept I can use php directly instead of php-cli first.

moses-moore-spafax avatar Oct 26 '16 19:10 moses-moore-spafax

Ok. I think this problem is specific to your environment — something (plugin or similar) must be clobbering the data somehow.

danielbachhuber avatar Oct 26 '16 19:10 danielbachhuber