Skip to content

Commit 37f9901

Browse files
authored
Fix update checks when --skip-plugins or --skip-themes is used (#553)
1 parent 0414ef0 commit 37f9901

4 files changed

Lines changed: 408 additions & 1 deletion

File tree

‎extension-command.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,17 @@ static function () {
5656
);
5757
}
5858
);
59+
60+
// Update data stored while --skip-plugins or --skip-themes is in effect must not
61+
// outlive the process, as it lacks what the skipped plugins or themes would have
62+
// added for themselves.
63+
WP_CLI::add_hook(
64+
'before_wp_load',
65+
static function () {
66+
$arguments = WP_CLI::get_runner()->arguments;
67+
68+
if ( isset( $arguments[0] ) && in_array( $arguments[0], [ 'plugin', 'theme' ], true ) ) {
69+
\WP_CLI\CommandWithUpgrade::discard_update_data_stored_while_skipping();
70+
}
71+
}
72+
);

‎features/plugin-update.feature‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,106 @@ Feature: Update WordPress plugins
436436
"""
437437
Success: Updated 1 of 1 plugins.
438438
"""
439+
440+
Scenario: Updating a plugin whose own update mechanism is skipped with --skip-plugins
441+
Given a WP install
442+
And a wp-content/plugins/premium-updater-simulation/premium-updater-simulation.php file:
443+
"""
444+
<?php
445+
/**
446+
* Plugin Name: Premium Updater Simulation
447+
* Description: Mimics a premium plugin whose license does not allow downloading the update.
448+
* Version: 1.0.0
449+
*/
450+
451+
add_filter(
452+
'pre_set_site_transient_update_plugins',
453+
function ( $transient ) {
454+
if ( ! is_object( $transient ) ) {
455+
$transient = new stdClass();
456+
}
457+
458+
$transient->response['premium-updater-simulation/premium-updater-simulation.php'] = (object) [
459+
'id' => 'premium-updater-simulation/premium-updater-simulation.php',
460+
'slug' => 'premium-updater-simulation',
461+
'plugin' => 'premium-updater-simulation/premium-updater-simulation.php',
462+
'new_version' => '2.0.0',
463+
'url' => '',
464+
'package' => '',
465+
];
466+
467+
return $transient;
468+
}
469+
);
470+
"""
471+
And I run `wp plugin activate premium-updater-simulation`
472+
473+
# Update data fetched while plugins are skipped must not be reused by later runs.
474+
When I run `wp plugin list --skip-plugins --fields=name,update`
475+
Then STDOUT should be a table containing rows:
476+
| name | update |
477+
| premium-updater-simulation | none |
478+
479+
When I try `wp plugin update premium-updater-simulation`
480+
Then STDERR should contain:
481+
"""
482+
Warning: Update package not available.
483+
"""
484+
And STDOUT should end with a table containing rows:
485+
| name | old_version | new_version | status |
486+
| premium-updater-simulation | 1.0.0 | 2.0.0 | Error |
487+
And STDERR should contain:
488+
"""
489+
Error: No plugins updated (1 failed).
490+
"""
491+
And the return code should be 1
492+
493+
# Once the update data is refreshed without the plugin's update mechanism, the plugin must not be mistaken for being up to date.
494+
When I try `wp transient delete update_plugins --network`
495+
And I try `wp plugin update premium-updater-simulation --skip-plugins`
496+
Then STDERR should be:
497+
"""
498+
Warning: premium-updater-simulation: Could not determine whether an update is available. The plugin's own update mechanism might not have run because --skip-plugins is in effect.
499+
Error: No plugins updated.
500+
"""
501+
And STDOUT should be empty
502+
And the return code should be 1
503+
504+
# Plugins that WordPress.org reported on are not affected.
505+
When I try `wp plugin update --all --skip-plugins --dry-run`
506+
Then STDERR should contain:
507+
"""
508+
Warning: premium-updater-simulation: Could not determine whether an update is available. The plugin's own update mechanism might not have run because --skip-plugins is in effect.
509+
"""
510+
511+
# Excluded plugins are not warned about.
512+
When I try `wp plugin update --all --skip-plugins --exclude=premium-updater-simulation --dry-run`
513+
Then STDERR should not contain:
514+
"""
515+
premium-updater-simulation
516+
"""
517+
518+
# Update data fetched while plugins were skipped is not reused once plugins are loaded again.
519+
When I try `wp plugin update premium-updater-simulation`
520+
Then STDERR should contain:
521+
"""
522+
Warning: Update package not available.
523+
"""
524+
And STDERR should contain:
525+
"""
526+
Error: No plugins updated (1 failed).
527+
"""
528+
And the return code should be 1
529+
530+
# Skipping other plugins leaves the plugin's update mechanism running.
531+
When I try `wp transient delete update_plugins --network`
532+
And I try `wp plugin update premium-updater-simulation --skip-plugins=akismet`
533+
Then STDERR should contain:
534+
"""
535+
Warning: Update package not available.
536+
"""
537+
And STDERR should contain:
538+
"""
539+
Error: No plugins updated (1 failed).
540+
"""
541+
And the return code should be 1

‎features/theme-update.feature‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,167 @@ Feature: Update WordPress themes
288288
"""
289289
Success: Updated 1 of 1 themes.
290290
"""
291+
292+
Scenario: Updating a theme whose own update mechanism is skipped with --skip-themes
293+
Given a WP install
294+
And a wp-content/themes/premium-theme-simulation/style.css file:
295+
"""
296+
/*
297+
Theme Name: Premium Theme Simulation
298+
Description: Mimics a premium theme whose license does not allow downloading the update.
299+
Version: 1.0.0
300+
*/
301+
"""
302+
And a wp-content/themes/premium-theme-simulation/index.php file:
303+
"""
304+
<?php
305+
"""
306+
And a wp-content/themes/premium-theme-simulation/functions.php file:
307+
"""
308+
<?php
309+
add_filter(
310+
'pre_set_site_transient_update_themes',
311+
function ( $transient ) {
312+
if ( ! is_object( $transient ) ) {
313+
$transient = new stdClass();
314+
}
315+
316+
$transient->response['premium-theme-simulation'] = [
317+
'theme' => 'premium-theme-simulation',
318+
'new_version' => '2.0.0',
319+
'url' => '',
320+
'package' => '',
321+
];
322+
323+
return $transient;
324+
}
325+
);
326+
"""
327+
And I run `wp theme activate premium-theme-simulation`
328+
329+
# Update data fetched while themes are skipped must not be reused by later runs.
330+
When I run `wp theme list --skip-themes --fields=name,update`
331+
Then STDOUT should be a table containing rows:
332+
| name | update |
333+
| premium-theme-simulation | none |
334+
335+
When I try `wp theme update premium-theme-simulation`
336+
Then STDERR should contain:
337+
"""
338+
Warning: Update package not available.
339+
"""
340+
And STDOUT should end with a table containing rows:
341+
| name | old_version | new_version | status |
342+
| premium-theme-simulation | 1.0.0 | 2.0.0 | Error |
343+
And STDERR should contain:
344+
"""
345+
Error: No themes updated (1 failed).
346+
"""
347+
And the return code should be 1
348+
349+
# Once the update data is refreshed without the theme's update mechanism, the theme must not be mistaken for being up to date.
350+
When I try `wp transient delete update_themes --network`
351+
And I try `wp theme update premium-theme-simulation --skip-themes`
352+
Then STDERR should be:
353+
"""
354+
Warning: premium-theme-simulation: Could not determine whether an update is available. The theme's own update mechanism might not have run because --skip-themes is in effect.
355+
Error: No themes updated.
356+
"""
357+
And STDOUT should be empty
358+
And the return code should be 1
359+
360+
# Update data fetched while themes were skipped is not reused once themes are loaded again.
361+
When I try `wp theme update premium-theme-simulation`
362+
Then STDERR should contain:
363+
"""
364+
Warning: Update package not available.
365+
"""
366+
And STDERR should contain:
367+
"""
368+
Error: No themes updated (1 failed).
369+
"""
370+
And the return code should be 1
371+
372+
Scenario: Updating a theme whose update mechanism lives in a skipped companion plugin
373+
Given a WP install
374+
And a wp-content/themes/premium-theme-simulation/style.css file:
375+
"""
376+
/*
377+
Theme Name: Premium Theme Simulation
378+
Description: Mimics a premium theme whose updates are provided by a companion plugin.
379+
Version: 1.0.0
380+
*/
381+
"""
382+
And a wp-content/themes/premium-theme-simulation/index.php file:
383+
"""
384+
<?php
385+
"""
386+
And a wp-content/plugins/premium-theme-updater/premium-theme-updater.php file:
387+
"""
388+
<?php
389+
/**
390+
* Plugin Name: Premium Theme Updater
391+
* Description: Mimics a companion plugin providing updates for a premium theme.
392+
* Version: 1.0.0
393+
*/
394+
395+
add_filter(
396+
'pre_set_site_transient_update_themes',
397+
function ( $transient ) {
398+
if ( ! is_object( $transient ) ) {
399+
$transient = new stdClass();
400+
}
401+
402+
$transient->response['premium-theme-simulation'] = [
403+
'theme' => 'premium-theme-simulation',
404+
'new_version' => '2.0.0',
405+
'url' => '',
406+
'package' => '',
407+
];
408+
409+
return $transient;
410+
}
411+
);
412+
"""
413+
And I run `wp plugin activate premium-theme-updater`
414+
And I try `wp transient delete update_themes --network`
415+
416+
When I try `wp theme update premium-theme-simulation`
417+
Then STDERR should contain:
418+
"""
419+
Warning: Update package not available.
420+
"""
421+
And STDERR should contain:
422+
"""
423+
Error: No themes updated (1 failed).
424+
"""
425+
And the return code should be 1
426+
427+
When I try `wp transient delete update_themes --network`
428+
And I try `wp theme update premium-theme-simulation --skip-plugins`
429+
Then STDERR should be:
430+
"""
431+
Warning: premium-theme-simulation: Could not determine whether an update is available. The theme's own update mechanism might not have run because --skip-plugins is in effect.
432+
Error: No themes updated.
433+
"""
434+
And the return code should be 1
435+
436+
When I try `wp theme update premium-theme-simulation --skip-plugins --skip-themes`
437+
Then STDERR should be:
438+
"""
439+
Warning: premium-theme-simulation: Could not determine whether an update is available. The theme's own update mechanism might not have run because --skip-plugins and --skip-themes are in effect.
440+
Error: No themes updated.
441+
"""
442+
And the return code should be 1
443+
444+
# Skipping only unrelated themes leaves the companion plugin running.
445+
When I try `wp theme update premium-theme-simulation --skip-themes=twentytwentyfive`
446+
Then STDERR should contain:
447+
"""
448+
Warning: Update package not available.
449+
"""
450+
And STDERR should contain:
451+
"""
452+
Error: No themes updated (1 failed).
453+
"""
454+
And the return code should be 1

0 commit comments

Comments
 (0)