get_http_cache_manager() public static method

public static get_http_cache_manager ( ) : WP_CLI\WpHttpCacheManager
return WP_CLI\WpHttpCacheManager
Ejemplo n.º 1
0
 protected function install_from_repo($slug, $assoc_args)
 {
     $api = themes_api('theme_information', array('slug' => $slug));
     if (is_wp_error($api)) {
         return $api;
     }
     if (isset($assoc_args['version'])) {
         self::alter_api_response($api, $assoc_args['version']);
     }
     if (!isset($assoc_args['force']) && wp_get_theme($slug)->exists()) {
         // We know this will fail, so avoid a needless download of the package.
         return new WP_Error('already_installed', 'Theme already installed.');
     }
     WP_CLI::log(sprintf('Installing %s (%s)', $api->name, $api->version));
     if (!isset($assoc_args['version']) || 'dev' !== $assoc_args['version']) {
         WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
     }
     $result = $this->get_upgrader($assoc_args)->install($api->download_link);
     return $result;
 }
Ejemplo n.º 2
0
 protected function update_many($args, $assoc_args)
 {
     call_user_func($this->upgrade_refresh);
     if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
         $logger = new \WP_CLI\Loggers\Quiet();
         \WP_CLI::set_logger($logger);
     }
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all') && empty($args)) {
         \WP_CLI::error("Please specify one or more {$this->item_type}s, or use --all.");
     }
     $items = $this->get_item_list();
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all')) {
         $items = $this->filter_item_list($items, $args);
     }
     $items_to_update = wp_list_filter($items, array('update' => true));
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) {
         if (empty($items_to_update)) {
             \WP_CLI::line("No {$this->item_type} updates available.");
             return;
         }
         if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
             \WP_CLI\Utils\format_items($assoc_args['format'], $items_to_update, array('name', 'status', 'version', 'update_version'));
         } else {
             if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) {
                 \WP_CLI::line("Available {$this->item_type} updates:");
                 foreach ($items_to_update as $item_to_update => $info) {
                     \WP_CLI::log("{$info['title']} update from version {$info['version']} to version {$info['update_version']}");
                 }
             } else {
                 \WP_CLI::line("Available {$this->item_type} updates:");
                 \WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version'));
             }
         }
         return;
     }
     $result = array();
     // Only attempt to update if there is something to update
     if (!empty($items_to_update)) {
         $cache_manager = \WP_CLI::get_http_cache_manager();
         foreach ($items_to_update as $item) {
             $cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']);
         }
         $upgrader = $this->get_upgrader($assoc_args);
         $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);
         }
     }
     if ($num_to_update > 0) {
         if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) {
             foreach ($items_to_update as $item_to_update => $info) {
                 $message = $result[$info['update_id']] !== null ? 'updated successfully' : 'did not update';
                 \WP_CLI::log("{$info['title']} {$message} from version {$info['version']} to version {$info['update_version']}");
             }
         } else {
             $status = array();
             foreach ($items_to_update as $item_to_update => $info) {
                 $status[$item_to_update] = array('name' => $info['name'], 'old_version' => $info['version'], 'new_version' => $info['update_version'], 'status' => $result[$info['update_id']] !== null ? 'Updated' : 'Error');
             }
             $format = 'table';
             if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
                 $format = $assoc_args['format'];
             }
             \WP_CLI\Utils\format_items($format, $status, array('name', 'old_version', 'new_version', 'status'));
         }
     }
 }
Ejemplo n.º 3
0
 protected function update_many($args, $assoc_args)
 {
     call_user_func($this->upgrade_refresh);
     $items = $this->get_item_list();
     if (!isset($assoc_args['all'])) {
         $items = $this->filter_item_list($items, $args);
     }
     $items_to_update = wp_list_filter($items, array('update' => true));
     if (isset($assoc_args['dry-run'])) {
         if (empty($items_to_update)) {
             \WP_CLI::line("No {$this->item_type} updates available.");
             return;
         }
         \WP_CLI::line("Available {$this->item_type} updates:");
         \WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version'));
         return;
     }
     $result = array();
     // Only attempt to update if there is something to update
     if (!empty($items_to_update)) {
         $cache_manager = \WP_CLI::get_http_cache_manager();
         foreach ($items_to_update as $item) {
             $cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']);
         }
         $upgrader = $this->get_upgrader($assoc_args);
         $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);
         }
     }
 }
Ejemplo n.º 4
0
 protected function install_from_repo($slug, $assoc_args)
 {
     $api = plugins_api('plugin_information', array('slug' => $slug));
     if (is_wp_error($api)) {
         return $api;
     }
     if (isset($assoc_args['version'])) {
         self::alter_api_response($api, $assoc_args['version']);
     }
     $status = install_plugin_install_status($api);
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && 'install' != $status['status']) {
         // We know this will fail, so avoid a needless download of the package.
         return new WP_Error('already_installed', 'Plugin already installed.');
     }
     WP_CLI::log(sprintf('Installing %s (%s)', html_entity_decode($api->name, ENT_QUOTES), $api->version));
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'version') != 'dev') {
         WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
     }
     $result = $this->get_upgrader($assoc_args)->install($api->download_link);
     return $result;
 }
Ejemplo n.º 5
0
 protected function install_from_repo($slug, $assoc_args)
 {
     $api = themes_api('theme_information', array('slug' => $slug));
     if (is_wp_error($api)) {
         return $api;
     }
     if (isset($assoc_args['version'])) {
         self::alter_api_response($api, $assoc_args['version']);
     }
     if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force')) {
         $theme = wp_get_theme($slug);
         if ($theme->exists()) {
             // We know this will fail, so avoid a needless download of the package.
             return new WP_Error('already_installed', 'Theme already installed.');
         }
         // Clear cache so WP_Theme doesn't create a "missing theme" object.
         $cache_hash = md5($theme->theme_root . '/' . $theme->stylesheet);
         foreach (array('theme', 'screenshot', 'headers', 'page_templates') as $key) {
             wp_cache_delete($key . '-' . $cache_hash, 'themes');
         }
     }
     WP_CLI::log(sprintf('Installing %s (%s)', html_entity_decode($api->name, ENT_QUOTES), $api->version));
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'version') != 'dev') {
         WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
     }
     $result = $this->get_upgrader($assoc_args)->install($api->download_link);
     return $result;
 }