Conversation
Comment on lines
+48
to
+105
| public static function convert( $input_path, $output_path, $output_format = '', $input_format = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed | ||
| if ( ! file_exists( $input_path ) ) { | ||
| return new WP_Error( 'resolate_zetajs_input_missing', __( 'El fichero origen para la conversión no existe.', 'resolate' ) ); | ||
| } | ||
|
|
||
| if ( ! self::is_available() ) { | ||
| return new WP_Error( 'resolate_zetajs_not_available', __( 'Configura la ruta del ejecutable de ZetaJS en RESOLATE_ZETAJS_BIN.', 'resolate' ) ); | ||
| } | ||
|
|
||
| $cli = self::get_cli_path(); | ||
| $dir = dirname( $output_path ); | ||
| if ( ! is_dir( $dir ) ) { | ||
| wp_mkdir_p( $dir ); | ||
| } | ||
|
|
||
| if ( file_exists( $output_path ) ) { | ||
| @unlink( $output_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | ||
| } | ||
|
|
||
| $descriptor = array( | ||
| 0 => array( 'pipe', 'r' ), | ||
| 1 => array( 'pipe', 'w' ), | ||
| 2 => array( 'pipe', 'w' ), | ||
| ); | ||
|
|
||
| $command = array( $cli, 'convert', $input_path, $output_path ); | ||
|
|
||
| $process = proc_open( $command, $descriptor, $pipes, null, null, array( 'bypass_shell' => true ) ); | ||
| if ( ! is_resource( $process ) ) { | ||
| return new WP_Error( 'resolate_zetajs_proc', __( 'No se pudo iniciar el proceso de conversión con ZetaJS.', 'resolate' ) ); | ||
| } | ||
|
|
||
| // Close STDIN as we don't need to feed data. | ||
| fclose( $pipes[0] ); | ||
| $stdout = stream_get_contents( $pipes[1] ); | ||
| fclose( $pipes[1] ); | ||
| $stderr = stream_get_contents( $pipes[2] ); | ||
| fclose( $pipes[2] ); | ||
|
|
||
| $status = proc_close( $process ); | ||
| if ( 0 !== $status ) { | ||
| $message = trim( $stderr ); | ||
| if ( '' === $message ) { | ||
| $message = trim( $stdout ); | ||
| } | ||
| if ( '' === $message ) { | ||
| $message = sprintf( __( 'El proceso de ZetaJS finalizó con código %d.', 'resolate' ), $status ); | ||
| } | ||
| return new WP_Error( 'resolate_zetajs_failed', $message ); | ||
| } | ||
|
|
||
| if ( ! file_exists( $output_path ) ) { | ||
| $context = $stderr ? $stderr : $stdout; | ||
| return new WP_Error( 'resolate_zetajs_output_missing', sprintf( __( 'La conversión finalizó pero no se generó el archivo de salida. Detalles: %s', 'resolate' ), $context ) ); | ||
| } | ||
|
|
||
| return $output_path; | ||
| } |
Check warning
Code scanning / PHPMD
Code Size Rules: CyclomaticComplexity Warning
Comment on lines
+48
to
+105
| public static function convert( $input_path, $output_path, $output_format = '', $input_format = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed | ||
| if ( ! file_exists( $input_path ) ) { | ||
| return new WP_Error( 'resolate_zetajs_input_missing', __( 'El fichero origen para la conversión no existe.', 'resolate' ) ); | ||
| } | ||
|
|
||
| if ( ! self::is_available() ) { | ||
| return new WP_Error( 'resolate_zetajs_not_available', __( 'Configura la ruta del ejecutable de ZetaJS en RESOLATE_ZETAJS_BIN.', 'resolate' ) ); | ||
| } | ||
|
|
||
| $cli = self::get_cli_path(); | ||
| $dir = dirname( $output_path ); | ||
| if ( ! is_dir( $dir ) ) { | ||
| wp_mkdir_p( $dir ); | ||
| } | ||
|
|
||
| if ( file_exists( $output_path ) ) { | ||
| @unlink( $output_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | ||
| } | ||
|
|
||
| $descriptor = array( | ||
| 0 => array( 'pipe', 'r' ), | ||
| 1 => array( 'pipe', 'w' ), | ||
| 2 => array( 'pipe', 'w' ), | ||
| ); | ||
|
|
||
| $command = array( $cli, 'convert', $input_path, $output_path ); | ||
|
|
||
| $process = proc_open( $command, $descriptor, $pipes, null, null, array( 'bypass_shell' => true ) ); | ||
| if ( ! is_resource( $process ) ) { | ||
| return new WP_Error( 'resolate_zetajs_proc', __( 'No se pudo iniciar el proceso de conversión con ZetaJS.', 'resolate' ) ); | ||
| } | ||
|
|
||
| // Close STDIN as we don't need to feed data. | ||
| fclose( $pipes[0] ); | ||
| $stdout = stream_get_contents( $pipes[1] ); | ||
| fclose( $pipes[1] ); | ||
| $stderr = stream_get_contents( $pipes[2] ); | ||
| fclose( $pipes[2] ); | ||
|
|
||
| $status = proc_close( $process ); | ||
| if ( 0 !== $status ) { | ||
| $message = trim( $stderr ); | ||
| if ( '' === $message ) { | ||
| $message = trim( $stdout ); | ||
| } | ||
| if ( '' === $message ) { | ||
| $message = sprintf( __( 'El proceso de ZetaJS finalizó con código %d.', 'resolate' ), $status ); | ||
| } | ||
| return new WP_Error( 'resolate_zetajs_failed', $message ); | ||
| } | ||
|
|
||
| if ( ! file_exists( $output_path ) ) { | ||
| $context = $stderr ? $stderr : $stdout; | ||
| return new WP_Error( 'resolate_zetajs_output_missing', sprintf( __( 'La conversión finalizó pero no se generó el archivo de salida. Detalles: %s', 'resolate' ), $context ) ); | ||
| } | ||
|
|
||
| return $output_path; | ||
| } |
Check warning
Code scanning / PHPMD
Code Size Rules: NPathComplexity Warning
Comment on lines
+1059
to
+1106
| private function collect_unknown_dynamic_fields( $post_id, $known_meta_keys ) { | ||
| $known_lookup = array(); | ||
| if ( ! empty( $known_meta_keys ) ) { | ||
| foreach ( $known_meta_keys as $meta_key ) { | ||
| $known_lookup[ $meta_key ] = true; | ||
| } | ||
| } | ||
|
|
||
| $unknown = array(); | ||
| $prefix = 'resolate_field_'; | ||
|
|
||
| foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||
| if ( ! is_string( $key ) || 0 !== strpos( $key, $prefix ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $known_lookup[ $key ] ) ) { | ||
| continue; | ||
| } | ||
| if ( is_array( $value ) ) { | ||
| continue; | ||
| } | ||
| $unknown[ $key ] = array( | ||
| 'value' => wp_unslash( $value ), // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||
| 'source' => 'post', | ||
| ); | ||
| } | ||
|
|
||
| if ( $post_id > 0 ) { | ||
| $all_meta = get_post_meta( $post_id ); | ||
| foreach ( $all_meta as $meta_key => $values ) { | ||
| if ( 0 !== strpos( $meta_key, $prefix ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $known_lookup[ $meta_key ] ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $unknown[ $meta_key ] ) ) { | ||
| continue; | ||
| } | ||
| $unknown[ $meta_key ] = array( | ||
| 'value' => get_post_meta( $post_id, $meta_key, true ), | ||
| 'source' => 'meta', | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return $unknown; | ||
| } |
Check warning
Code scanning / PHPMD
Code Size Rules: CyclomaticComplexity Warning
Comment on lines
+1059
to
+1106
| private function collect_unknown_dynamic_fields( $post_id, $known_meta_keys ) { | ||
| $known_lookup = array(); | ||
| if ( ! empty( $known_meta_keys ) ) { | ||
| foreach ( $known_meta_keys as $meta_key ) { | ||
| $known_lookup[ $meta_key ] = true; | ||
| } | ||
| } | ||
|
|
||
| $unknown = array(); | ||
| $prefix = 'resolate_field_'; | ||
|
|
||
| foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||
| if ( ! is_string( $key ) || 0 !== strpos( $key, $prefix ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $known_lookup[ $key ] ) ) { | ||
| continue; | ||
| } | ||
| if ( is_array( $value ) ) { | ||
| continue; | ||
| } | ||
| $unknown[ $key ] = array( | ||
| 'value' => wp_unslash( $value ), // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||
| 'source' => 'post', | ||
| ); | ||
| } | ||
|
|
||
| if ( $post_id > 0 ) { | ||
| $all_meta = get_post_meta( $post_id ); | ||
| foreach ( $all_meta as $meta_key => $values ) { | ||
| if ( 0 !== strpos( $meta_key, $prefix ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $known_lookup[ $meta_key ] ) ) { | ||
| continue; | ||
| } | ||
| if ( isset( $unknown[ $meta_key ] ) ) { | ||
| continue; | ||
| } | ||
| $unknown[ $meta_key ] = array( | ||
| 'value' => get_post_meta( $post_id, $meta_key, true ), | ||
| 'source' => 'meta', | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return $unknown; | ||
| } |
Check warning
Code scanning / PHPMD
Code Size Rules: NPathComplexity Warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68ecb0d851dc8322903a323c158e053c