OSDN Git Service

Only use maintenance mode if a plugin or theme needs updating
authorJames Collins <james@jamesc.id.au>
Wed, 5 Jun 2013 12:42:10 +0000 (22:42 +1000)
committerJames Collins <james@jamesc.id.au>
Wed, 5 Jun 2013 12:42:10 +0000 (22:42 +1000)
When updating plugins (wp plugin update-all) or themes (wp theme update-all) on a WordPress multisite installation, maintenance activated and deactivated even if there are no updates to install.

The Plugin_Upgrader::bulk_upgrade() and Theme_Upgrader::bulk_upgrade() WordPress functions currently don't check that the array passed to it isn't empty, causing maintenance mode to be enabled even if no updates are required.

This bug doesn't affect non multisite installs, because for non multisite installs the code in Plugin_Upgrader::bulk_upgrade() and Theme_Upgrader::bulk_upgrade() only uses maintenance mode if the plugin/theme being updated is activated.

Fixes #491

php/WP_CLI/CommandWithUpgrade.php

index 50c4bc1..f02f3c6 100644 (file)
@@ -179,7 +179,8 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {
                }
 
                $upgrader = \WP_CLI\Utils\get_upgrader( $this->upgrader );
-               $result = $upgrader->bulk_upgrade( wp_list_pluck( $items_to_update, 'update_id' ) );
+
+               $result = count($items_to_update) ? $upgrader->bulk_upgrade( wp_list_pluck( $items_to_update, 'update_id' ) ) : array();
 
                // Let the user know the results.
                $num_to_update = count( $items_to_update );