WordPress.org

Make WordPress Core

Ticket #10911: upload.php.patch

File upload.php.patch, 1.0 KB (added by johnjosephbachir, 9 years ago)

Somewhat more simple and possibly more optimal SQL.

  • wp-admin/upload.php

     
    2020        if ( !current_user_can('edit_posts') )
    2121                wp_die( __('You are not allowed to scan for lost attachments.') );
    2222
    23         $all_posts = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'post' OR post_type = 'page'");
    24         $all_att = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'attachment'");
     23        $all_posts = implode(',', $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type IN ('post', 'page')"));
     24        $lost = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent > '0' and post_parent NOT IN ($all_posts)");
    2525
    26         $lost = array();
    27         foreach ( (array) $all_att as $att ) {
    28                 if ( $att->post_parent > 0 && ! in_array($att->post_parent, $all_posts) )
    29                         $lost[] = $att->ID;
    30         }
    3126        $_GET['detached'] = 1;
    3227
    3328} elseif ( isset($_GET['found_post_id']) && isset($_GET['media']) ) {