protected function get_upgrader($assoc_args) { $upgrader_class = $this->get_upgrader_class(\WP_CLI\Utils\get_flag_value($assoc_args, 'force')); return \WP_CLI\Utils\get_upgrader($upgrader_class); }
protected function get_upgrader($assoc_args) { $upgrader_class = $this->get_upgrader_class(isset($assoc_args['force'])); return \WP_CLI\Utils\get_upgrader($upgrader_class); }
protected function install_from_repo($slug, $assoc_args) { $result = NULL; $api = themes_api('theme_information', array('slug' => $slug)); if (is_wp_error($api)) { if (null === maybe_unserialize($api->get_error_data())) { WP_CLI::error("Can't find the theme in the WordPress.org repository."); } else { WP_CLI::error($api); } } // Check to see if we should update, rather than install. if ($this->has_update($slug)) { WP_CLI::line(sprintf('Updating %s (%s)', $api->name, $api->version)); $result = WP_CLI\Utils\get_upgrader($this->upgrader)->upgrade($slug); /** * Else, if there's no update, it's either not installed, * or it's newer than what we've got. */ } else { if (!is_readable($this->get_stylesheet_path($slug))) { WP_CLI::line(sprintf('Installing %s (%s)', $api->name, $api->version)); $result = WP_CLI\Utils\get_upgrader($this->upgrader)->install($api->download_link); } else { WP_CLI::error('Theme already installed and up to date.'); } } // Finally, activate theme if requested. if ($result && isset($assoc_args['activate'])) { WP_CLI::line("Activating '{$slug}'..."); $this->activate(array($slug)); } }
/** * Update WordPress. * * @synopsis [<zip>] [--version=<version>] [--force] */ function update($args, $assoc_args) { global $wp_version; $update = $from_api = null; $upgrader = 'Core_Upgrader'; if (empty($assoc_args['version'])) { wp_version_check(); $from_api = get_site_transient('update_core'); if (empty($from_api->updates)) { $update = false; } else { list($update) = $from_api->updates; } } else { if (version_compare($wp_version, $assoc_args['version'], '<') || isset($assoc_args['force'])) { $new_package = null; if (empty($args[0])) { $new_package = 'https://wordpress.org/wordpress-' . $assoc_args['version'] . '.zip'; WP_CLI::line(sprintf('Downloading WordPress %s (%s)...', $assoc_args['version'], 'en_US')); } else { $new_package = $args[0]; $upgrader = 'Non_Destructive_Core_Upgrader'; } $update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package)); } else { WP_CLI::success('WordPress is up to date.'); return; } } require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $result = WP_CLI\Utils\get_upgrader($upgrader)->upgrade($update); if (is_wp_error($result)) { $msg = WP_CLI::error_to_string($result); if ('up_to_date' != $result->get_error_code()) { WP_CLI::error($msg); } else { WP_CLI::success($msg); } } else { WP_CLI::success('WordPress updated successfully.'); } }
function update_all($args, $assoc_args) { call_user_func($this->upgrade_refresh); $items_to_update = wp_list_filter($this->get_item_list(), array('update' => true)); if (isset($assoc_args['dry-run'])) { $item_list = "Available {$this->item_type} updates:"; if (empty($items_to_update)) { $item_list .= " none"; } else { foreach ($items_to_update as $file => $details) { $item_list .= "\n\t%y" . $details['name'] . "%n"; } } WP_CLI::line($item_list); return; } $upgrader = WP_CLI\Utils\get_upgrader($this->upgrader); $result = $upgrader->bulk_upgrade(wp_list_pluck($items_to_update, 'update_id')); // Let the user know the results. $num_to_update = count($items_to_update); $num_updated = count(array_filter($result)); $line = "Updated {$num_updated}/{$num_to_update} {$this->item_type}s."; if ($num_to_update == $num_updated) { WP_CLI::success($line); } else { if ($num_updated > 0) { WP_CLI::warning($line); } else { WP_CLI::error($line); } } }
protected function install_from_repo($slug, $assoc_args) { $api = plugins_api('plugin_information', array('slug' => $slug)); if (is_wp_error($api)) { if (null === maybe_unserialize($api->get_error_data())) { WP_CLI::error("Can't find the plugin in the WordPress.org repository."); } else { WP_CLI::error($api); } } if (isset($assoc_args['version'])) { list($link) = explode($slug, $api->download_link); if ('dev' == $assoc_args['version']) { $api->download_link = $link . $slug . '.zip'; $api->version = 'Development Version'; } else { $api->download_link = $link . $slug . '.' . $assoc_args['version'] . '.zip'; $api->version = $assoc_args['version']; // check if the requested version exists $response = wp_remote_head($api->download_link); if (!$response || $response['headers']['content-type'] != 'application/octet-stream') { WP_CLI::error("Can't find the requested plugin's version " . $assoc_args['version'] . " in the WordPress.org plugins repository."); } } } $status = install_plugin_install_status($api); WP_CLI::line(sprintf('Installing %s (%s)', $api->name, $api->version)); switch ($status['status']) { case 'update_available': case 'install': $upgrader = WP_CLI\Utils\get_upgrader($this->upgrader); $result = $upgrader->install($api->download_link); if ($result && isset($assoc_args['activate'])) { WP_CLI::line("Activating '{$slug}'..."); $this->activate(array($slug)); } break; case 'newer_installed': WP_CLI::error(sprintf('Newer version (%s) installed.', $status['version'])); break; case 'latest_installed': WP_CLI::error('Latest version already installed.'); break; } }