Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions features/option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,45 @@ Feature: Manage WordPress options
on
"""
Scenario: Report an error when the autoload value cannot be stored
Given a WP install
And a wp-content/mu-plugins/fail-autoload-update.php file:
"""
<?php
add_filter(
'query',
static function ( $query ) {
if ( false !== strpos( $query, 'SET `autoload` =' ) && false !== strpos( $query, "`option_name` = 'hello'" ) ) {
return 'UPDATE wp_cli_missing_table SET autoload = 1';
}
return $query;
}
);
"""
And I run `wp option add hello world --autoload=on`
When I try `wp option update hello world --autoload=off`
Then STDERR should contain:
"""
Error: Could not update autoload value for 'hello' option.
"""
And STDOUT should not contain:
"""
Success:
"""
And the return code should be 1
When I try `wp option set-autoload hello off`
Then STDERR should contain:
"""
Error: Could not update autoload value for 'hello' option.
"""
And STDOUT should not contain:
"""
Success:
"""
And the return code should be 1
@require-wp-4.2
@less-than-wp-6.6
Scenario: Managed autoloaded options
Expand Down
6 changes: 5 additions & 1 deletion src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,16 @@ public function set_autoload( $args ) {
return;
}

$wpdb->update(
$updated = $wpdb->update(
$wpdb->options,
array( 'autoload' => $autoload ),
array( 'option_name' => $option )
);

if ( false === $updated ) {
WP_CLI::error( "Could not update autoload value for '{$option}' option." );
}

// Recreate cache refreshing from update_option().
$notoptions = wp_cache_get( 'notoptions', 'options' );

Expand Down