diff options
author | ivan <ivan> | 2008-03-24 01:28:10 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-03-24 01:28:10 +0000 |
commit | f7696f45691c414aaa3c6fe48ce6e374588009f4 (patch) | |
tree | 3c359c478fee425a91a9599ff604a92a70847076 | |
parent | 0b704b4eeb63358df9094b4c68cd1f47d1a9bd23 (diff) |
part two of #1160: linking a ticket to its first customer will auto-link any customerless requestors
-rw-r--r-- | rt/html/Ticket/Elements/AddCustomers | 2 | ||||
-rw-r--r-- | rt/lib/RT/Interface/Web_Vendor.pm | 75 | ||||
-rwxr-xr-x | rt/lib/RT/Record.pm | 29 |
3 files changed, 94 insertions, 12 deletions
diff --git a/rt/html/Ticket/Elements/AddCustomers b/rt/html/Ticket/Elements/AddCustomers index 01c7367c4..e04c07702 100644 --- a/rt/html/Ticket/Elements/AddCustomers +++ b/rt/html/Ticket/Elements/AddCustomers @@ -1,4 +1,5 @@ %# Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am> +%# Copyright (c) 2008 Freeside Internet Services, Inc. %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have @@ -24,6 +25,7 @@ </td> </tr> % } +</table> % } diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm index 3f07656eb..1999096a7 100644 --- a/rt/lib/RT/Interface/Web_Vendor.pm +++ b/rt/lib/RT/Interface/Web_Vendor.pm @@ -43,12 +43,15 @@ sub ProcessTicketCustomers { my %args = ( TicketObj => undef, ARGSRef => undef, + Debug => 0, @_ ); my @results = (); my $Ticket = $args{'TicketObj'}; my $ARGSRef = $args{'ARGSRef'}; + my $Debug = $args{'Debug'}; + my $me = 'ProcessTicketCustomers'; ### false laziness w/RT::Interface::Web::ProcessTicketLinks # Delete links that are gone gone gone. @@ -71,21 +74,69 @@ sub ProcessTicketCustomers { } ### - my @delete_custnums = - map { /^Ticket-AddCustomer-(\d+)$/; $1 } - grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } - keys %$ARGSRef; + ### + #find new customers + ### my @custnums = map { /^Ticket-AddCustomer-(\d+)$/; $1 } grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } keys %$ARGSRef; + #my @delete_custnums = + # map { /^Ticket-AddCustomer-(\d+)$/; $1 } + # grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } + # keys %$ARGSRef; + + ### + #figure out if we're going to auto-link requestors, and find them if so + ### + + my $num_cur_cust = $Ticket->Customers->Count; + my $num_new_cust = scalar(@custnums); + warn "$me: $num_cur_cust current customers / $num_new_cust new customers\n" + if $Debug; + + #if we're linking the first ticket to one customer + my $link_requestors = ( $num_cur_cust == 0 && $num_new_cust == 1 ); + warn "$me: adding a single customer to a previously customerless". + " ticket, so linking customers to requestor too\n" + if $Debug && $link_requestors; + + my @Requestors = (); + if ( $link_requestors ) { + + #find any requestors without customers + @Requestors = + grep { ! $_->Customers->Count } + @{ $Ticket->Requestors->UserMembersObj->ItemsArrayRef }; + + warn "$me: found ". scalar(@Requestors). " requestors without". + " customers; linking them\n" + if $Debug; + + } + + ### + #link ticket (and requestors) to customers + ### + foreach my $custnum ( @custnums ) { - my( $val, $msg ) = - $Ticket->AddLink( 'Type' => 'MemberOf', - 'Target' => "freeside://freeside/cust_main/$custnum", - ); + + my @link = ( 'Type' => 'MemberOf', + 'Target' => "freeside://freeside/cust_main/$custnum", + ); + + my( $val, $msg ) = $Ticket->AddLink(@link); push @results, $msg; + + #add customer links to requestors + foreach my $Requestor ( @Requestors ) { + my( $val, $msg ) = $Requestor->AddLink(@link); + push @results, $msg; + warn "$me: linking requestor to custnum $custnum: $msg\n" + if $Debug > 1; + } + } return @results; @@ -125,10 +176,10 @@ sub ProcessObjectCustomers { } ### - my @delete_custnums = - map { /^Object-AddCustomer-(\d+)$/; $1 } - grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } - keys %$ARGSRef; + #my @delete_custnums = + # map { /^Object-AddCustomer-(\d+)$/; $1 } + # grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } + # keys %$ARGSRef; my @custnums = map { /^Object-AddCustomer-(\d+)$/; $1 } grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} } diff --git a/rt/lib/RT/Record.pm b/rt/lib/RT/Record.pm index 1b622739e..5207ca3d2 100755 --- a/rt/lib/RT/Record.pm +++ b/rt/lib/RT/Record.pm @@ -1211,8 +1211,37 @@ sub DependsOn { # }}} +# {{{ Customers +=head2 Customers + This returns an RT::Links object which references all the customers that this object is a member of. + +=cut + +sub Customers { + my( $self, %opt ) = @_; + my $Debug = $opt{'Debug'}; + + unless ( $self->{'Customers'} ) { + + $self->{'Customers'} = $self->MemberOf->Clone; + + $self->{'Customers'}->Limit( + FIELD => 'Target', + OPERATOR => 'STARTSWITH', + VALUE => 'freeside://freeside/cust_main/', + ); + } + + warn "->Customers method called on $self; returning ". + ref($self->{'Customers'}). ' object' + if $Debug; + + return $self->{'Customers'}; +} + +# }}} # {{{ sub _Links |