X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FInterface%2FWeb_Vendor.pm;h=1999096a7223a8640deab85892393e14ff952077;hb=624b2d44625f69d71175c3348cae635d580c890b;hp=5be20e6b999dd0260b5304ce20f9baca89c57b66;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1;p=freeside.git diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm index 5be20e6b9..1999096a7 100644 --- a/rt/lib/RT/Interface/Web_Vendor.pm +++ b/rt/lib/RT/Interface/Web_Vendor.pm @@ -1,4 +1,5 @@ # Copyright (c) 2004 Ivan Kohler +# 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 @@ -42,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. @@ -70,18 +74,120 @@ 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 @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; + +} + +#false laziness w/above... eventually it should go away in favor of this +sub ProcessObjectCustomers { + my %args = ( + Object => undef, + ARGSRef => undef, + @_ + ); + my @results = (); + + my $Object = $args{'Object'}; + my $ARGSRef = $args{'ARGSRef'}; + + ### false laziness w/RT::Interface::Web::ProcessTicketLinks + # Delete links that are gone gone gone. + foreach my $arg ( keys %$ARGSRef ) { + if ( $arg =~ /DeleteLink-(.*?)-(DependsOn|MemberOf|RefersTo)-(.*)$/ ) { + my $base = $1; + my $type = $2; + my $target = $3; + + push @results, + "Trying to delete: Base: $base Target: $target Type $type"; + my ( $val, $msg ) = $Object->DeleteLink( Base => $base, + Type => $type, + Target => $target ); + + push @results, $msg; + + } + + } + ### + + #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->{$_} } + keys %$ARGSRef; + foreach my $custnum ( @custnums ) { my( $val, $msg ) = - $Ticket->AddLink( 'Type' => 'MemberOf', + $Object->AddLink( 'Type' => 'MemberOf', 'Target' => "freeside://freeside/cust_main/$custnum", ); push @results, $msg;