X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem%2FRT_External.pm;h=fa97b395625e0d66537a029208b2900c57937bb2;hb=fcce61390d750f98bd82e84d4664ae9c03202be2;hp=d1c9ebf21315e1d8d8de5fdcc85ec939a7cc208d;hpb=f8a8f142236a338fde4b733df48e022d19748c88;p=freeside.git diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index d1c9ebf21..fa97b3956 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -9,6 +9,8 @@ use URI::Escape; use FS::UID qw(dbh); use FS::Record qw(qsearchs); use FS::cust_main; +use Carp qw(cluck); +use FS::DBI; $me = '[FS::TicketSystem::RT_External]'; $DEBUG = 0; @@ -35,8 +37,8 @@ FS::UID->install_callback( sub { $dbh = dbh; if ($conf->config('ticket_system') eq 'RT_External') { my ($datasrc, $user, $pass) = $conf->config('ticket_system-rt_external_datasrc'); - $dbh = DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 }) - or die "RT_External DBI->connect error: $DBI::errstr\n"; + $dbh = FS::DBI->connect($datasrc, $user, $pass, { 'ChopBlanks' => 1 }) + or die "RT_External FS::DBI->connect error: $FS::DBI::errstr\n"; $external_url = $conf->config('ticket_system-rt_external_url'); } @@ -96,6 +98,36 @@ sub customer_tickets { } +sub service_tickets { + warn "service_tickets not available with RT_External.\n"; + return; +} + +sub comments_on_tickets { + my ($self, $custnum, $limit, $time ) = @_; + $limit ||= 0; + + my( $from_sql, @param) = $self->_from_customer( $custnum ); + my $sql = qq{ + SELECT transactions.*, Attachments.content, Tickets.subject + FROM transactions + JOIN Attachments ON( Attachments.transactionid = transactions.id ) + JOIN Tickets ON ( Tickets.id = transactions.objectid ) + JOIN Links ON ( Tickets.id = Links.LocalBase + AND Links.Base LIKE '%/ticket/' || Tickets.id ) + + + WHERE ( Status = 'new' OR Status = 'open' OR Status = 'stalled' ) + AND Target = 'freeside://freeside/cust_main/$custnum' + AND transactions.type = 'Comment' + AND transactions.created >= (SELECT TIMESTAMP WITH TIME ZONE 'epoch' + $time * INTERVAL '1 second') + LIMIT $limit + }; + cluck $sql if $DEBUG > 0; + #AND created > + $dbh->selectall_arrayref( $sql, { Slice => {} } ) or die $dbh->errstr . " $sql"; +} + sub _from_customer { my( $self, $custnum, $priority ) = @_; @@ -156,14 +188,16 @@ sub _from_customer { } my $sql = " - FROM Tickets - JOIN Queues ON ( Tickets.Queue = Queues.id ) - JOIN Links ON ( Tickets.id = Links.LocalBase ) - JOIN Users ON ( Tickets.Owner = Users.id ) - $join - WHERE ( ". join(' OR ', map "Status = '$_'", $self->statuses ). " ) - AND Target = 'freeside://freeside/cust_main/$custnum' - $where + FROM Tickets + JOIN Queues ON ( Tickets.Queue = Queues.id ) + JOIN Users ON ( Tickets.Owner = Users.id ) + JOIN Links ON ( Tickets.id = Links.LocalBase + AND Links.Base LIKE '%/ticket/' || Tickets.id ) + $join + + WHERE ( ". join(' OR ', map "Status = '$_'", $self->statuses ). " ) + AND Target = 'freeside://freeside/cust_main/$custnum' + $where "; ( $sql, @param ); @@ -178,7 +212,20 @@ sub statuses { } sub href_customer_tickets { - my( $self, $custnum ) = ( shift, shift ); + my($self, $custnum) = (shift, shift); + if ( $custnum =~ /^(\d+)$/ ) { + return $self->href_search_tickets("MemberOf = 'freeside://freeside/cust_main/$1'"); + } + warn "bad custnum $custnum"; return ''; +} + +sub href_service_tickets { + warn "service_tickets not available with RT_External.\n"; + ''; +} + +sub href_search_tickets { + my( $self, $where ) = ( shift, shift ); my( $priority, @statuses); if ( ref($_[0]) ) { my $opt = shift; @@ -197,8 +244,8 @@ sub href_customer_tickets { #$href .= my $href = "Search/Results.html?Order=ASC&". - "Query= MemberOf = 'freeside://freeside/cust_main/$custnum' ". - #" AND ( Status = 'open' OR Status = 'new' OR Status = 'stalled' )" + "Query= $where" . + #MemberOf = 'freeside://freeside/cust_main/$custnum' ". " AND ( ". join(' OR ', map "Status = '$_'", @statuses ). " ) " ; @@ -218,7 +265,7 @@ sub href_customer_tickets { uri_escape($href); #eventually should unescape all of it... - $href .= '&Rows=100'. + $href .= '&RowsPerPage=50'. '&OrderBy=id&Page=1'. '&Format=%27%20%20%20%3Cb%3E%3Ca%20href%3D%22'. $self->baseurl. @@ -245,25 +292,49 @@ sub href_customer_tickets { } +sub href_params_new_ticket { + # my( $self, $custnum_or_cust_main, $requestors ) = @_; + # no longer takes $custnum--it must be an object + my ( $self, $object, $requestors ) = @_; + my $cust_main; # for default requestors + if ( $object->isa('FS::cust_main') ) { + $cust_main = $object; + } + elsif ( $object->isa('FS::svc_Common') ) { + $object = $object->cust_svc; + $cust_main = $object->cust_pkg->cust_main if ( $object->cust_pkg ); + } + elsif ( $object->isa('FS::cust_svc') ) { + $cust_main = $object->cust_pkg->cust_main if ( $object->cust_pkg ); + } + + # explicit $requestors > config option > invoicing_list + $requestors = $conf->config('ticket_system-requestor') + if !$requestors; + $requestors = $cust_main->invoicing_list_emailonly_scalar + if (!$requestors) and defined($cust_main); + + my $subtype = $object->table; + my $pkey = $object->get($object->primary_key); + + my @param = ( + 'Queue' => ($cust_main->agent->ticketing_queueid || $default_queueid), + 'new-MemberOf'=> "freeside://freeside/$subtype/$pkey", + 'Requestors' => $requestors, + ); + + ( $self->baseurl.'Ticket/Create.html', @param ); +} + sub href_new_ticket { - my( $self, $custnum_or_cust_main, $requestors ) = @_; + my $self = shift; + + my( $base, @param ) = $self->href_params_new_ticket(@_); + + my $uri = new URI $base; + $uri->query_form(@param); + $uri; - my( $custnum, $cust_main ); - if ( ref($custnum_or_cust_main) ) { - $cust_main = $custnum_or_cust_main; - $custnum = $cust_main->custnum; - } else { - $custnum = $custnum_or_cust_main; - $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ); - } - my $queueid = $cust_main->agent->ticketing_queueid || $default_queueid; - - $self->baseurl. - 'Ticket/Create.html?'. - "Queue=$queueid". - "&new-MemberOf=freeside://freeside/cust_main/$custnum". - ( $requestors ? '&Requestors='. uri_escape($requestors) : '' ) - ; } sub href_ticket { @@ -315,7 +386,7 @@ sub _retrieve_single_value { sub transaction_creator { my( $self, $transaction_id ) = @_; - my $sql = "SELECT Name FRP< Transactions JOIN Users ON ". + my $sql = "SELECT Name FROM Transactions JOIN Users ON ". "Transactions.Creator=Users.id WHERE Transactions.id = ". $transaction_id; @@ -349,5 +420,18 @@ sub transaction_status { $self->_retrieve_single_value($sql); } +sub access_right { + warn "WARNING: no access rights available w/ external RT"; + 0; +} + +sub create_ticket { + return 'create_ticket unimplemented w/external RT (write something w/RT::Client::REST?)'; +} + +sub init { } #unimplemented + +sub selfservice_priority { '' } #unimplemented + 1;