X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem%2FRT_External.pm;h=b5414b97cfdcb9b2c643e7f72197dda656cf5b24;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hp=bcad43bc50cc67a99024cfdae695ef44ace9fa34;hpb=6eae8e86517298d4de53d9754487d53b4f29765d;p=freeside.git diff --git a/FS/FS/TicketSystem/RT_External.pm b/FS/FS/TicketSystem/RT_External.pm index bcad43bc5..b5414b97c 100644 --- a/FS/FS/TicketSystem/RT_External.pm +++ b/FS/FS/TicketSystem/RT_External.pm @@ -9,6 +9,7 @@ use URI::Escape; use FS::UID qw(dbh); use FS::Record qw(qsearchs); use FS::cust_main; +use Carp qw(cluck); $me = '[FS::TicketSystem::RT_External]'; $DEBUG = 0; @@ -73,15 +74,19 @@ sub customer_tickets { $limit ||= 0; my( $from_sql, @param) = $self->_from_customer( $custnum, $priority ); - my $sql="SELECT Tickets.*, Queues.name, ". - "position(Tickets.status in 'newopenstalledresolvedrejecteddeleted')". - " AS svalue " . - ( length($priority) ? ", objectcustomfieldvalues.content" : '' ). - " $from_sql ". - " ORDER BY svalue, ". - " priority ". ( $priority_reverse ? 'ASC' : 'DESC' ). ", ". - " id DESC ". - " LIMIT $limit"; + my $sql = " + SELECT Tickets.*, + Queues.Name AS Queue, + Users.Name AS Owner, + position(Tickets.Status in 'newopenstalledresolvedrejecteddeleted') + AS svalue + ". ( length($priority) ? ", ObjectCustomFieldValues.Content" : '' )." + $from_sql + ORDER BY svalue, + Priority ". ( $priority_reverse ? 'ASC' : 'DESC' ). ", + id DESC + LIMIT $limit + "; warn "$me $sql (@param)" if $DEBUG; my $sth = $dbh->prepare($sql) or die $dbh->errstr. "preparing $sql"; $sth->execute(@param) or die $sth->errstr. "executing $sql"; @@ -92,6 +97,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 ) = @_; @@ -101,7 +136,7 @@ sub _from_customer { if ( defined($priority) ) { my $queue_sql = " ObjectCustomFields.ObjectId = ( SELECT id FROM Queues - WHERE Queues.name = ? ) + WHERE Queues.Name = ? ) OR ( ? = '' AND ObjectCustomFields.ObjectId = 0 )"; my $customfield_sql = @@ -110,7 +145,7 @@ sub _from_customer { JOIN ObjectCustomFields ON ( CustomFields.id = ObjectCustomFields.CustomField ) WHERE LookupType = 'RT::Queue-RT::Ticket' - AND name = ? + AND Name = ? AND ( $queue_sql ) )"; @@ -133,32 +168,34 @@ sub _from_customer { $join = "JOIN ObjectCustomFieldValues ON ( Tickets.id = ObjectCustomFieldValues.ObjectId )"; - $where = " AND content = ? - AND ObjectCustomFieldValues.disabled != 1 + $where = " AND Content = ? + AND ObjectCustomFieldValues.Disabled != 1 AND ObjectType = 'RT::Ticket' AND $customfield_sql"; } else { - $where = - "AND 0 = ( SELECT count(*) FROM ObjectCustomFieldValues - WHERE ObjectId = Tickets.id - AND ObjectType = 'RT::Ticket' - AND $customfield_sql - ) + $where = " AND NOT EXISTS ( SELECT 1 FROM ObjectCustomFieldValues + WHERE ObjectId = Tickets.id + AND ObjectType = 'RT::Ticket' + AND $customfield_sql + ) "; } } my $sql = " - FROM Tickets - JOIN Queues ON ( Tickets.queue = Queues.id ) - JOIN Links ON ( Tickets.id = Links.localbase ) - $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 ); @@ -173,7 +210,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; @@ -192,8 +242,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 ). " ) " ; @@ -213,7 +263,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. @@ -240,25 +290,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 { @@ -269,7 +343,7 @@ sub href_ticket { sub queues { my($self) = @_; - my $sql = "SELECT id, name FROM Queues WHERE disabled = 0"; + my $sql = "SELECT id, Name FROM Queues WHERE Disabled = 0"; my $sth = $dbh->prepare($sql) or die $dbh->errstr. " preparing $sql"; $sth->execute() or die $sth->errstr. " executing $sql"; @@ -282,7 +356,7 @@ sub queue { return '' unless $queueid; - my $sql = "SELECT name FROM Queues WHERE id = ?"; + my $sql = "SELECT Name FROM Queues WHERE id = ?"; my $sth = $dbh->prepare($sql) or die $dbh->errstr. " preparing $sql"; $sth->execute($queueid) or die $sth->errstr. " executing $sql"; @@ -293,7 +367,7 @@ sub queue { sub baseurl { #my $self = shift; - $external_url; + $external_url. '/'; } sub _retrieve_single_value { @@ -310,8 +384,8 @@ sub _retrieve_single_value { sub transaction_creator { my( $self, $transaction_id ) = @_; - my $sql = "SELECT name from transactions JOIN users ON ". - "transactions.creator=users.id WHERE transactions.id = ". + my $sql = "SELECT Name FROM Transactions JOIN Users ON ". + "Transactions.Creator=Users.id WHERE Transactions.id = ". $transaction_id; $self->_retrieve_single_value($sql); @@ -320,7 +394,7 @@ sub transaction_creator { sub transaction_ticketid { my( $self, $transaction_id ) = @_; - my $sql = "SELECT objectid from transactions WHERE transactions.id = ". + my $sql = "SELECT ObjectId FROM Transactions WHERE Transactions.id = ". $transaction_id; $self->_retrieve_single_value($sql); @@ -329,8 +403,8 @@ sub transaction_ticketid { sub transaction_subject { my( $self, $transaction_id ) = @_; - my $sql = "SELECT subject from Transactions JOIN Tickets ON objectid=". - "Tickets.id WHERE transactions.id = ". $transaction_id; + my $sql = "SELECT Subject FROM Transactions JOIN Tickets ON ObjectId=". + "Tickets.id WHERE Transactions.id = ". $transaction_id; $self->_retrieve_single_value($sql); } @@ -338,11 +412,24 @@ sub transaction_subject { sub transaction_status { my( $self, $transaction_id ) = @_; - my $sql = "SELECT status from Transactions JOIN Tickets ON objectid=". - "Tickets.id WHERE transactions.id = ". $transaction_id; + my $sql = "SELECT Status FROM Transactions JOIN Tickets ON ObjectId=". + "Tickets.id WHERE Transactions.id = ". $transaction_id; $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;