Making WordPress.org

Changeset 11299


Ignore:
Timestamp:
10/27/2021 03:01:22 AM (5 years ago)
Author:
dd32
Message:

Theme Directory: When a SVN commit is blocked by the svn pre-commit hook, pass the quoted error back to the client.

This primarily will affect theme updates that are attempted to be uploaded that contain a PHP Fatal error that wasn't caught before this step.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r11281 r11299  
    659659        if ( $args['commit_to_svn'] ) {
    660660            $result = $this->add_to_svn();
    661             if ( ! $result ) {
     661            if ( ! $result || is_wp_error( $result ) ) {
    662662                return new WP_Error(
    663663                    'failed_svn_commit',
     
    666666                        __( 'There was an error adding your theme to SVN. Please try again, if this error persists report the error to %s.', 'wporg-themes' ),
    667667                        '<a href="mailto:themes@wordpress.org">themes@wordpress.org</a>'
     668                    ) .
     669                    (
     670                        is_wp_error( $result ) && $result->get_error_message( 'pre-commit-hook' ) ?
     671                            '<br><code>' . nl2br( esc_html( $result->get_error_message( 'pre-commit-hook' ) ) ) . '</code>' :
     672                            ''
    668673                    )
    669674                );
     
    13801385        $password   = escapeshellarg( THEME_DROPBOX_PASSWORD );
    13811386
    1382         $last_line = $this->exec_with_notify( self::SVN . " --non-interactive --username themedropbox --password {$password} --no-auto-props -m {$import_msg} import {$theme_path} {$svn_path}" );
     1387        $last_line = $this->exec_with_notify( self::SVN . " --non-interactive --username themedropbox --password {$password} --no-auto-props -m {$import_msg} import {$theme_path} {$svn_path}", $output, $return_var, $stderr );
     1388
     1389        // Pass through any error output from the SVN error handler.
     1390        if (
     1391            ! empty( $stderr ) &&
     1392            false !== stripos( $stderr[0], 'Commit blocked by pre-commit hook' ) &&
     1393            preg_match( '!([*]{12,})(.*?)\\1!s', implode( "\n", $stderr ) . "\n", $m )
     1394        ) {
     1395            return new WP_Error( 'pre-commit-hook', trim( $m[0] ) );
     1396        }
    13831397
    13841398        if ( preg_match( '/Committed revision (\d+)\./i', $last_line, $m ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/lib/class-exec-with-logging.php

    r11232 r11299  
    1212     * Execute a shell process, same behaviour as `exec()` but with PHP Warnings/Notices generated on errors.
    1313     *
    14      * @param string $command    Command to execute. Escape it.
    15      * @param array  $output     Array to append program output to. Passed by reference.
    16      * @param int    $return_var The commands return value. Passed by reference.
     14     * @param string $command      Command to execute. Escape it.
     15     * @param array  $output       Array to append program output to. Passed by reference.
     16     * @param int    $return_var   The commands return value. Passed by reference.
     17     * @param array  $error_output Array to append program output to. Passed by reference.
    1718     *
    1819     * @return false|string False on failure, last line of output on success, as per exec().
    1920     */
    20     public static function exec( $command, &$output = null, &$return_var = null ) {
     21    public static function exec( $command, &$output = null, &$return_var = null, &$error_output = null ) {
    2122        $proc = proc_open(
    2223            $command,
     
    3940        $return_var = proc_close( $proc );
    4041
     42        // Redact any passwords that might be in a command and included in logged errors.
     43        foreach ( [ 'command', 'stdout', 'stderr' ] as $field ) {
     44            $$field = str_replace( [ THEME_TRACBOT_PASSWORD, THEME_DROPBOX_PASSWORD ], '[redacted]', $$field );
     45        }
     46
    4147        // Append to $output, as `exec()` does.
    4248        if ( ! is_array( $output ) ) {
    4349            $output = [];
    4450        }
     51        if ( ! is_array( $error_output ) ) {
     52            $error_output = [];
     53        }
    4554        if ( $stdout ) {
    4655            $output = array_merge( $output, explode( "\n", rtrim( $stdout, "\r\n" ) ) );
    4756        }
    48 
    49         // Redact any passwords that might be in a command and included in logged errors.
    50         $command = str_replace( [ THEME_TRACBOT_PASSWORD, THEME_DROPBOX_PASSWORD ], '[redacted]', $command );
     57        if ( $stderr ) {
     58            $error_output = array_merge( $error_output, explode( "\n", rtrim( $stderr, "\r\n" ) ) );
     59        }
    5160
    5261        if ( $return_var > 0 ) {
Note: See TracChangeset for help on using the changeset viewer.