Skip to content

Commit

Permalink
Improve hpos cli verbose output (#38699)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryhughes committed Jun 23, 2023
2 parents 41d24a7 + f879ebb commit 7ed5f59
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/improve-hpos-cli-verbose-output
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Use wp_json_encode instead of print_r in output for HPOS-related WP CLI commands.
Expand Up @@ -407,8 +407,7 @@ public function verify_cot_data( $args = array(), $assoc_args = array() ) {
$total_time += $batch_total_time;

if ( $verbose && count( $failed_ids_in_current_batch ) > 0 ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- This is a CLI command and debugging code is intended.
$errors = print_r( $failed_ids_in_current_batch, true );
$errors = wp_json_encode( $failed_ids_in_current_batch, JSON_PRETTY_PRINT );
WP_CLI::warning(
sprintf(
/* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
Expand All @@ -433,8 +432,7 @@ public function verify_cot_data( $args = array(), $assoc_args = array() ) {
$errors_in_remigrate_batch = $this->post_to_cot_migrator->verify_migrated_orders( $failed_ids );
$errors_in_remigrate_batch = $this->verify_meta_data( $failed_ids, $errors_in_remigrate_batch );
if ( count( $errors_in_remigrate_batch ) > 0 ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- This is a CLI command and debugging code is intended.
$formatted_errors = print_r( $errors_in_remigrate_batch, true );
$formatted_errors = wp_json_encode( $errors_in_remigrate_batch, JSON_PRETTY_PRINT );
WP_CLI::warning(
sprintf(
/* Translators: %1$d is number of errors and %2$s is the formatted array of order IDs. */
Expand Down Expand Up @@ -496,8 +494,7 @@ public function verify_cot_data( $args = array(), $assoc_args = array() ) {
)
);
} else {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- This is a CLI command and debugging code is intended.
$errors = print_r( $failed_ids, true );
$errors = wp_json_encode( $failed_ids, JSON_PRETTY_PRINT );

return WP_CLI::error(
sprintf(
Expand Down
Expand Up @@ -368,13 +368,12 @@ protected function log_error( \Exception $error, BatchProcessorInterface $batch_
$batch_detail_string = '';
// Log only first and last, as the entire batch may be too big.
if ( count( $batch ) > 0 ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- Logging is for debugging.
$batch_detail_string = '\n' . print_r(
$batch_detail_string = "\n" . wp_json_encode(
array(
'batch_start' => $batch[0],
'batch_end' => end( $batch ),
),
true
JSON_PRETTY_PRINT
);
}
$error_message = "Error processing batch for {$batch_processor->get_name()}: {$error->getMessage()}" . $batch_detail_string;
Expand Down
Expand Up @@ -1308,8 +1308,7 @@ private function get_diff_meta_data_between_orders( \WC_Abstract_Order &$order1,
* @return void
*/
private function log_diff( array $diff ): void {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- This is a log function.
$this->error_logger->notice( 'Diff found: ' . print_r( $diff, true ) );
$this->error_logger->notice( 'Diff found: ' . wp_json_encode( $diff, JSON_PRETTY_PRINT ) );
}

/**
Expand Down

0 comments on commit 7ed5f59

Please sign in to comment.