1 # Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am>
2 # Copyright (c) 2008 Freeside Internet Services, Inc.
4 # This work is made available to you under the terms of Version 2 of
5 # the GNU General Public License. A copy of that license should have
6 # been provided with this software, but in any event can be snarfed
9 # This work is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
16 RT::Interface::Web_Vendor
22 Freeside vendor overlay for RT::Interface::Web.
26 use_ok(RT::Interface::Web_Vendor);
32 #package RT::Interface::Web;
35 package HTML::Mason::Commands;
38 =head2 ProcessTicketCustomers
42 sub ProcessTicketCustomers {
51 my $Ticket = $args{'TicketObj'};
52 my $ARGSRef = $args{'ARGSRef'};
53 my $Debug = $args{'Debug'};
54 my $me = 'ProcessTicketCustomers';
56 ### false laziness w/RT::Interface::Web::ProcessTicketLinks
57 # Delete links that are gone gone gone.
58 foreach my $arg ( keys %$ARGSRef ) {
59 if ( $arg =~ /DeleteLink-(.*?)-(DependsOn|MemberOf|RefersTo)-(.*)$/ ) {
65 "Trying to delete: Base: $base Target: $target Type $type";
66 my ( $val, $msg ) = $Ticket->DeleteLink( Base => $base,
81 my @custnums = map { /^Ticket-AddCustomer-(\d+)$/; $1 }
82 grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
85 #my @delete_custnums =
86 # map { /^Ticket-AddCustomer-(\d+)$/; $1 }
87 # grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
91 #figure out if we're going to auto-link requestors, and find them if so
94 my $num_cur_cust = $Ticket->Customers->Count;
95 my $num_new_cust = scalar(@custnums);
96 warn "$me: $num_cur_cust current customers / $num_new_cust new customers\n"
99 #if we're linking the first ticket to one customer
100 my $link_requestors = ( $num_cur_cust == 0 && $num_new_cust == 1 );
101 warn "$me: adding a single customer to a previously customerless".
102 " ticket, so linking customers to requestor too\n"
103 if $Debug && $link_requestors;
106 if ( $link_requestors ) {
108 #find any requestors without customers
110 grep { ! $_->Customers->Count }
111 @{ $Ticket->Requestors->UserMembersObj->ItemsArrayRef };
113 warn "$me: found ". scalar(@Requestors). " requestors without".
114 " customers; linking them\n"
120 #link ticket (and requestors) to customers
123 foreach my $custnum ( @custnums ) {
125 my @link = ( 'Type' => 'MemberOf',
126 'Target' => "freeside://freeside/cust_main/$custnum",
129 my( $val, $msg ) = $Ticket->AddLink(@link);
132 #add customer links to requestors
133 foreach my $Requestor ( @Requestors ) {
134 my( $val, $msg ) = $Requestor->AddLink(@link);
136 warn "$me: linking requestor to custnum $custnum: $msg\n"
146 #false laziness w/above... eventually it should go away in favor of this
147 sub ProcessObjectCustomers {
155 my $Object = $args{'Object'};
156 my $ARGSRef = $args{'ARGSRef'};
158 ### false laziness w/RT::Interface::Web::ProcessTicketLinks
159 # Delete links that are gone gone gone.
160 foreach my $arg ( keys %$ARGSRef ) {
161 if ( $arg =~ /DeleteLink-(.*?)-(DependsOn|MemberOf|RefersTo)-(.*)$/ ) {
167 "Trying to delete: Base: $base Target: $target Type $type";
168 my ( $val, $msg ) = $Object->DeleteLink( Base => $base,
179 #my @delete_custnums =
180 # map { /^Object-AddCustomer-(\d+)$/; $1 }
181 # grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
184 my @custnums = map { /^Object-AddCustomer-(\d+)$/; $1 }
185 grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
188 foreach my $custnum ( @custnums ) {
190 $Object->AddLink( 'Type' => 'MemberOf',
191 'Target' => "freeside://freeside/cust_main/$custnum",