[Rt-commit] [svn] r713 - in rt/branches/rt-3.1: . lib/RT

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Tue Apr 20 23:29:39 EDT 2004


Author: jesse
Date: Tue Apr 20 23:29:39 2004
New Revision: 713

Modified:
   rt/branches/rt-3.1/   (props changed)
   rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm
Log:
 ----------------------------------------------------------------------
 r2110 at tinbook:  jesse | 2004-04-21T03:26:54.764726Z
 
 Fixing a regression caused by the new logging of nonfatal ticket creation errors.
 ----------------------------------------------------------------------
 

Modified: rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm	(original)
+++ rt/branches/rt-3.1/lib/RT/Ticket_Overlay.pm	Tue Apr 20 23:29:39 2004
@@ -316,39 +316,38 @@
 sub Create {
     my $self = shift;
 
-    my %args = ( id              => undef,
-                 EffectiveId     => undef,
-                 Queue           => undef,
-                 Requestor       => undef,
-                 Cc              => undef,
-                 AdminCc         => undef,
-                 Type            => 'ticket',
-                 Owner           => undef,
-                 Subject         => '',
-                 InitialPriority => undef,
-                 FinalPriority   => undef,
-                 Priority   => undef,
-                 Status          => 'new',
-                 TimeWorked      => "0",
-                 TimeLeft        => 0,
-                 TimeEstimated        => 0,
-                 Due             => undef,
-                 Starts          => undef,
-                 Started         => undef,
-                 Resolved        => undef,
-                 MIMEObj         => undef,
-                 _RecordTransaction => 1,
-                 
-
+    my %args = (
+        id                 => undef,
+        EffectiveId        => undef,
+        Queue              => undef,
+        Requestor          => undef,
+        Cc                 => undef,
+        AdminCc            => undef,
+        Type               => 'ticket',
+        Owner              => undef,
+        Subject            => '',
+        InitialPriority    => undef,
+        FinalPriority      => undef,
+        Priority           => undef,
+        Status             => 'new',
+        TimeWorked         => "0",
+        TimeLeft           => 0,
+        TimeEstimated      => 0,
+        Due                => undef,
+        Starts             => undef,
+        Started            => undef,
+        Resolved           => undef,
+        MIMEObj            => undef,
+        _RecordTransaction => 1,
 
-                 @_ );
+        @_
+    );
 
     my ( $ErrStr, $Owner, $resolved );
     my (@non_fatal_errors);
 
     my $QueueObj = RT::Queue->new($RT::SystemUser);
 
-    
     if ( ( defined( $args{'Queue'} ) ) && ( !ref( $args{'Queue'} ) ) ) {
         $QueueObj->Load( $args{'Queue'} );
     }
@@ -356,9 +355,9 @@
         $QueueObj->Load( $args{'Queue'}->Id );
     }
     else {
-        $RT::Logger->debug( $args{'Queue'} . " not a recognised queue object.");
+        $RT::Logger->debug(
+            $args{'Queue'} . " not a recognised queue object." );
     }
-;
 
     #Can't create a ticket without a queue.
     unless ( defined($QueueObj) && $QueueObj->Id ) {
@@ -367,18 +366,26 @@
     }
 
     #Now that we have a queue, Check the ACLS
-    unless ( $self->CurrentUser->HasRight( Right    => 'CreateTicket',
-                                                Object => $QueueObj )
-      ) {
-        return ( 0, 0,
-                 $self->loc( "No permission to create tickets in the queue '[_1]'", $QueueObj->Name ) );
+    unless (
+        $self->CurrentUser->HasRight(
+            Right  => 'CreateTicket',
+            Object => $QueueObj
+        )
+      )
+    {
+        return (
+            0, 0,
+            $self->loc(
+                "No permission to create tickets in the queue '[_1]'",
+                $QueueObj->Name
+            )
+        );
     }
 
     unless ( $QueueObj->IsValidStatus( $args{'Status'} ) ) {
         return ( 0, 0, $self->loc('Invalid value for status') );
     }
 
-
     #Since we have a queue, we can set queue defaults
     #Initial Priority
 
@@ -386,7 +393,7 @@
     $args{'InitialPriority'} = ( $QueueObj->InitialPriority || 0 )
       unless ( $args{'InitialPriority'} );
 
-    #Final priority 
+    #Final priority
 
     # If there's no queue default final priority and it's not set, set it to 0
     $args{'FinalPriority'} = ( $QueueObj->FinalPriority || 0 )
@@ -396,7 +403,6 @@
     # where we're importing tickets (eg, from an older RT version.)
     my $priority = $args{'Priority'} || $args{'InitialPriority'};
 
-
     # {{{ Dates
     #TODO we should see what sort of due date we're getting, rather +
     # than assuming it's in ISO format.
@@ -405,32 +411,35 @@
     my $Due = new RT::Date( $self->CurrentUser );
 
     if ( $args{'Due'} ) {
-        $Due->Set( Format => 'ISO', Value  => $args{'Due'} );
+        $Due->Set( Format => 'ISO', Value => $args{'Due'} );
     }
-    elsif (  $QueueObj->DefaultDueIn  ) {
+    elsif ( $QueueObj->DefaultDueIn ) {
         $Due->SetToNow;
         $Due->AddDays( $QueueObj->DefaultDueIn );
     }
 
     my $Starts = new RT::Date( $self->CurrentUser );
     if ( defined $args{'Starts'} ) {
-        $Starts->Set( Format => 'ISO', Value  => $args{'Starts'} );
+        $Starts->Set( Format => 'ISO', Value => $args{'Starts'} );
     }
 
     my $Started = new RT::Date( $self->CurrentUser );
     if ( defined $args{'Started'} ) {
-        $Started->Set( Format => 'ISO', Value  => $args{'Started'} );
+        $Started->Set( Format => 'ISO', Value => $args{'Started'} );
     }
 
     my $Resolved = new RT::Date( $self->CurrentUser );
     if ( defined $args{'Resolved'} ) {
-        $Resolved->Set( Format => 'ISO', Value  => $args{'Resolved'} );
+        $Resolved->Set( Format => 'ISO', Value => $args{'Resolved'} );
     }
 
-
     #If the status is an inactive status, set the resolved date
-    if ($QueueObj->IsInactiveStatus($args{'Status'}) && !$args{'Resolved'}) {
-        $RT::Logger->debug("Got a ".$args{'Status'} . "ticket with a resolved of ".$args{'Resolved'});
+    if ( $QueueObj->IsInactiveStatus( $args{'Status'} ) && !$args{'Resolved'} )
+    {
+        $RT::Logger->debug( "Got a "
+              . $args{'Status'}
+              . "ticket with a resolved of "
+              . $args{'Resolved'} );
         $Resolved->SetToNow;
     }
 
@@ -455,27 +464,41 @@
         $Owner = RT::User->new( $self->CurrentUser );
         $Owner->Load( $args{'Owner'} );
 
-	push @non_fatal_errors, $self->loc("Owner could not be set.  User '[_1]' could not be loaded", $args{'Owner'}) unless ($Owner->Id);
+        push( @non_fatal_errors,
+                $self->loc("Owner could not be set.") . " "
+              . $self->loc( "User '[_1]' could not be found.", $args{'Owner'} )
+          )
+          unless ( $Owner->Id );
 
     }
 
-    #If we have a proposed owner and they don't have the right 
+    #If we have a proposed owner and they don't have the right
     #to own a ticket, scream about it and make them not the owner
-    if (     ( defined($Owner) )
-         and ( $Owner->Id )
-         and ( $Owner->Id != $RT::Nobody->Id )
-         and ( !$Owner->HasRight( Object => $QueueObj,
-                                       Right    => 'OwnTicket' ) )
-      ) {
+    if (
+            ( defined($Owner) )
+        and ( $Owner->Id )
+        and ( $Owner->Id != $RT::Nobody->Id )
+        and (
+            !$Owner->HasRight(
+                Object => $QueueObj,
+                Right  => 'OwnTicket'
+            )
+        )
+      )
+    {
 
         $RT::Logger->warning( "User "
-                              . $Owner->Name . "("
-                              . $Owner->id
-                              . ") was proposed "
-                              . "as a ticket owner but has no rights to own "
-                              . "tickets in ".$QueueObj->Name );
+              . $Owner->Name . "("
+              . $Owner->id
+              . ") was proposed "
+              . "as a ticket owner but has no rights to own "
+              . "tickets in "
+              . $QueueObj->Name );
 
-        push @non_fatal_errors, $self->loc("Owner '[_1]' does not have rights to own this ticket.  Defaulting to 'Nobody'.", $Owner->Name);
+        push @non_fatal_errors,
+          $self->loc( "Owner '[_1]' does not have rights to own this ticket.",
+            $Owner->Name
+          );
 
         $Owner = undef;
     }
@@ -488,109 +511,130 @@
 
     # }}}
 
-    # We attempt to load or create each of the people who might have a role for this ticket
-    # _outside_ the transaction, so we don't get into ticket creation races
+# We attempt to load or create each of the people who might have a role for this ticket
+# _outside_ the transaction, so we don't get into ticket creation races
     foreach my $type ( "Cc", "AdminCc", "Requestor" ) {
-     next unless (defined $args{$type});
-        foreach my $watcher ( ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) ) {
-        my $user = RT::User->new($RT::SystemUser);
-        $user->LoadOrCreateByEmail($watcher) if ($watcher && $watcher !~ /^\d+$/);
+        next unless ( defined $args{$type} );
+        foreach my $watcher (
+            ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
+        {
+            my $user = RT::User->new($RT::SystemUser);
+            $user->LoadOrCreateByEmail($watcher)
+              if ( $watcher && $watcher !~ /^\d+$/ );
         }
     }
 
-
     $RT::Handle->BeginTransaction();
 
-    my %params =( Queue           => $QueueObj->Id,
-                                   Owner           => $Owner->Id,
-                                   Subject         => $args{'Subject'},
-                                   InitialPriority => $args{'InitialPriority'},
-                                   FinalPriority   => $args{'FinalPriority'},
-                                   Priority        => $priority,
-                                   Status          => $args{'Status'},
-                                   TimeWorked      => $args{'TimeWorked'},
-                                   TimeEstimated   => $args{'TimeEstimated'},
-                                   TimeLeft        => $args{'TimeLeft'},
-                                   Type            => $args{'Type'},
-                                   Starts          => $Starts->ISO,
-                                   Started         => $Started->ISO,
-                                   Resolved        => $Resolved->ISO,
-                                   Due             => $Due->ISO );
+    my %params = (
+        Queue           => $QueueObj->Id,
+        Owner           => $Owner->Id,
+        Subject         => $args{'Subject'},
+        InitialPriority => $args{'InitialPriority'},
+        FinalPriority   => $args{'FinalPriority'},
+        Priority        => $priority,
+        Status          => $args{'Status'},
+        TimeWorked      => $args{'TimeWorked'},
+        TimeEstimated   => $args{'TimeEstimated'},
+        TimeLeft        => $args{'TimeLeft'},
+        Type            => $args{'Type'},
+        Starts          => $Starts->ISO,
+        Started         => $Started->ISO,
+        Resolved        => $Resolved->ISO,
+        Due             => $Due->ISO
+    );
 
-    # Parameters passed in during an import that we probably don't want to touch, otherwise
+# Parameters passed in during an import that we probably don't want to touch, otherwise
     foreach my $attr qw(id Creator Created LastUpdated LastUpdatedBy) {
-        $params{$attr} = $args{$attr} if ($args{$attr});
+        $params{$attr} = $args{$attr} if ( $args{$attr} );
     }
 
     # Delete null integer parameters
-    foreach my $attr qw(TimeWorked TimeLeft TimeEstimated InitialPriority FinalPriority) {
-        delete $params{$attr}  unless (exists $params{$attr} && $params{$attr});
+    foreach my $attr
+      qw(TimeWorked TimeLeft TimeEstimated InitialPriority FinalPriority) {
+        delete $params{$attr}
+          unless ( exists $params{$attr} && $params{$attr} );
     }
 
-
-    my ($id,$ticket_message) = $self->SUPER::Create( %params);
+    my ( $id, $ticket_message ) = $self->SUPER::Create(%params);
     unless ($id) {
-        $RT::Logger->crit( "Couldn't create a ticket: " . $ticket_message);
+        $RT::Logger->crit( "Couldn't create a ticket: " . $ticket_message );
         $RT::Handle->Rollback();
-        return ( 0, 0, $self->loc( "Ticket could not be created due to an internal error") );
+        return ( 0, 0,
+            $self->loc("Ticket could not be created due to an internal error")
+        );
     }
 
     #Set the ticket's effective ID now that we've created it.
-    my ( $val, $msg ) = $self->__Set( Field => 'EffectiveId', Value => ($args{'EffectiveId'} || $id ) );
+    my ( $val, $msg ) = $self->__Set(
+        Field => 'EffectiveId',
+        Value => ( $args{'EffectiveId'} || $id )
+    );
 
     unless ($val) {
         $RT::Logger->crit("$self ->Create couldn't set EffectiveId: $msg\n");
         $RT::Handle->Rollback();
-        return ( 0, 0, $self->loc( "Ticket could not be created due to an internal error") );
+        return ( 0, 0,
+            $self->loc("Ticket could not be created due to an internal error")
+        );
     }
 
     my $create_groups_ret = $self->_CreateTicketGroups();
     unless ($create_groups_ret) {
         $RT::Logger->crit( "Couldn't create ticket groups for ticket "
-                           . $self->Id
-                           . ". aborting Ticket creation." );
+              . $self->Id
+              . ". aborting Ticket creation." );
         $RT::Handle->Rollback();
         return ( 0, 0,
-                 $self->loc( "Ticket could not be created due to an internal error") );
+            $self->loc("Ticket could not be created due to an internal error")
+        );
     }
 
-    # Set the owner in the Groups table
-    # We denormalize it into the Ticket table too because doing otherwise would 
-    # kill performance, bigtime. It gets kept in lockstep thanks to the magic of transactionalization
-
-    $self->OwnerGroup->_AddMember( PrincipalId => $Owner->PrincipalId , InsideTransaction => 1);
+# Set the owner in the Groups table
+# We denormalize it into the Ticket table too because doing otherwise would
+# kill performance, bigtime. It gets kept in lockstep thanks to the magic of transactionalization
+
+    $self->OwnerGroup->_AddMember(
+        PrincipalId       => $Owner->PrincipalId,
+        InsideTransaction => 1
+    );
 
     # {{{ Deal with setting up watchers
 
-
     foreach my $type ( "Cc", "AdminCc", "Requestor" ) {
-        next unless (defined $args{$type});
-        foreach my $watcher ( ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) ) {
+        next unless ( defined $args{$type} );
+        foreach my $watcher (
+            ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
+        {
 
-	   # If there is an empty entry in the list, let's get out of here.
-	   next unless $watcher;
+            # If there is an empty entry in the list, let's get out of here.
+            next unless $watcher;
 
-	    # we reason that all-digits number must be a principal id, not email
-	    # this is the only way to can add
-	    my $field = 'Email';
-	    $field = 'PrincipalId' if $watcher =~ /^\d+$/;
+            # we reason that all-digits number must be a principal id, not email
+            # this is the only way to can add
+            my $field = 'Email';
+            $field = 'PrincipalId' if $watcher =~ /^\d+$/;
 
-	    my ( $wval, $wmsg );
+            my ( $wval, $wmsg );
 
             if ( $type eq 'AdminCc' ) {
 
-                # Note that we're using AddWatcher, rather than _AddWatcher, as we 
-                # actually _want_ that ACL check. Otherwise, random ticket creators
-                # could make themselves adminccs and maybe get ticket rights. that would
-                # be poor
-                ( $wval, $wmsg ) = $self->AddWatcher( Type   => $type,
-                                                         $field => $watcher,
-                                                         Silent => 1 );
+        # Note that we're using AddWatcher, rather than _AddWatcher, as we
+        # actually _want_ that ACL check. Otherwise, random ticket creators
+        # could make themselves adminccs and maybe get ticket rights. that would
+        # be poor
+                ( $wval, $wmsg ) = $self->AddWatcher(
+                    Type   => $type,
+                    $field => $watcher,
+                    Silent => 1
+                );
             }
             else {
-                ( $wval, $wmsg ) = $self->_AddWatcher( Type   => $type,
-                                                          $field => $watcher,
-                                                          Silent => 1 );
+                ( $wval, $wmsg ) = $self->_AddWatcher(
+                    Type   => $type,
+                    $field => $watcher,
+                    Silent => 1
+                );
             }
 
             push @non_fatal_errors, $wmsg unless ($wval);
@@ -600,9 +644,8 @@
     # }}}
     # {{{ Deal with setting up links
 
-
     foreach my $type ( keys %LINKTYPEMAP ) {
-        next unless (defined $args{$type});
+        next unless ( defined $args{$type} );
         foreach my $link (
             ref( $args{$type} ) ? @{ $args{$type} } : ( $args{$type} ) )
         {
@@ -618,50 +661,55 @@
 
     # }}}
 
-   # {{{ Add all the custom fields 
+    # {{{ Add all the custom fields
 
     foreach my $arg ( keys %args ) {
-    next unless ( $arg =~ /^CustomField-(\d+)$/i );
-    my $cfid = $1;
-    foreach
-      my $value ( ref( $args{$arg} ) ? @{ $args{$arg} } : ( $args{$arg} ) ) {
-        next unless (length($value));
-        $self->_AddCustomFieldValue( Field => $cfid,
-                                     Value => $value,
-                                     RecordTransaction => 0
-                                 );
-    }
+        next unless ( $arg =~ /^CustomField-(\d+)$/i );
+        my $cfid = $1;
+        foreach
+          my $value ( ref( $args{$arg} ) ? @{ $args{$arg} } : ( $args{$arg} ) )
+        {
+            next unless ( length($value) );
+            $self->_AddCustomFieldValue(
+                Field             => $cfid,
+                Value             => $value,
+                RecordTransaction => 0
+            );
+        }
     }
+
     # }}}
 
     if ( $args{'_RecordTransaction'} ) {
+
         # {{{ Add a transaction for the create
         my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
-                                                     Type      => "Create",
-                                                     TimeTaken => 0,
-                                                     MIMEObj => $args{'MIMEObj'}
+            Type      => "Create",
+            TimeTaken => 0,
+            MIMEObj   => $args{'MIMEObj'}
         );
 
-
         if ( $self->Id && $Trans ) {
-            $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name );
-            $ErrStr = join ( "\n", $ErrStr, @non_fatal_errors );
 
-            $RT::Logger->info("Ticket ".$self->Id. " created in queue '".$QueueObj->Name."' by ".$self->CurrentUser->Name);
-	    $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name );
-	    $ErrStr = join ( "\n", $ErrStr, @non_fatal_errors );
-	    return ( $self->Id, $0, $ErrStr );
+            $RT::Logger->info( "Ticket " . $self->Id . " created in queue '" . $QueueObj->Name . "' by " . $self->CurrentUser->Name );
+            $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name );
+            $ErrStr = join( "\n", $ErrStr, @non_fatal_errors );
         }
         else {
             $RT::Handle->Rollback();
 
-            # TODO where does this get errstr from?
+            $ErrStr = join( "\n", $ErrStr, @non_fatal_errors );
             $RT::Logger->error("Ticket couldn't be created: $ErrStr");
-            return ( 0, 0, $self->loc( "Ticket could not be created due to an internal error"));
+            return (
+                0, 0,
+                $self->loc(
+                    "Ticket could not be created due to an internal error")
+            );
         }
 
         $RT::Handle->Commit();
         return ( $self->Id, $TransObj->Id, $ErrStr );
+
         # }}}
     }
     else {
@@ -669,7 +717,7 @@
         # Not going to record a transaction
         $RT::Handle->Commit();
         $ErrStr = $self->loc( "Ticket [_1] created in queue '[_2]'", $self->Id, $QueueObj->Name );
-        $ErrStr = join ( "\n", $ErrStr, @non_fatal_errors );
+        $ErrStr = join( "\n", $ErrStr, @non_fatal_errors );
         return ( $self->Id, $0, $ErrStr );
 
     }


More information about the Rt-commit mailing list