Make WordPress Core

Ticket #12871: 12871.importer.diff

File 12871.importer.diff, 4.0 KB (added by duck_, 14 years ago)
  • trunk/parsers.php

     
    173173                        foreach ( $wp->postmeta as $meta ) {
    174174                                $post['postmeta'][] = array(
    175175                                        'key' => (string) $meta->meta_key,
    176                                         'value' => (string) $meta->meta_value,
     176                                        'value' => (string) $meta->meta_value
    177177                                );
    178178                        }
    179179
    180180                        foreach ( $wp->comment as $comment ) {
     181                                $meta = array();
     182                                if ( isset( $comment->commentmeta ) ) {
     183                                        foreach ( $comment->commentmeta as $m ) {
     184                                                $meta[] = array(
     185                                                        'key' => (string) $m->meta_key,
     186                                                        'value' => (string) $m->meta_value
     187                                                );
     188                                        }
     189                                }
     190                       
    181191                                $post['comments'][] = array(
    182192                                        'comment_id' => (int) $comment->comment_id,
    183193                                        'comment_author' => (string) $comment->comment_author,
     
    191201                                        'comment_type' => (string) $comment->comment_type,
    192202                                        'comment_parent' => (string) $comment->comment_parent,
    193203                                        'comment_user_id' => (int) $comment->comment_user_id,
     204                                        'commentmeta' => $meta,
    194205                                );
    195206                        }
    196207
     
    302313        function tag_close( $parser, $tag ) {
    303314                switch ( $tag ) {
    304315                        case 'wp:comment':
     316                                unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
    305317                                if ( ! empty( $this->sub_data ) )
    306318                                        $this->data['comments'][] = $this->sub_data;
    307319                                $this->sub_data = false;
    308320                                break;
     321                        case 'wp:commentmeta':
     322                                $this->sub_data['commentmeta'][] = array(
     323                                        'key' => $this->sub_data['key'],
     324                                        'value' => $this->sub_data['value']
     325                                );
     326                                break;
    309327                        case 'category':
    310328                                if ( ! empty( $this->sub_data ) ) {
    311329                                        $this->sub_data['name'] = $this->cdata;
     
    546564                $comments = $comments[1];
    547565                if ( $comments ) {
    548566                        foreach ( $comments as $comment ) {
     567                                preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
     568                                $commentmeta = $commentmeta[1];
     569                                $c_meta = array();
     570                                foreach ( $commentmeta as $m ) {
     571                                        $c_meta[] = array(
     572                                                'key' => $this->get_tag( $m, 'wp:meta_key' ),
     573                                                'value' => $this->get_tag( $m, 'wp:meta_value' ),
     574                                        );
     575                                }
     576
    549577                                $post_comments[] = array(
    550578                                        'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
    551579                                        'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
     
    559587                                        'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
    560588                                        'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
    561589                                        'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
     590                                        'commentmeta' => $c_meta,
    562591                                );
    563592                        }
    564593                }
  • trunk/wordpress-importer.php

     
    523523                                continue;
    524524                        }
    525525
    526                         if ( isset( $this->processed_posts[$post['post_id']] ) )
     526                        if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) )
    527527                                continue;
    528528
    529529                        if ( $post['status'] == 'auto-draft' )
     
    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]['commentmeta']          = $comment['commentmeta'];
    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                                                foreach( $comment['commentmeta'] as $meta ) {
     672                                                        $value = maybe_unserialize( $meta['value'] );
     673                                                        add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
     674                                                }
     675
    669676                                                $num_comments++;
    670677                                        }
    671678                                }