From c7a1dee767fafb37ef2532bbad6c5c5f7f1b4ff4 Mon Sep 17 00:00:00 2001 From: ashfame Date: Thu, 7 May 2026 17:07:45 +0000 Subject: [PATCH] Close import content output stream --- .../Steps/class-importcontentstep.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/components/Blueprints/Steps/class-importcontentstep.php b/components/Blueprints/Steps/class-importcontentstep.php index b09088560..5703fe15d 100644 --- a/components/Blueprints/Steps/class-importcontentstep.php +++ b/components/Blueprints/Steps/class-importcontentstep.php @@ -86,27 +86,31 @@ private function importWxr( Runtime $runtime, array $content_definition, Tracker $import_process->start(); $output = $import_process->getOutputStream( Process::OUTPUT_FILE ); - foreach ( $this->output_lines( $output ) as $line ) { - $data = @json_decode( $line, true ); - if ( ! is_array( $data ) ) { - // Non-JSON output is treated as a crash. We use a dedicated file pipe - // for communication and it should never contain a non-JSON line. - $import_process->stop(); - throw new ProcessFailedException( $import_process ); - } - // Report progress, errors, etc. - switch ( $data['type'] ?? '**MISSING**' ) { - case 'progress': - $progress->set( $data['progress'], 'Importing WXR file: ' . $data['caption'] ); - break; - case 'error': - throw new BlueprintExecutionException( $data['message'] ); - case 'completion': - $progress->finish(); - break; - default: - throw new BlueprintExecutionException( 'Unknown message type: ' . $data['type'] ); + try { + foreach ( $this->output_lines( $output ) as $line ) { + $data = @json_decode( $line, true ); + if ( ! is_array( $data ) ) { + // Non-JSON output is treated as a crash. We use a dedicated file pipe + // for communication and it should never contain a non-JSON line. + $import_process->stop(); + throw new ProcessFailedException( $import_process ); + } + // Report progress, errors, etc. + switch ( $data['type'] ?? '**MISSING**' ) { + case 'progress': + $progress->set( $data['progress'], 'Importing WXR file: ' . $data['caption'] ); + break; + case 'error': + throw new BlueprintExecutionException( $data['message'] ); + case 'completion': + $progress->finish(); + break; + default: + throw new BlueprintExecutionException( 'Unknown message type: ' . $data['type'] ); + } } + } finally { + $output->close_reading(); } if ( 0 !== $import_process->getExitCode() ) {