ticketing escalation, part 1, RT#8254
[freeside.git] / rt / lib / RT / Action / AutoOpen.pm
index 3423db9..e1cf0ae 100644 (file)
@@ -1,8 +1,8 @@
 # BEGIN BPS TAGGED BLOCK {{{
 # 
 # COPYRIGHT:
-#  
-# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
+# 
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
 #                                          <jesse@bestpractical.com>
 # 
 # (Except where explicitly superseded by other copyright notices)
@@ -22,7 +22,9 @@
 # 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 # 
 # 
 # CONTRIBUTION SUBMISSION POLICY:
 # those contributions and any derivatives thereof.
 # 
 # END BPS TAGGED BLOCK }}}
-# This Action will open the BASE if a dependent is resolved.
 
+# This Action will open the BASE if a dependent is resolved.
 package RT::Action::AutoOpen;
-require RT::Action::Generic;
 
 use strict;
-use vars qw/@ISA/;
-@ISA=qw(RT::Action::Generic);
+use warnings;
 
-#Do what we need to do and send it out.
+use base qw(RT::Action);
 
-#What does this type of Action does
+=head1 DESCRIPTION
 
-# {{{ sub Describe 
-sub Describe  {
-  my $self = shift;
-  return (ref $self );
-}
-# }}}
+Opens a ticket unless it's allready open, but only unless transaction
+L<RT::Transaction/IsInbound is inbound>.
+
+Doesn't open a ticket if message's head has field C<RT-Control> with
+C<no-autoopen> substring.
 
+=cut
 
-# {{{ sub Prepare 
 sub Prepare {
     my $self = shift;
 
     # if the ticket is already open or the ticket is new and the message is more mail from the
     # requestor, don't reopen it.
 
-    if ( ( $self->TicketObj->Status eq 'open' )
-         || ( ( $self->TicketObj->Status eq 'new' )
-              && $self->TransactionObj->IsInbound )
-         || ( defined $self->TransactionObj->Message->First
-              && $self->TransactionObj->Message->First->GetHeader('RT-Control') =~ /\bno-autoopen\b/i )
-      ) {
+    my $status = $self->TicketObj->Status;
+    return undef if $status eq 'open';
+    return undef if $status eq 'new' && $self->TransactionObj->IsInbound;
 
-        return undef;
-    }
-    else {
-        return (1);
+    if ( my $msg = $self->TransactionObj->Message->First ) {
+        return undef if ($msg->GetHeader('RT-Control') || '') =~ /\bno-autoopen\b/i;
     }
+
+    return 1;
 }
-# }}}
 
 sub Commit {
     my $self = shift;
-      my $oldstatus = $self->TicketObj->Status();
-        $self->TicketObj->__Set( Field => 'Status', Value => 'open' );
-        $self->TicketObj->_NewTransaction(
-                         Type     => 'Status',
-                         Field    => 'Status',
-                         OldValue => $oldstatus,
-                         NewValue => 'open',
-                         Data => 'Ticket auto-opened on incoming correspondence'
-        );
-
-
-    return(1);
+
+    my $oldstatus = $self->TicketObj->Status;
+    $self->TicketObj->__Set( Field => 'Status', Value => 'open' );
+    $self->TicketObj->_NewTransaction(
+        Type     => 'Status',
+        Field    => 'Status',
+        OldValue => $oldstatus,
+        NewValue => 'open',
+        Data     => 'Ticket auto-opened on incoming correspondence'
+    );
+
+    return 1;
 }
 
 eval "require RT::Action::AutoOpen_Vendor";