Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ConvertTicket -> import_ticket

Just handle the "special" stuff here.
  • Loading branch information...
commit 20477e91c9c3407f44b50dbdc0d02784f89b4577 1 parent f5203a3
Andrew Fresh authored

Showing 1 changed file with 60 additions and 15 deletions. Show diff stats Hide diff stats

  1. +60 15 rt-ticket-importer
75 rt-ticket-importer
@@ -167,27 +167,72 @@ sub ConvertTransaction { _ConvertItem( 'Transactions', @_ ) }
167 167 sub ConvertAttachment { _ConvertItem( 'Attachments', @_ ) }
168 168 sub ConvertLink { _ConvertItem( 'Links', @_ ) }
169 169
  170 +sub import_ticket {
  171 + my ($ticket) = @_;
170 172
171   - $ticketObj->SetEffectiveId( ConvertTicket($eid) ) if ( $eid != $id );
172   - $ticketObj->{'_AccessibleCache'}{Created}
173   - = { 'read' => 1, 'write' => 1, 'auto' => 0 };
174   - $ticketObj->{'_AccessibleCache'}{Creator}
175   - = { 'read' => 1, 'write' => 1, 'auto' => 0 };
176   - $ticketObj->{'_AccessibleCache'}{LastUpdated}
177   - = { 'read' => 1, 'write' => 1, 'auto' => 0 };
178   - $ticketObj->{'_AccessibleCache'}{LastUpdatedBy}
179   - = { 'read' => 1, 'write' => 1, 'auto' => 0 };
180   - $ticketObj->SetCreated( $ticket->{'Created'} );
181   - $ticketObj->SetCreator( $ticket->{'Creator'} );
182   - $ticketObj->SetLastUpdated( $ticket->{'LastUpdated'} );
183   - $ticketObj->SetLastUpdatedBy( $ticket->{'LastUpdatedBy'} );
  173 + my %t;
  174 + foreach my $key ( keys %{$ticket} ) {
  175 + my $value = $ticket->{$key};
  176 + next unless $value;
  177 +
  178 + if ( $link_types{$key} ) {
  179 +
  180 + # have to process these after all the tickets are created
  181 + queue_links($value);
  182 + next;
  183 + }
  184 + elsif ( ref $value ) {
  185 + next;
  186 + }
  187 + elsif ( $key eq 'Queue' ) {
  188 + $value = ConvertQueue($value);
  189 + }
  190 + elsif ( $user_types{$key} ) {
  191 + $value = [ grep {$_} map { ConvertUser($_) } split /\s*,\s*/,
  192 + $value ];
  193 + next unless @{$value};
  194 + $value = $value->[0] if @{$value} == 1;
  195 + }
  196 +
  197 + $t{$key} = $value;
  198 + }
  199 +
  200 + my $eid = $t{EffectiveId};
  201 + $t{EffectiveId} = 0;
  202 +
  203 + my $ticketObj = new RT::Ticket($RT::SystemUser);
  204 + my ( $newid, $msg ) = $ticketObj->Import(%t) or return;
  205 + print $msg and return unless $newid;
  206 +
  207 + # My exporter didnt export merged tickets so we dont need to do this
  208 + # But it may be required and I just dont know about it.
  209 + #$ticketObj->SetEffectiveId(ConvertTicket($eid)) if ($eid != $ticket->{id});
  210 +
  211 + $ticketObj->{_AccessibleCache}{Created}
  212 + = { read => 1, write => 1, auto => 0 };
  213 + $ticketObj->{_AccessibleCache}{Creator}
  214 + = { read => 1, write => 1, auto => 0 };
  215 + $ticketObj->{_AccessibleCache}{LastUpdated}
  216 + = { read => 1, write => 1, auto => 0 };
  217 + $ticketObj->{_AccessibleCache}{LastUpdatedBy}
  218 + = { read => 1, write => 1, auto => 0 };
  219 + $ticketObj->SetCreated( $ticket->{Created} );
  220 + $ticketObj->SetCreator( $ticket->{Creator} );
  221 + $ticketObj->SetLastUpdated( $ticket->{LastUpdated} );
  222 + $ticketObj->SetLastUpdatedBy( $ticket->{LastUpdatedBy} );
184 223
185 224 $ticketObj->AddCustomFieldValue(
186 225 Field => $cf,
187   - Value => "[$rtname #$id]"
  226 + Value => "[$rtname #$ticket->{id}]"
188 227 );
189 228
190   - $TICKETS{$id} = $newid;
  229 + foreach my $custom_field ( @{ $ticket->{CustomFields} } ) {
  230 + $ticketObj->AddCustomFieldValue(
  231 + Field => $custom_field->{Name},
  232 + Value => $custom_field->{Value},
  233 + );
  234 + }
  235 +
191 236 return $newid;
192 237 }
193 238

0 comments on commit 20477e9

Please sign in to comment.
Something went wrong with that request. Please try again.