Ticket #22435: export.2.diff
File export.2.diff, 4.7 KB (added by , 11 years ago) |
---|
-
wp-includes/export/class-wp-export-query.php
27 27 private $author; 28 28 private $category; 29 29 30 public $missing_parents = false; 31 30 32 public function __construct( $filters = array() ) { 31 33 $this->filters = wp_parse_args( $filters, self::$defaults ); 32 34 $this->post_ids = $this->calculate_post_ids(); … … 76 78 return array(); 77 79 } 78 80 $categories = (array) get_categories( array( 'get' => 'all' ) ); 81 82 $this->check_for_orphaned_terms( $categories ); 83 79 84 $categories = self::topologically_sort_terms( $categories ); 85 80 86 return $categories; 81 87 } 82 88 … … 85 91 return array(); 86 92 } 87 93 $tags = (array) get_tags( array( 'get' => 'all' ) ); 94 95 $this->check_for_orphaned_terms( $tags ); 96 88 97 return $tags; 89 98 } 90 99 … … 94 103 } 95 104 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 96 105 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 106 $this->check_for_orphaned_terms( $custom_terms ); 97 107 $custom_terms = self::topologically_sort_terms( $custom_terms ); 98 108 return $custom_terms; 99 109 } … … 271 281 return $sorted; 272 282 } 273 283 284 private function check_for_orphaned_terms( $terms ) { 285 $term_ids = array(); 286 $have_parent = array(); 287 288 foreach ( $terms as $term ) { 289 $term_ids[ $term->term_id ] = true; 290 if ( $term->parent != 0 ) 291 $have_parent[] = $term; 292 } 293 294 foreach ( $have_parent as $has_parent ) { 295 if ( ! isset( $term_ids[ $has_parent->parent ] ) ) { 296 $this->missing_parents = $has_parent; 297 throw new WP_Export_Term_Exception( __( 'Term is missing a parent.' ) ); 298 } 299 } 300 } 301 274 302 private static function get_terms_for_post( $post ) { 275 303 $taxonomies = get_object_taxonomies( $post->post_type ); 276 304 if ( empty( $taxonomies ) ) … … 309 337 310 338 class WP_Export_Exception extends RuntimeException { 311 339 } 340 341 class WP_Export_Term_Exception extends RuntimeException { 342 } -
wp-includes/export/functions.export.php
27 27 } 28 28 } 29 29 return $args; 30 } 30 } 31 No newline at end of file -
wp-includes/export/writers.php
26 26 } 27 27 28 28 public function export() { 29 try { 30 $export = $this->get_export(); 31 $this->send_headers(); 32 echo $export; 33 } catch ( WP_Export_Exception $e ) { 34 $message = apply_filters( 'export_error_message', $e->getMessage() ); 35 wp_die( $message, __( 'Export Error' ), array( 'back_link' => true ) ); 36 } catch ( WP_Export_Term_Exception $e ) { 37 do_action( 'export_term_orphaned', $this->formatter->export->missing_parents ); 38 $message = apply_filters( 'export_term_error_message', $e->getMessage() ); 39 wp_die( $message, __( 'Export Error' ), array( 'back_link' => true ) ); 40 } 41 } 42 43 protected function write( $xml ) { 44 $this->result .= $xml; 45 } 46 47 protected function get_export() { 48 $this->result = ''; 49 parent::export(); 50 return $this->result; 51 } 52 53 protected function send_headers() { 29 54 header( 'Content-Description: File Transfer' ); 30 55 header( 'Content-Disposition: attachment; filename=' . $this->file_name ); 31 56 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); 32 parent::export();33 57 } 34 35 protected function write( $xml ) {36 echo $xml;37 }38 58 } 39 59 40 60 class WP_Export_Returner extends WP_Export_Base_Writer { … … 42 62 43 63 public function export() { 44 64 $this->private = ''; 45 parent::export(); 65 try { 66 parent::export(); 67 } catch ( WP_Export_Exception $e ) { 68 $message = apply_filters( 'export_error_message', $e->getMessage() ); 69 return new WP_Error( 'wp-export-error', $message ); 70 71 } catch ( WP_Export_Term_Exception $e ) { 72 do_action( 'export_term_orphaned', $this->formatter->export->missing_parents ); 73 $message = apply_filters( 'export_term_error_message', $e->getMessage() ); 74 return new WP_Error( 'wp-export-error', $message ); 75 } 46 76 return $this->result; 47 77 } 48 78 protected function write( $xml ) { … … 64 94 if ( !$this->f ) { 65 95 throw new WP_Export_Exception( sprintf( __( 'WP Export: error opening %s for writing.' ), $this->file_name ) ); 66 96 } 67 parent::export(); 97 98 try { 99 parent::export(); 100 } catch ( WP_Export_Exception $e ) { 101 throw $e; 102 } catch ( WP_Export_Term_Exception $e ) { 103 throw $e; 104 } 105 68 106 fclose( $this->f ); 69 107 } 70 108