[rt-devel] Patch for CLI (1 bug correction and 3 features)

Xavier Henner henner at nerim.net
Fri Dec 27 15:56:51 EST 2002


Hello

I have recently installed RT in our NOC. The staff love webRT interface but the
sysadmin wanted a CLI and there was some problems (and a bug) in RT CLI.

I changed 2/3 little things to bin/rt and lib/RT/Interface/CLI.pm
As it may interrest somebody, I post the patch.


The changes are : 

1) when the --reply command is used, the edited file is prefiled with
the last reply made on the ticket

2) when --reply or --comment is used, the signature is added

3) there was a bug with the "Content" argument of GetMessageContent() :
if a content was specified, all \n where destroyed (split (/\n/, $string) destroys the /n.
@tab=(<FILE>) don't) As Content was not used, it was not a real problem.
I added a loop to change that because I wanted to use the Content
argument.
   
4) when the editor is used, if the user don't write anything (:q! with
vi for example) the comment (or the reply) is not added (mutt has the
same behaviour)



*** bin/rt.old	Fri Dec  6 23:19:12 2002
--- bin/rt	Fri Dec 27 20:47:22 2002
***************
*** 941,973 ****
  
  	# {{{ Perform ticket comments/replies
  	if ($reply) {
  	    $RT::Logger->debug("Replying to ticket ".$Ticket->Id);
  	    
  	    my $linesref = GetMessageContent( Edit => $edit, Source => $source,
! 					     CurrentUser => $CurrentUser
  					   );
  	    
! 	    #TODO build this entity
! 	    require MIME::Entity;
! 	    my $MIMEObj = MIME::Entity->build(Data => $linesref);
! 	    
! 	    $Ticket->Correspond( MIMEObj => $MIMEObj ,
! 				 TimeTaken => $time_taken);
  	}	
  	
  	elsif ($comment) {
  	    $RT::Logger->debug("Commenting on ticket ".$Ticket->Id);
  	
  	    my $linesref =GetMessageContent(Edit => $edit, Source => $source,
  					    CurrentUser => $CurrentUser);
! 	    #TODO build this entity
! 	    require MIME::Entity;
! 	    my $MIMEObj = MIME::Entity->build(Data => $linesref);
  	    
! 	    $Ticket->Comment( MIMEObj => $MIMEObj,
! 			      TimeTaken => $time_taken);
  	}
  
      # }}}
  	
  	# {{{ Display whatever we need to display
--- 941,983 ----
  
  	# {{{ Perform ticket comments/replies
  	if ($reply) {
  	    $RT::Logger->debug("Replying to ticket ".$Ticket->Id);
  	    
+             my $content="";
+ 
+             if(!$source){
+ 	      $content=&ShowLastReply($Ticket);
+ 	    }
+ 
  	    my $linesref = GetMessageContent( Edit => $edit, Source => $source,
! 					     CurrentUser => $CurrentUser, Content => $content
  					   );
+ 
+             if($linesref) {
+ 	        #TODO build this entity
+ 	        require MIME::Entity;
+ 	        my $MIMEObj = MIME::Entity->build(Data => $linesref);
  	    
! 	        $Ticket->Correspond( MIMEObj => $MIMEObj ,
! 		  		 TimeTaken => $time_taken);
! 	    }
  	}	
  	
  	elsif ($comment) {
  	    $RT::Logger->debug("Commenting on ticket ".$Ticket->Id);
  	
  	    my $linesref =GetMessageContent(Edit => $edit, Source => $source,
  					    CurrentUser => $CurrentUser);
!             if($linesref) {
! 	       #TODO build this entity
! 	       require MIME::Entity;
! 	       my $MIMEObj = MIME::Entity->build(Data => $linesref);
  	    
! 	       $Ticket->Comment( MIMEObj => $MIMEObj,
! 	       	        TimeTaken => $time_taken);
! 	    }
  	}
  
      # }}}
  	
  	# {{{ Display whatever we need to display
***************
*** 1259,1268 ****
--- 1269,1298 ----
  	print $message->ContentType, " not shown";
      }
    }
    print "\n";
    return();
+ }
+ # }}}
+ 
+ # {{{ sub ShowLastReply 
+ sub ShowLastReply {
+   my $Ticket = shift;
+   my $Transaction;
+   my $Transactions = $Ticket->Transactions;
+   my $Result = "> ";
+ 
+   my $LastTransaction;
+ 
+   while ($Transaction = $Transactions->Next) {
+     if($Transaction->Type eq "Create" || $Transaction->Type eq "Correspond"){
+       $LastTransaction=$Transaction;
+     }
+   }
+  
+   $Result=$LastTransaction->Content(Quote => 1);  
+   return($Result);
  }
  # }}}
  
  
  # {{{ sub BuildListingFormat






*** lib/RT/Interface/CLI.pm.old	Fri Dec 27 17:26:40 2002
--- lib/RT/Interface/CLI.pm	Fri Dec 27 20:37:03 2002
***************
*** 169,198 ****
  	@lines = (<SOURCE>);
  	close (SOURCE);
      }
      elsif ($args{'Content'}) {
  	@lines = split('\n',$args{'Content'});
      }
      #get us a tempfile.
      my ($fh, $filename) = tempfile();
  	
      #write to a tmpfile
      for (@lines) {
  	print $fh $_;
      }
      close ($fh);
!     
      #Edit the file if we need to
      if ($edit) {	
- 
  	unless ($ENV{'EDITOR'}) {
  	    $RT::Logger->crit('No $EDITOR variable defined'. "\n");
  	    return undef;
  	}
  	system ($ENV{'EDITOR'}, $filename);
      }	
!     
      open (READ, "<$filename");
      my @newlines = (<READ>);
      close (READ);
  
      unlink ($filename) unless (debug());
--- 169,213 ----
  	@lines = (<SOURCE>);
  	close (SOURCE);
      }
      elsif ($args{'Content'}) {
  	@lines = split('\n',$args{'Content'});
+ 	for(my $i=0;$i<@lines;$i++){
+            $lines[$i].="\n";
+         }
      }
      #get us a tempfile.
      my ($fh, $filename) = tempfile();
  	
      #write to a tmpfile
      for (@lines) {
  	print $fh $_;
      }
+     if ($currentuser->UserObj->Signature) {
+       printf $fh "-- \n".$currentuser->UserObj->Signature;
+     }
      close ($fh);
! 	
!     my $oldtime = -M $filename;    
!     my $newtime = -M $filename;    
! 
      #Edit the file if we need to
      if ($edit) {	
  	unless ($ENV{'EDITOR'}) {
  	    $RT::Logger->crit('No $EDITOR variable defined'. "\n");
  	    return undef;
  	}
  	system ($ENV{'EDITOR'}, $filename);
+         $newtime = -M $filename;    
      }	
! 
!     # If the file was not changed, we do nothing
!     if($oldtime eq $newtime) {
!         unlink ($filename) unless (debug());
! 	return 0;
!     }
! 
      open (READ, "<$filename");
      my @newlines = (<READ>);
      close (READ);
  
      unlink ($filename) unless (debug());




-- 
Xavier Henner
Ingénieur Système
Nerim -- Fournisseur d'accès à Internet
URL: <http://www.nerim.net/>



More information about the Rt-devel mailing list