Ticket #19225: better-attachment-url-backfilling.2.diff
| File better-attachment-url-backfilling.2.diff, 1.6 KB (added by tott, 20 months ago) |
|---|
-
wordpress-importer.php
952 952 global $wpdb; 953 953 // make sure we do the longest urls first, in case one is a substring of another 954 954 uksort( $this->url_remap, array(&$this, 'cmpr_strlen') ); 955 955 $replacements = $post_contents = array(); 956 956 foreach ( $this->url_remap as $from_url => $to_url ) { 957 // remap urls in post_content958 $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) );959 // remap enclosure urls960 957 $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); 958 959 $posts = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE %s", '%' . like_escape( $from_url ) . '%' ) ); 960 if ( count( $post_ids ) > 0 ) { 961 foreach ( $posts as $post ) { 962 $replacements[$post->ID][$from_url] = $to_url; 963 $post_contents[$post->ID] = $post->post_content; 964 } 965 } 966 unset( $posts ); 967 } 968 foreach( $replacements as $post_id => $post_replacements ) { 969 uksort( $post_replacements, array(&$this, 'cmpr_strlen') ); 970 $new_post_content = str_replace( array_keys( $post_replacements ), array_values( $post_replacements ), $post_contents[$post_id] ); 971 if ( $new_post_content <> $post_contents[$post_id] ) 972 $wpdb->update( $wpdb->posts, array( 'post_content' => $new_post_content ), array( 'ID' => $post_id ) ); 961 973 } 962 974 } 963 975