/** * Update WordPress. * * ## OPTIONS * * [<zip>] * : Path to zip file to use, instead of downloading from wordpress.org. * * [--version=<version>] * : Update to this version, instead of to the latest version. * * [--force] * : Update even when installed WP version is greater than the requested version. * * [--locale=<locale>] * : Select which language you want to download. * * ## EXAMPLES * * wp core update * * wp core update --version=3.8 ../latest.zip * * wp core update --version=3.1 --force * * @alias upgrade */ function update($args, $assoc_args) { global $wp_version; $update = $from_api = null; $upgrader = 'WP_CLI\\CoreUpgrader'; if (!empty($args[0])) { $upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader'; $version = !empty($assoc_args['version']) ? $assoc_args['version'] : null; $update = (object) array('response' => 'upgrade', 'current' => $version, 'download' => $args[0], 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $args[0]), 'version' => $version, 'locale' => null); } else { 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'])) { $version = $assoc_args['version']; $locale = isset($assoc_args['locale']) ? $assoc_args['locale'] : get_locale(); $new_package = $this->get_download_url($version, $locale); $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), 'version' => $version, 'locale' => $locale); } else { WP_CLI::success('WordPress is up to date.'); return; } } } require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if ($update->version) { WP_CLI::log("Updating to version {$update->version} ({$update->locale})..."); } else { WP_CLI::log("Starting update..."); } $GLOBALS['wp_cli_update_obj'] = $update; $result = Utils\get_upgrader($upgrader)->upgrade($update); unset($GLOBALS['wp_cli_update_obj']); 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.'); } }
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); }
/** * Update WordPress. * * ## OPTIONS * * [<zip>] * : Path to zip file to use, instead of downloading from wordpress.org. * * [--version=<version>] * : Update to this version, instead of to the latest version. * * [--force] * : Will update even when current WP version < passed version. Use with * caution. * * ## EXAMPLES * * wp core update * * wp core update --version=3.4 ../latest.zip * * wp core update --version=3.1 --force * * @alias upgrade */ 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::log(sprintf('Downloading WordPress %s (%s)...', $assoc_args['version'], 'en_US')); } else { $new_package = $args[0]; $upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader'; } $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 = 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.'); } }
/** * Update WordPress. * * ## OPTIONS * * [<zip>] * : Path to zip file to use, instead of downloading from wordpress.org. * * [--minor] * : Only perform updates for minor releases (e.g. update from WP 4.3 to 4.3.3 instead of 4.4.2). * * [--version=<version>] * : Update to a specific version, instead of to the latest version. * * [--force] * : Update even when installed WP version is greater than the requested version. * * [--locale=<locale>] * : Select which language you want to download. * * ## EXAMPLES * * wp core update * * wp core update --version=3.8 ../latest.zip * * wp core update --version=3.1 --force * * @alias upgrade */ function update($args, $assoc_args) { global $wp_version; $update = $from_api = null; $upgrader = 'WP_CLI\\CoreUpgrader'; if (empty($args[0]) && empty($assoc_args['version']) && \WP_CLI\Utils\get_flag_value($assoc_args, 'minor')) { $updates = $this->get_updates(array('minor' => true)); if (!empty($updates)) { $assoc_args['version'] = $updates[0]['version']; } else { WP_CLI::success('WordPress is at the latest minor release.'); return; } } if (!empty($args[0])) { $upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader'; $version = \WP_CLI\Utils\get_flag_value($assoc_args, 'version'); $update = (object) array('response' => 'upgrade', 'current' => $version, 'download' => $args[0], 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $args[0]), 'version' => $version, 'locale' => null); } else { if (empty($assoc_args['version'])) { wp_version_check(); $from_api = get_site_transient('update_core'); if (!empty($from_api->updates)) { list($update) = $from_api->updates; } } else { if (\WP_CLI\Utils\wp_version_compare($assoc_args['version'], '<') || \WP_CLI\Utils\get_flag_value($assoc_args, 'force')) { $version = $assoc_args['version']; $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', get_locale()); $new_package = $this->get_download_url($version, $locale); $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), 'version' => $version, 'locale' => $locale); } } } if (!empty($update) && ($update->version != $wp_version || \WP_CLI\Utils\get_flag_value($assoc_args, 'force'))) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if ($update->version) { WP_CLI::log("Updating to version {$update->version} ({$update->locale})..."); } else { WP_CLI::log("Starting update..."); } $from_version = $wp_version; $GLOBALS['wp_cli_update_obj'] = $update; $result = Utils\get_upgrader($upgrader)->upgrade($update); unset($GLOBALS['wp_cli_update_obj']); 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 { if (file_exists(ABSPATH . 'wp-includes/version.php')) { include ABSPATH . 'wp-includes/version.php'; $to_version = $wp_version; } $locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', get_locale()); $this->cleanup_extra_files($from_version, $to_version, $locale); WP_CLI::success('WordPress updated successfully.'); } } else { WP_CLI::success('WordPress is up to date.'); } }
/** * Updates VersionPress * * ## OPTIONS * * <zip> * : Path to ZIP file containing VersionPress. * * ## EXAMPLES * * wp vp update ../versionpress-4.0.zip * * */ public function update($args = [], $assoc_args = []) { global $versionPressContainer; $zip = $args[0]; if (!is_file($zip)) { WP_CLI::error("File '{$zip}' not found."); } $this->switchMaintenance('on'); /** @var Committer $committer */ $committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER); $committer->disableCommit(); vp_deactivate(); WP_CLI::success('Deactivated VersionPress'); /** @var \Plugin_Upgrader $upgrader */ $upgrader = WP_CLI\Utils\get_upgrader(WP_CLI\DestructivePluginUpgrader::class); // Use silent upgrader skin - we don't need any output from the upgrader $upgrader->skin = new SilentUpgraderSkin(); $result = $upgrader->run(['package' => $zip, 'destination' => WP_PLUGIN_DIR, 'hook_extra' => ['type' => 'plugin', 'action' => 'update', 'plugin' => 'versionpress/versionpress.php']]); if ($result) { WP_CLI::success('Updated VersionPress'); $process = $this->runVPInternalCommand('finish-update'); echo $process->getConsoleOutput(); $this->switchMaintenance('off'); } else { WP_CLI::error(join("\n", ['Update failed. Unfortunatelly, you have to manually update VersionPress.', ' 1. Delete wp-content/versionpress.', ' 2. Extract the ZIP to wp-content/versionpress.', ' 3. Run \'wp plugin activate versionpress\' and \'wp vp activate\'.', ' 4. Delete the \'.maintenance\' file.'])); } }