WordPress.org

Make WordPress Core

Changeset 48417


Ignore:
Timestamp:
07/10/2020 06:06:46 AM (3 months ago)
Author:
whyisjake
Message:

Upgrade/Install: Ensure cleanup after canceled update.

Ensure that the uploaded zip is hidden from the media library, where a task will remove failed installs after two hours.

Fixes #50612.

Props psykro, desrosj, joyously, azaozz, noisysocks, whyisjake.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r48267 r48417  
    16071607});
    16081608
     1609// On the "Update plugin/theme from uploaded zip" screen
     1610// hide the "Replace current with uploaded" button and show a warning in 1 hour and 59 minutes.
     1611$document.ready( function( $ ) {
     1612    var $overwrite, $warning;
     1613
     1614    if ( ! $body.hasClass( 'update-php' ) ) {
     1615        return;
     1616    }
     1617
     1618    $overwrite = $( 'a.update-from-upload-overwrite' );
     1619    $warning   = $( '.update-from-upload-expired' );
     1620
     1621    if ( ! $overwrite.length || ! $warning.length ) {
     1622        return;
     1623    }
     1624
     1625    window.setTimeout(
     1626        function() {
     1627            $overwrite.hide();
     1628            $warning.removeClass( 'hidden' );
     1629
     1630            if ( window.wp && window.wp.a11y ) {
     1631                window.wp.a11y.speak( $warning.text() );
     1632            }
     1633        },
     1634        7140000 // 119 minutes. The uploaded file is deleted after 2 hours.
     1635    );
     1636} );
     1637
    16091638// Fire a custom jQuery event at the end of window resize.
    16101639( function() {
  • trunk/src/wp-admin/includes/class-plugin-installer-skin.php

    r48390 r48417  
    293293
    294294            $install_actions['ovewrite_plugin'] = sprintf(
    295                 '<a class="button button-primary" href="%s" target="_parent">%s</a>',
     295                '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
    296296                wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ),
    297                 esc_html( __( 'Replace current with uploaded' ) )
     297                __( 'Replace current with uploaded' )
    298298            );
    299299        } else {
     
    301301        }
    302302
     303        $cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url );
     304
    303305        $install_actions['plugins_page'] = sprintf(
    304306            '<a class="button" href="%s">%s</a>',
    305             self_admin_url( 'plugin-install.php' ),
     307            wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ),
    306308            __( 'Cancel and go back' )
    307309        );
     
    319321
    320322        if ( ! empty( $install_actions ) ) {
     323            printf(
     324                '<p class="update-from-upload-expired hidden">%s</p>',
     325                __( 'The uploaded file has expired. Please go back and upload it again.' )
     326            );
    321327            echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
    322328        }
  • trunk/src/wp-admin/includes/class-theme-installer-skin.php

    r48390 r48417  
    322322
    323323            $install_actions['ovewrite_theme'] = sprintf(
    324                 '<a class="button button-primary" href="%s" target="_parent">%s</a>',
     324                '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
    325325                wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'theme-upload' ),
    326                 esc_html( __( 'Replace current with uploaded' ) )
     326                __( 'Replace current with uploaded' )
    327327            );
    328328        } else {
     
    330330        }
    331331
     332        $cancel_url = add_query_arg( 'action', 'upload-theme-cancel-overwrite', $this->url );
     333
    332334        $install_actions['themes_page'] = sprintf(
    333335            '<a class="button" href="%s" target="_parent">%s</a>',
    334             self_admin_url( 'theme-install.php' ),
     336            wp_nonce_url( $cancel_url, 'theme-upload-cancel-overwrite' ),
    335337            __( 'Cancel and go back' )
    336338        );
     
    348350
    349351        if ( ! empty( $install_actions ) ) {
     352            printf(
     353                '<p class="update-from-upload-expired hidden">%s</p>',
     354                __( 'The uploaded file has expired. Please go back and upload it again.' )
     355            );
    350356            echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
    351357        }
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r48352 r48417  
    6969    public function prepare_items() {
    7070        global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
     71
     72        // Exclude attachments scheduled for deletion in the next two hours
     73        // if they are for zip packages for interrupted or failed updates.
     74        // See File_Upload_Upgrader class.
     75        $not_in = array();
     76
     77        foreach ( _get_cron_array() as $cron ) {
     78            if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) {
     79                $details = reset( $cron['upgrader_scheduled_cleanup'] );
     80
     81                if ( ! empty( $details['args'][0] ) ) {
     82                    $not_in[] = (int) $details['args'][0];
     83                }
     84            }
     85        }
     86
     87        if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) {
     88            $not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in );
     89        }
     90
     91        if ( ! empty( $not_in ) ) {
     92            $_REQUEST['post__not_in'] = $not_in;
     93        }
    7194
    7295        list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
  • trunk/src/wp-admin/update.php

    r48390 r48417  
    1717
    1818require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     19
     20wp_enqueue_script( 'wp-a11y' );
    1921
    2022if ( isset( $_GET['action'] ) ) {
     
    175177        require_once ABSPATH . 'wp-admin/admin-footer.php';
    176178
     179    } elseif ( 'upload-plugin-cancel-overwrite' === $action ) {
     180        if ( ! current_user_can( 'upload_plugins' ) ) {
     181            wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
     182        }
     183
     184        check_admin_referer( 'plugin-upload-cancel-overwrite' );
     185
     186        // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die()
     187        // that shows a generic "Please select a file" error.
     188        if ( ! empty( $_GET['package'] ) ) {
     189            $attachment_id = (int) $_GET['package'];
     190
     191            if ( get_post( $attachment_id ) ) {
     192                $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
     193                $file_upload->cleanup();
     194            }
     195        }
     196
     197        wp_redirect( self_admin_url( 'plugin-install.php' ) );
     198        exit;
    177199    } elseif ( 'upgrade-theme' === $action ) {
    178200
     
    298320        require_once ABSPATH . 'wp-admin/admin-footer.php';
    299321
     322    } elseif ( 'upload-theme-cancel-overwrite' === $action ) {
     323        if ( ! current_user_can( 'upload_themes' ) ) {
     324            wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
     325        }
     326
     327        check_admin_referer( 'theme-upload-cancel-overwrite' );
     328
     329        // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die()
     330        // that shows a generic "Please select a file" error.
     331        if ( ! empty( $_GET['package'] ) ) {
     332            $attachment_id = (int) $_GET['package'];
     333
     334            if ( get_post( $attachment_id ) ) {
     335                $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
     336                $file_upload->cleanup();
     337            }
     338        }
     339
     340        wp_redirect( self_admin_url( 'theme-install.php' ) );
     341        exit;
    300342    } else {
    301343        /**
Note: See TracChangeset for help on using the changeset viewer.