Permalink
Browse files

ConvertAttachment -> import_attachment

Same as the rest, just different.
  • Loading branch information...
1 parent 6f4fc24 commit 502b717fa9c35d1fb782bb2c05821f5d77dfffd1 @afresh1 committed Aug 11, 2012
Showing with 36 additions and 32 deletions.
  1. +36 −32 rt-ticket-importer
View
@@ -311,50 +311,54 @@ sub import_transaction {
return $newid;
}
-sub ConvertAttachment {
- my $id = shift;
-
- return $ATTACHMENTS{$id} if ( $ATTACHMENTS{$id} );
- my $attachment = $attachments->{$id};
+sub import_attachment {
+ my ($attachment) = @_;
+ my %a;
foreach my $key ( keys %$attachment ) {
- $attachment->{$key} = undef if ( ref( $attachment->{$key} ) );
- }
+ my $value = $attachment->{$key};
+ next unless $value;
+
+ if ( ref $value ) {
+ next;
+ }
+ elsif ( $user_types{$key} ) {
+ $value = [ grep {$_} map { ConvertUser($_) } split /\s*,\s*/,
+ $value ];
+ next unless @{$value};
+ $value = $value->[0] if @{$value} == 1;
+ }
- if ( $attachment->{'Parent'} ) {
- my $parent = $attachment->{'Parent'};
- $attachment->{'Parent'} = ConvertAttachment($parent);
+ $a{$key} = $value;
}
- my $attachObj = new RT::Attachment($RT::SystemUser);
+ delete $a{Owner};
- $attachment->{'Creator'} = ConvertUser( $attachment->{'Creator'} );
+ if ( $a{Parent} ) {
- $attachment->{'TransactionId'}
- = ConvertTransaction( $attachment->{'TransactionId'} );
- return undef unless ( defined( $attachment->{'TransactionId'} ) );
+ # I guess we just have to hope this exists
+ my $parent = $a{Parent};
+ $a{Parent} = $E{Attachments}{$parent};
+ }
- Encode::_utf8_off( $attachment->{'Content'} );
- $attachment->{'Content'} = decode_base64( $attachment->{'Content'} );
+ if ( $a{Content} ) {
+ Encode::_utf8_off( $a{Content} );
+ $a{Content} = decode_base64( $a{Content} );
+ }
+ else { $a{Content} = '' }
- my ( $newid, $msg ) = $attachObj->Import(%$attachment);
+ my $attachObj = new RT::Attachment($RT::SystemUser);
+ my ( $newid, $msg ) = $attachObj->Import(%a);
+ print $msg and return unless $newid;
- unless ($newid) {
- print STDERR "Failed to create Attachment $id ($msg)!!!\n";
- return undef;
- }
+ $attachObj->{_AccessibleCache}{Created}
+ = { read => 1, write => 1, auto => 0 };
+ $attachObj->{_AccessibleCache}{Creator}
+ = { read => 1, write => 1, auto => 0 };
+ $attachObj->SetCreated( $a{Created} );
+ $attachObj->SetCreator( $a{Creator} );
- print "Created Attachment # $id : as # $newid\n";
- $| = 1;
- $attachObj->{'_AccessibleCache'}{Created}
- = { 'read' => 1, 'write' => 1, 'auto' => 0 };
- $attachObj->{'_AccessibleCache'}{Creator}
- = { 'read' => 1, 'write' => 1, 'auto' => 0 };
- $attachObj->SetCreated( $attachment->{'Created'} );
- $attachObj->SetCreator( $attachment->{'Creator'} );
- $ATTACHMENTS{$id} = $newid;
return $newid;
-
}
sub ConvertLink {

0 comments on commit 502b717

Please sign in to comment.