set_logger() public static method

Set the logger instance.
public static set_logger ( object $logger )
$logger object
Esempio n. 1
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'));
         }
     }
 }