Changeset 2716
- Timestamp:
- 07/04/08 09:52:12 (20 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/release-41/plugins/WXRImporter/lib/WXRImporter/WXRHandler.pm
r2515 r2716 69 69 $self->{in_wp_comment_content} = 1 if ('wp' eq $prefix) && ('comment_content' eq $name); 70 70 71 push @{$self->{'bucket'}}, \%values if scalar(%values); 72 push @{$self->{'bucket'}}, $prefix . '_' . $name; 71 if ( scalar(%values) ) { 72 push @{ $self->{'bucket'} }, 73 { $prefix . '_' . $name => undef, _a => \%values }; 74 } 75 else { 76 push @{ $self->{'bucket'} }, $prefix . '_' . $name; 77 } 73 78 1; 74 79 } … … 86 91 my $chars = MT::I18N::utf8_off($data->{Data}); 87 92 if ('HASH' eq ref($element)) { 88 my @hash_array = %$element;93 my @hash_array = grep { $_ ne '_a' } keys %$element; 89 94 return unless $hash_array[0]; 90 95 my $val = $element->{$hash_array[0]}; … … 119 124 } 120 125 push @{$self->{'bucket'}}, $element; 121 122 126 my $name_element = $prefix . '_' . $name; 123 127 if ('_item' eq $name_element) { … … 127 131 } elsif ('wp_category' eq $name_element) { 128 132 $self->_create_category($data); 133 } elsif ('wp_tag' eq $name_element) { 134 $self->_create_tag($data); 129 135 } elsif ('wp_comment' eq $name_element) { 130 136 $self->_create_feedback($data); … … 253 259 return die MT->translate( 254 260 "Saving category failed: [_1]", $cat->errstr); 261 } 262 } 263 } 264 265 sub _create_tag { 266 my $self = shift; 267 my $data = shift; 268 269 my $cb = $self->{callback}; 270 my $blog = $self->{blog}; 271 272 require MT::Tag; 273 my $tag = MT::Tag->new; 274 my $set_name; 275 while ( my $hash = pop @{ $self->{'bucket'} } ) { 276 last if 'wp_tag' eq $hash; 277 next if 'HASH' ne ref $hash; 278 my @hash_array = %$hash; 279 my $key = $hash_array[0]; 280 my $value = $hash_array[1]; 281 if ( 'wp_tag_name' eq $key ) { 282 return if ( MT::Tag->load( { name => $value } ) ); 283 $tag->name($value); 284 $set_name = 1; 285 } 286 } 287 if ($set_name) { 288 $cb->( MT->translate( "Creating new tag ('[_1]')...", $tag->name ) ); 289 if ( $tag->save ) { 290 $cb->( MT->translate("ok") . "\n" ); 291 } 292 else { 293 $cb->( MT->translate("failed") . "\n" ); 294 return die MT->translate( "Saving tag failed: [_1]", $tag->errstr ); 255 295 } 256 296 } … … 451 491 }; 452 492 my %meta_hash; 493 my @tags; 453 494 454 495 my $class = MT->model($class_type); … … 462 503 $post->status($blog->status_default); 463 504 for my $hash (@$hashes) { 464 my @hash_array = %$hash;505 my @hash_array = grep { $_ ne '_a' } keys %$hash; 465 506 my $key = $hash_array[0]; 466 my $value = $hash _array[1];507 my $value = $hash->{ $hash_array[0] }; 467 508 if ('_title' eq $key) { 468 509 $post->title($value); … … 482 523 $cat_ids{$cat->id} = 1; 483 524 $primary_cat_id = $cat->id unless $primary_cat_id; 525 } 526 if ( $hash->{_a} ) { 527 if ( $hash->{_a}->{domain} eq 'tag' ) { 528 push @tags, $value; 529 } 484 530 } 485 531 } elsif ('_guid' eq $key) { … … 589 635 } 590 636 637 # Associate tags to the entry. 638 if (@tags) { 639 $post->set_tags(@tags); 640 } 641 591 642 # Now save the entry/page. 592 643 if ('entry' eq $class_type) {
