[Bps-public-commit] r9490 - in RT-Extension-SLA/lib/RT: Action

ruz at bestpractical.com ruz at bestpractical.com
Fri Oct 26 23:31:32 EDT 2007


Author: ruz
Date: Fri Oct 26 23:31:31 2007
New Revision: 9490

Modified:
   RT-Extension-SLA/lib/RT/Action/SLA_SetStarts.pm
   RT-Extension-SLA/lib/RT/Extension/SLA.pm

Log:
* delete some old functions we don't want to use
* reimplement SetStarts action using new API

Modified: RT-Extension-SLA/lib/RT/Action/SLA_SetStarts.pm
==============================================================================
--- RT-Extension-SLA/lib/RT/Action/SLA_SetStarts.pm	(original)
+++ RT-Extension-SLA/lib/RT/Action/SLA_SetStarts.pm	Fri Oct 26 23:31:31 2007
@@ -27,28 +27,18 @@
 
     my $ticket = $self->TicketObj;
 
-# XXX I encountered a 'Couldn't set starts date: That is already the current 
-# value' warning if I didn't test it here. wierd
-    return 0 if $ticket->StartsObj->Unix > 0;
-
     my $level = $ticket->FirstCustomFieldValue('SLA');
     unless ( $level ) {
         $RT::Logger->debug('Ticket #'. $ticket->id .' has no service level defined, skip setting Starts');
         return 1;
     }
 
-    my $SLA = $self->SLA(Level => $level);
-    my $starts = $SLA->Starts( $self->TransactionObj->CreatedObj->Unix, $level );
-
-    my $date = RT::Date->new($RT::SystemUser);
-    $date->Set( Format => 'unix', Value => $starts );
-    my ($status, $msg) = $ticket->SetStarts( $date->ISO );
-    unless ( $status ) {
-        $RT::Logger->error("Couldn't set starts date: $msg");
-        return 0;
-    }
+    my $starts = $self->Starts(
+        Level => $level,
+        Time => $ticket->CreatedObj->Unix,
+    );
 
-    return 1;
+    return $self->SetDateField( Starts => $starts );
 }
 
 1;

Modified: RT-Extension-SLA/lib/RT/Extension/SLA.pm
==============================================================================
--- RT-Extension-SLA/lib/RT/Extension/SLA.pm	(original)
+++ RT-Extension-SLA/lib/RT/Extension/SLA.pm	Fri Oct 26 23:31:31 2007
@@ -259,11 +259,12 @@
 sub Due {
     my $self = shift;
     my %args = ( Level => undef, Type => undef, Time => undef, @_ );
-    my $meta = $RT::SLA{'Levels'}{ $args{'Level'} };
 
     my $agreement = $self->Agreement( %args );
     return undef unless $agreement;
 
+    my $meta = $RT::SLA{'Levels'}{ $args{'Level'} };
+
     my $res = $args{'Time'};
     if ( defined $agreement->{'BusinessMinutes'} ) {
         my $bhours = $self->BusinessHours( $meta->{'BusinessHours'} );
@@ -275,67 +276,17 @@
     return $res;
 }
 
-
-=head2 Agreements [ Type => 'Response' ]
-
-DEPRECATED
-
-Returns an instance of L<Business::SLA> class filled with
-service levels for particular Type.
-
-Now we take list of agreements and its description from the
-RT config.
-
-By default Type is 'Response'. 'Resolve' is another type
-we support.
-
-=cut
-
-sub Agreements {
+sub Starts {
     my $self = shift;
-    my %args = ( Type => 'Response', Time => undef, @_ );
-
-    my $class = $RT::SLA{'Module'} || 'Business::SLA';
-    eval "require $class" or die $@;
-    my $SLA = $class->new( BusinessHours => $self->BusinessHours );
+    my %args = ( Level => undef, Time => undef, @_ );
 
-    my $levels = $RT::SLA{'Levels'};
-    foreach my $level ( keys %$levels ) {
-        my $props = $self->Agreement( %args, Level => $level );
-        next unless $props;
-
-        $SLA->Add( $level => %$props );
-    }
-
-    return $SLA;
-}
-
-=head2 SLA [ Level => $level ]
-
-Returns an instance of L<Business::SLA> class filled with the level.
-
-Now we take list of agreements and its description from the
-RT config.
-
-=cut
-
-sub SLA {
-    my $self  = shift;
-    my %args  = @_;
-    my $level = $args{Level};
-
-    my $class = $RT::SLA{'Module'} || 'Business::SLA';
-    eval "require $class" or die $@;
-
-    my $SLA = $class->new(
-        BusinessHours => $self->BusinessHours(
-            $RT::SLA{'Levels'}{ $level }{'BusinessHours'}
-        ),
-    );
+    my $meta = $RT::SLA{'Levels'}{ $args{'Level'} };
+    return undef unless $meta;
 
-    $SLA->Add( $level => %{ $self->Agreement(%args) } );
+    return $args{'Time'} if $meta->{'StartImmediately'};
 
-    return $SLA;
+    my $bhours = $self->BusinessHours( $meta->{'BusinessHours'} );
+    return $bhours->first_after( $args{'Time'} );
 }
 
 sub GetCustomField {



More information about the Bps-public-commit mailing list