Make WordPress Core

Ticket #12871: importer-0.4.diff

File importer-0.4.diff, 5.2 KB (added by oreio, 12 years ago)

Patch updated to apply in plugin version 0.4

  • parsers.php

    diff -ur wordpress-importer-0.4/parsers.php wordpress-importer/parsers.php
    old new  
    178178                        }
    179179
    180180                        foreach ( $wp->comment as $comment ) {
     181                                if(isset($comment->comment_meta)) {
     182                                        $comment_meta = array();
     183                                        foreach ( $comment->comment_meta as $cmeta ) {
     184                                                $comment_meta[] = array(
     185                                                        'key' => (string) $cmeta->c_meta_key,
     186                                                        'value' => (string) $cmeta->c_meta_value,
     187                                                );
     188                                        }
     189                                }
    181190                                $post['comments'][] = array(
    182191                                        'comment_id' => (int) $comment->comment_id,
    183192                                        'comment_author' => (string) $comment->comment_author,
     
    191200                                        'comment_type' => (string) $comment->comment_type,
    192201                                        'comment_parent' => (string) $comment->comment_parent,
    193202                                        'comment_user_id' => (int) $comment->comment_user_id,
     203                                        'comment_meta' => $comment_meta,
    194204                                );
    195205                        }
    196206
     
    219229                'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
    220230                'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
    221231                'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
    222                 'wp:author_first_name', 'wp:author_last_name',
     232                'wp:author_first_name', 'wp:author_last_name', 'wp:comment_meta',
    223233        );
    224234        var $wp_sub_tags = array(
    225235                'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
     
    229239
    230240        function parse( $file ) {
    231241                $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
    232                 $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
     242                $this->authors = $this->posts = $this->term = $this->category = $this->tag = $this->c_meta = array();
    233243
    234244                $xml = xml_parser_create( 'UTF-8' );
    235245                xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
     
    318328                                        $this->data['postmeta'][] = $this->sub_data;
    319329                                $this->sub_data = false;
    320330                                break;
     331                        case 'wp:comment_meta':
     332                                if ( ! empty( $this->sub_data ) &&  ! empty( $this->c_meta ) )
     333                                        $this->sub_data['comment_meta'][] = $this->c_meta;
     334                                $this->c_meta = false;
     335                                break;
     336                        case 'wp:c_meta_key':
     337                                $this->c_meta['key'] = !empty($this->cdata) ? $this->cdata : false;
     338                                break;
     339                        case 'wp:c_meta_value':
     340                                $this->c_meta['value'] = !empty($this->cdata) ? $this->cdata : false;
     341                                break;
    321342                        case 'item':
    322343                                $this->posts[] = $this->data;
    323344                                $this->data = false;
     
    546567                $comments = $comments[1];
    547568                if ( $comments ) {
    548569                        foreach ( $comments as $comment ) {
     570                                preg_match_all( '|<wp:comment_meta>(.+?)</wp:comment_meta>|is', $comment, $commentmeta );
     571                                $commentmeta = $commentmeta[1];
     572                                if ( $commentmeta ) {
     573                                        foreach ( $commentmeta as $c ) {
     574                                                $comment_meta[] = array(
     575                                                        'key' => $this->get_tag( $c, 'wp:c_meta_key' ),
     576                                                        'value' => $this->get_tag( $c, 'wp:c_meta_value' ),
     577                                                );
     578                                        }
     579                                }
    549580                                $post_comments[] = array(
    550581                                        'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
    551582                                        'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
     
    559590                                        'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
    560591                                        'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
    561592                                        'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
     593                                        'comment_meta' => $comment_meta,
    562594                                );
    563595                        }
    564596                }
  • wordpress-importer.php

    diff -ur wordpress-importer-0.4/wordpress-importer.php wordpress-importer/wordpress-importer.php
    old new  
    654654                                        $newcomments[$comment_id]['comment_approved']     = $comment['comment_approved'];
    655655                                        $newcomments[$comment_id]['comment_type']         = $comment['comment_type'];
    656656                                        $newcomments[$comment_id]['comment_parent']       = $comment['comment_parent'];
     657                                        $newcomments[$comment_id]['comment_meta']         = $comment['comment_meta'];
    657658                                        if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
    658659                                                $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
    659660                                }
     
    666667                                                        $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
    667668                                                $comment = wp_filter_comment( $comment );
    668669                                                $inserted_comments[$key] = wp_insert_comment( $comment );
     670                                               
     671                                                // add/update comment meta
     672                                                if ( isset( $comment['comment_meta'] ) ) {
     673                                                        foreach ( $comment['comment_meta'] as $cmeta ) {
     674                                                                $meta_key = apply_filters( 'import_comment_meta_key', $cmeta['key'] );
     675                                                                if ( $meta_key ) {
     676                                                                        // export gets meta straight from the DB so could have a serialized string
     677                                                                        $value = maybe_unserialize( $cmeta['value'] );
     678                                                                        update_comment_meta($inserted_comments[$key], $meta_key, $value );
     679                                                                        do_action( 'import_comment_meta', $inserted_comments[$key], $meta_key, $value );
     680                                                                }
     681                                                        }
     682                                                }
     683                                               
    669684                                                $num_comments++;
    670685                                        }
    671686                                }