[rt-devel] bring on the clones

ivan ivan-rt-devel at 420.am
Mon Aug 13 06:50:02 EDT 2001


Hi,

Started using RT for some of my own projects; this is a feature I really
missed from the MAPS codebase; it's kind of the conceptual opposite of a
"merge" - when someone sends in a ticket that contains multiple issues you
want to track separately.  patch attached. 

-- 
meow
_ivan
-------------- next part --------------
diff -ur rt-2-0-4.dist/lib/RT/Ticket.pm rt-2-0-4.ivan1/lib/RT/Ticket.pm
--- rt-2-0-4.dist/lib/RT/Ticket.pm	Wed Jul 18 13:06:45 2001
+++ rt-2-0-4.ivan1/lib/RT/Ticket.pm	Mon Aug 13 03:36:44 2001
@@ -544,6 +544,58 @@
 }
 # }}}
 
+# {{{ sub Clone
+
+=head2 Clone
+
+Clones an existing ticket and its create transaction; returns the new Ticket
+object.
+
+=cut
+
+sub Clone {
+  my $self = shift;
+
+  my $Requestor = [ map $_->Email, @{ $self->Requestors->ItemsArrayRef } ];
+  my $Cc        = [ map $_->Email, @{ $self->Cc->ItemsArrayRef } ];
+  my $AdminCc   = [ map $_->Email, @{ $self->AdminCc->ItemsArrayRef } ];
+
+  use RT::Transactions;
+  my $transactions = RT::Transactions->new($self->CurrentUser);
+  $transactions->Limit( FIELD => 'Ticket', VALUE => $self->id() );
+  $transactions->Limit( FIELD => 'Type',   VALUE => 'Create' );
+  my $attachment = $transactions->Next->Message->Next;
+
+  use MIME::Entity;
+  my $MIMEObj = MIME::Entity->build( Data => $attachment->Content,
+    map { /^([\w\-]+:)\s*(.*)$/; $1 => $2; } split(/\n/, $attachment->Headers )
+  );
+    
+  #my $clone = ref($self)->new($self->CurrentUser);
+  my $clone = RT::Ticket->new($self->CurrentUser);
+  $clone->Create(
+                  Queue           => $self->Queue,
+                  Requestor       => $Requestor,
+                  Cc              => $Cc,
+                  AdminCc         => $AdminCc,
+                  Owner           => $self->Owner,
+                  Subject         => $self->Subject,
+                  InitialPriority => $self->InitialPriority,
+                  FinalPriority   => $self->FinalPriority,
+                  Priority        => $self->Priority,
+                  Status          => $self->Status,
+                  TimeWorked      => 0,
+#                  Type            => $self->Type,
+                  Due             => $self->Due,
+                  #Created         => $self->Created,
+                  #Creator         => $self->Creator,
+                  MIMEObj         => $MIMEObj,
+                ) or return 0;
+  $clone; 
+}
+
+# }}}
+
 # {{{ Routines dealing with watchers.
 
 # {{{ Routines dealing with adding new watchers
diff -ur rt-2-0-4.dist/lib/blib/lib/RT/Ticket.pm rt-2-0-4.ivan1/lib/blib/lib/RT/Ticket.pm
--- rt-2-0-4.dist/lib/blib/lib/RT/Ticket.pm	Wed Jul 18 13:06:45 2001
+++ rt-2-0-4.ivan1/lib/blib/lib/RT/Ticket.pm	Mon Aug 13 03:36:44 2001
@@ -544,6 +544,58 @@
 }
 # }}}
 
+# {{{ sub Clone
+
+=head2 Clone
+
+Clones an existing ticket and its create transaction; returns the new Ticket
+object.
+
+=cut
+
+sub Clone {
+  my $self = shift;
+
+  my $Requestor = [ map $_->Email, @{ $self->Requestors->ItemsArrayRef } ];
+  my $Cc        = [ map $_->Email, @{ $self->Cc->ItemsArrayRef } ];
+  my $AdminCc   = [ map $_->Email, @{ $self->AdminCc->ItemsArrayRef } ];
+
+  use RT::Transactions;
+  my $transactions = RT::Transactions->new($self->CurrentUser);
+  $transactions->Limit( FIELD => 'Ticket', VALUE => $self->id() );
+  $transactions->Limit( FIELD => 'Type',   VALUE => 'Create' );
+  my $attachment = $transactions->Next->Message->Next;
+
+  use MIME::Entity;
+  my $MIMEObj = MIME::Entity->build( Data => $attachment->Content,
+    map { /^([\w\-]+:)\s*(.*)$/; $1 => $2; } split(/\n/, $attachment->Headers )
+  );
+    
+  #my $clone = ref($self)->new($self->CurrentUser);
+  my $clone = RT::Ticket->new($self->CurrentUser);
+  $clone->Create(
+                  Queue           => $self->Queue,
+                  Requestor       => $Requestor,
+                  Cc              => $Cc,
+                  AdminCc         => $AdminCc,
+                  Owner           => $self->Owner,
+                  Subject         => $self->Subject,
+                  InitialPriority => $self->InitialPriority,
+                  FinalPriority   => $self->FinalPriority,
+                  Priority        => $self->Priority,
+                  Status          => $self->Status,
+                  TimeWorked      => 0,
+#                  Type            => $self->Type,
+                  Due             => $self->Due,
+                  #Created         => $self->Created,
+                  #Creator         => $self->Creator,
+                  MIMEObj         => $MIMEObj,
+                ) or return 0;
+  $clone; 
+}
+
+# }}}
+
 # {{{ Routines dealing with watchers.
 
 # {{{ Routines dealing with adding new watchers
diff -ur rt-2-0-4.dist/webrt/Ticket/Display.html rt-2-0-4.ivan1/webrt/Ticket/Display.html
--- rt-2-0-4.dist/webrt/Ticket/Display.html	Wed Jun 20 14:27:54 2001
+++ rt-2-0-4.ivan1/webrt/Ticket/Display.html	Mon Aug 13 03:12:40 2001
@@ -94,6 +94,10 @@
     my $action = $1;
     my ($res, $msg)=$Ticket->$action();
     push(@Actions, $msg);
+  } elsif ( $ARGS{'Action'} eq 'Clone' ) {
+    $Ticket = $Ticket->Clone();
+    push @Actions, "Ticket cloned from #$ARGS{'id'}";
+    $ARGS{'id'} = $Ticket->id;
   }
 }
     
diff -ur rt-2-0-4.dist/webrt/Ticket/Elements/Tabs rt-2-0-4.ivan1/webrt/Ticket/Elements/Tabs
--- rt-2-0-4.dist/webrt/Ticket/Elements/Tabs	Sun Jun 17 11:36:11 2001
+++ rt-2-0-4.ivan1/webrt/Ticket/Elements/Tabs	Mon Aug 13 03:31:55 2001
@@ -85,6 +85,13 @@
     }
 }
 
+if ($Ticket->CurrentUserHasRight('CreateTicket')) {
+    $actions->{'Clone'} = 
+      {
+       title => 'Clone',
+       path  => "Ticket/Display.html?Action=Clone&id=$id",
+      };
+}
 
 
 


More information about the Rt-devel mailing list