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

PHP notice on updating theme translations with no updates #58

Closed
grappler opened this issue Sep 14, 2018 · 3 comments
Closed

PHP notice on updating theme translations with no updates #58

grappler opened this issue Sep 14, 2018 · 3 comments

Comments

@grappler
Copy link

When running the update command and there are no updates there is a PHP warning with WP-CLI 2.0.1

wp language theme update twentysixteen
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 91
Warning: Invalid argument supplied for foreach() in phar:///bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Success: Updated 0/0 translations.
@grappler grappler changed the title PHP noticw on updating theme translations with no updates PHP notice on updating theme translations with no updates Sep 14, 2018
@schlessera
Copy link
Member

Additional information provided by @swissspidy in duplicate issue #60 :


I'm currently getting the following PHP warnings when updating language packs on a site:

PHP Warning:  Invalid argument supplied for foreach() in phar:///usr/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Warning: Invalid argument supplied for foreach() in phar:///usr/bin/wp/vendor/wp-cli/language-command/src/WP_CLI/CommandWithTranslation.php on line 95
Success: Updated 0/0 translations.

The code in question is here:

$obj_type = rtrim( $this->obj_type, 's' );
$available_updates = $updates_per_type[ $obj_type ];
$num_to_update += count( $available_updates );
if ( ! Utils\get_flag_value( $assoc_args, 'dry-run' ) ) {
// Update translations.
foreach ( $available_updates as $update ) {
WP_CLI::line( "Updating '{$update->Language}' translation for {$update->Name} {$update->Version}..." );
$result = Utils\get_upgrader( $upgrader )->upgrade( $update );
$results[] = $result;
}
}
}

Looks like the code currently doesn't check whether $available_updates is actually set or is an array. We could add a continue statement in that case.

frozzare added a commit to frozzare/language-command that referenced this issue Oct 3, 2018
@ocean90
Copy link
Contributor

ocean90 commented Oct 4, 2018

@frozzare Did you forget to submit your change as a PR? 🙂

@frozzare
Copy link
Contributor

frozzare commented Oct 4, 2018

@ocean90 yeah, sorry. Did get so late last night so I forgot about this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants